diff options
| author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2025-10-10 15:32:30 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-11-24 23:22:51 +0100 |
| commit | 5e5ac81e9562c9f77910766f3a1c857b3da36472 (patch) | |
| tree | 1f46be320d717fc4d2c95a706487807ac003abdb | |
| parent | 92fbb1f82b88f30f7457f5ff81a9cec4bf47804d (diff) | |
image: Add support for f2fs.
* gnu/build/image.scm (make-f2fs-image): New variable.
(make-partition-image): Support f2fs.
(estimate-partition-size): Add optional margin.
* gnu/system/image.scm (system-disk-image): Support f2fs.
* doc/guix.texi: (partition Reference): Support f2fs.
Change-Id: Ia7fc4483c3cc1af5f34fac86a529a90a1bd7c2c6
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
| -rw-r--r-- | doc/guix.texi | 4 | ||||
| -rw-r--r-- | gnu/build/image.scm | 41 | ||||
| -rw-r--r-- | gnu/system/image.scm | 8 |
3 files changed, 45 insertions, 8 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 1e4d022e99e..310700cd0cb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -54287,8 +54287,8 @@ there is no offset applied. | |||
| 54287 | @item @code{file-system} (default: @code{"ext4"}) | 54287 | @item @code{file-system} (default: @code{"ext4"}) |
| 54288 | The partition file system as a string, defaulting to @code{"ext4"}. | 54288 | The partition file system as a string, defaulting to @code{"ext4"}. |
| 54289 | 54289 | ||
| 54290 | The supported values are @code{"vfat"}, @code{"fat16"}, @code{"fat32"}, | 54290 | The supported values are @code{"btrfs"}, @code{"ext4"}, @code{"fat16"}, |
| 54291 | @code{"btrfs"}, and @code{"ext4"}. | 54291 | @code{"fat32"}, and @code{"vfat"}. |
| 54292 | 54292 | ||
| 54293 | @code{"vfat"}, @code{"fat16"}, and @code{"fat32"} partitions without the | 54293 | @code{"vfat"}, @code{"fat16"}, and @code{"fat32"} partitions without the |
| 54294 | @code{'esp} flag are by default LBA compatible. | 54294 | @code{'esp} flag are by default LBA compatible. |
diff --git a/gnu/build/image.scm b/gnu/build/image.scm index 2eb2ebd2179..c7cf72be91d 100644 --- a/gnu/build/image.scm +++ b/gnu/build/image.scm | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr> | 6 | ;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr> |
| 7 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> | 7 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> |
| 8 | ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> | 8 | ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> |
| 9 | ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 9 | ;;; Copyright © 2022, 2025 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> |
| 10 | ;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il> | 10 | ;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il> |
| 11 | ;;; | 11 | ;;; |
| 12 | ;;; This file is part of GNU Guix. | 12 | ;;; This file is part of GNU Guix. |
| @@ -66,12 +66,14 @@ | |||
| 66 | (number->string | 66 | (number->string |
| 67 | (inexact->exact (ceiling (/ size 1024))))) | 67 | (inexact->exact (ceiling (/ size 1024))))) |
| 68 | 68 | ||
| 69 | (define (estimate-partition-size root) | 69 | (define* (estimate-partition-size root #:optional (margin .25)) |
| 70 | "Given the ROOT directory, evaluate and return its size. As this doesn't | 70 | "Given the ROOT directory, evaluate and return its size. As this doesn't |
| 71 | take the partition metadata size into account, take a 25% margin. As this in | 71 | take the partition metadata size into account, take a MARGIN. As this in |
| 72 | turn doesn't take any constant overhead into account, force a 1-MiB minimum." | 72 | turn doesn't take any constant overhead into account, force a 1-MiB minimum." |
| 73 | (max (ash 1 20) | 73 | (max (ash 1 20) |
| 74 | (* 1.25 (file-size root)))) | 74 | ;; without inexact->exact, 'guess can result in an error like that: |
| 75 | ;; "Wrong type (expecting exact integer): 7179941140.0". | ||
| 76 | (inexact->exact (round (* (+ 1. margin) (file-size root)))))) | ||
| 75 | 77 | ||
| 76 | (define* (make-btrfs-image partition target root) | 78 | (define* (make-btrfs-image partition target root) |
| 77 | "Handle the creation of BTRFS partition images. See | 79 | "Handle the creation of BTRFS partition images. See |
| @@ -118,6 +120,35 @@ turn doesn't take any constant overhead into account, force a 1-MiB minimum." | |||
| 118 | (estimate-partition-size root) | 120 | (estimate-partition-size root) |
| 119 | size))))))) | 121 | size))))))) |
| 120 | 122 | ||
| 123 | (define* (make-f2fs-image partition target root | ||
| 124 | #:key | ||
| 125 | (owner-uid 0) | ||
| 126 | (owner-gid 0)) | ||
| 127 | "Handle the creation of F2FS partition images. See 'make-partition-image'." | ||
| 128 | (let ((size (partition-size partition)) | ||
| 129 | (label (partition-label partition)) | ||
| 130 | (uuid (partition-uuid partition)) | ||
| 131 | (fs-options (partition-file-system-options partition))) | ||
| 132 | ;; The mkfs.f2fs utility can't create files, so we need to create one | ||
| 133 | ;; before running it. | ||
| 134 | (call-with-output-file target (const #t)) | ||
| 135 | (truncate-file | ||
| 136 | target | ||
| 137 | (if (eq? size 'guess) | ||
| 138 | ;; The F2FS filesystem has more overhead than other filesystems like | ||
| 139 | ;; BTRFS and ext4. | ||
| 140 | (estimate-partition-size root .50) | ||
| 141 | size)) | ||
| 142 | (apply invoke "fakeroot" "mkfs.f2fs" | ||
| 143 | "-l" label | ||
| 144 | "-R" (format #f "~a:~a" owner-uid owner-gid) | ||
| 145 | `(,@(if uuid | ||
| 146 | `("-U" ,(uuid->string uuid)) | ||
| 147 | '()) | ||
| 148 | ,@fs-options | ||
| 149 | ,target)) | ||
| 150 | (invoke "fakeroot" "sload.f2fs" "-P" "-f" root target))) | ||
| 151 | |||
| 121 | (define* (make-vfat-image partition target root fs-bits) | 152 | (define* (make-vfat-image partition target root fs-bits) |
| 122 | "Handle the creation of VFAT partition images. See 'make-partition-image'." | 153 | "Handle the creation of VFAT partition images. See 'make-partition-image'." |
| 123 | (let ((size (partition-size partition)) | 154 | (let ((size (partition-size partition)) |
| @@ -162,6 +193,8 @@ ROOT directory to populate the image." | |||
| 162 | (make-btrfs-image partition target root)) | 193 | (make-btrfs-image partition target root)) |
| 163 | ((string-prefix? "ext" type) | 194 | ((string-prefix? "ext" type) |
| 164 | (make-ext-image partition target root)) | 195 | (make-ext-image partition target root)) |
| 196 | ((string=? "f2fs" type) | ||
| 197 | (make-f2fs-image partition target root)) | ||
| 165 | ((or (string=? type "vfat") (string=? type "fat16")) | 198 | ((or (string=? type "vfat") (string=? type "fat16")) |
| 166 | (make-vfat-image partition target root 16)) | 199 | (make-vfat-image partition target root 16)) |
| 167 | ((string=? type "fat32") | 200 | ((string=? type "fat32") |
diff --git a/gnu/system/image.scm b/gnu/system/image.scm index 4693e13d164..b89d3a67781 100644 --- a/gnu/system/image.scm +++ b/gnu/system/image.scm | |||
| @@ -404,7 +404,8 @@ used in the image." | |||
| 404 | (cond | 404 | (cond |
| 405 | ((member 'esp flags) "0xEF") | 405 | ((member 'esp flags) "0xEF") |
| 406 | ((or (string=? file-system "btrfs") | 406 | ((or (string=? file-system "btrfs") |
| 407 | (string-prefix? "ext" file-system)) "0x83") | 407 | (string-prefix? "ext" file-system) |
| 408 | (string=? file-system "f2fs")) "0x83") | ||
| 408 | ((or (string=? file-system "vfat") | 409 | ((or (string=? file-system "vfat") |
| 409 | (string=? file-system "fat16")) "0x0E") | 410 | (string=? file-system "fat16")) "0x0E") |
| 410 | ((string=? file-system "fat32") "0x0C") | 411 | ((string=? file-system "fat32") "0x0C") |
| @@ -424,7 +425,8 @@ used in the image." | |||
| 424 | (cond | 425 | (cond |
| 425 | ((member 'esp flags) "U") | 426 | ((member 'esp flags) "U") |
| 426 | ((or (string=? file-system "btrfs") | 427 | ((or (string=? file-system "btrfs") |
| 427 | (string-prefix? "ext" file-system)) "L") | 428 | (string-prefix? "ext" file-system) |
| 429 | (string=? file-system "f2fs")) "L") | ||
| 428 | ((or (string=? file-system "vfat") | 430 | ((or (string=? file-system "vfat") |
| 429 | (string=? file-system "fat16") | 431 | (string=? file-system "fat16") |
| 430 | (string=? file-system "fat32")) "F") | 432 | (string=? file-system "fat32")) "F") |
| @@ -460,6 +462,8 @@ used in the image." | |||
| 460 | (list btrfs-progs fakeroot)) | 462 | (list btrfs-progs fakeroot)) |
| 461 | ((string-prefix? "ext" type) | 463 | ((string-prefix? "ext" type) |
| 462 | (list e2fsprogs fakeroot)) | 464 | (list e2fsprogs fakeroot)) |
| 465 | ((string=? type "f2fs") | ||
| 466 | (list f2fs-tools fakeroot)) | ||
| 463 | ((or (string=? type "vfat") | 467 | ((or (string=? type "vfat") |
| 464 | (string-prefix? "fat" type)) | 468 | (string-prefix? "fat" type)) |
| 465 | (list dosfstools fakeroot mtools)) | 469 | (list dosfstools fakeroot mtools)) |
