Message ID | b25689c92bc381c8019e239a540a7175f5efc2fe.1685266344.git.efraim@flashner.co.il |
---|---|
State | New |
Headers | show |
Series | Image for HiFive Unmatched | expand |
Efraim Flashner <efraim@flashner.co.il> skribis: > * gnu/build/image.scm (make-unformatted-image): New procedure. > (make-partition-image): Add support for unformatted partition. > * gnu/system/image.scm (system-disk-image)[partition->gpt-type]: Add > case for using unformatted partition uuid. > [partition-image]: Add coreutils to image-builder closure. [...] > +(define* (make-unformatted-image partition target) > + "Make an unformatted partition of a certain size." > + (let ((size (partition-size partition))) > + (invoke "truncate" "--size" (number->string size) target))) Simply: (truncate-file target size). > - (inputs '#+(list e2fsprogs fakeroot dosfstools mtools)) > + (inputs '#+(list e2fsprogs ; ext2/3/4 > + fakeroot > + dosfstools ; vfat > + mtools ; vfat > + coreutils)) ; truncate And this can be dropped. Ludo’.
On Fri, Jun 09, 2023 at 10:42:37PM +0200, Ludovic Courtès wrote: > Efraim Flashner <efraim@flashner.co.il> skribis: > > > * gnu/build/image.scm (make-unformatted-image): New procedure. > > (make-partition-image): Add support for unformatted partition. > > * gnu/system/image.scm (system-disk-image)[partition->gpt-type]: Add > > case for using unformatted partition uuid. > > [partition-image]: Add coreutils to image-builder closure. > > [...] > > > +(define* (make-unformatted-image partition target) > > + "Make an unformatted partition of a certain size." > > + (let ((size (partition-size partition))) > > + (invoke "truncate" "--size" (number->string size) target))) > > Simply: (truncate-file target size). Almost. Backtrace: 1 (primitive-load "/gnu/store/v9kg0qwyws5s5m07klzkfqc9dmf…") 0 (truncate-file "/gnu/store/rcillf8ni077l9fi2cy2gdzzpqv…" …) ERROR: In procedure truncate-file: In procedure truncate-file: No such file or directory I changed it to: (let ((size (partition-size partition))) ;; Create the file and then truncate it to the desired size. (with-output-to-file target (lambda _ (display ""))) (truncate-file target size))) And that got me the empty partition/block device as needed. > > - (inputs '#+(list e2fsprogs fakeroot dosfstools mtools)) > > + (inputs '#+(list e2fsprogs ; ext2/3/4 > > + fakeroot > > + dosfstools ; vfat > > + mtools ; vfat > > + coreutils)) ; truncate > > And this can be dropped. Not for this review, but I'd like to make the inputs dependant on which partition type is being made. There's no need to have dosfstools and mtools when making an ext4 partition. And if we add a btrfs partition option there's a large possibility that someone using that won't need e2fsprogs at all while creating their image. > Ludo’. Thanks
Hi, Efraim Flashner <efraim@flashner.co.il> skribis: > I changed it to: > > (let ((size (partition-size partition))) > ;; Create the file and then truncate it to the desired size. > (with-output-to-file target > (lambda _ (display ""))) > (truncate-file target size))) > > And that got me the empty partition/block device as needed. A slight improvement would be: (catch 'system-error (lambda () (truncate-file target size)) (lambda args (if (= ENOENT (system-error-errno args)) (call-with-output-file target (const #t)) (apply throw args)))) It’s more verbose but makes the intent clearer. Ludo’.
diff --git a/gnu/build/image.scm b/gnu/build/image.scm index 65a0373980..d47cb31aa0 100644 --- a/gnu/build/image.scm +++ b/gnu/build/image.scm @@ -7,6 +7,7 @@ ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> +;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il> ;;; ;;; This file is part of GNU Guix. ;;; @@ -122,6 +123,11 @@ (define* (make-vfat-image partition target root fs-bits) (string-append "::" file)))) (scandir root)))) +(define* (make-unformatted-image partition target) + "Make an unformatted partition of a certain size." + (let ((size (partition-size partition))) + (invoke "truncate" "--size" (number->string size) target))) + (define* (make-partition-image partition-sexp target root) "Create and return the image of PARTITION-SEXP as TARGET. Use the given ROOT directory to populate the image." @@ -134,6 +140,8 @@ (define* (make-partition-image partition-sexp target root) (make-vfat-image partition target root 16)) ((string=? type "fat32") (make-vfat-image partition target root 32)) + ((string=? type "unformatted") + (make-unformatted-image partition target)) (else (raise (condition (&message diff --git a/gnu/system/image.scm b/gnu/system/image.scm index afef79185f..3fe813f096 100644 --- a/gnu/system/image.scm +++ b/gnu/system/image.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> ;;; Copyright © 2022 Alex Griffin <a@ajgrf.com> +;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il> ;;; ;;; This file is part of GNU Guix. ;;; @@ -390,6 +391,9 @@ (define* (system-disk-image image ((or (string=? file-system "vfat") (string=? file-system "fat16") (string=? file-system "fat32")) "F") + ((and (string=? file-system "unformatted") + (partition-uuid partition)) + (uuid->string (partition-uuid partition))) (else (raise (condition (&message @@ -414,7 +418,11 @@ (define* (system-disk-image image (with-imported-modules* (let ((initializer (or #$(partition-initializer partition) initialize-root-partition)) - (inputs '#+(list e2fsprogs fakeroot dosfstools mtools)) + (inputs '#+(list e2fsprogs ; ext2/3/4 + fakeroot + dosfstools ; vfat + mtools ; vfat + coreutils)) ; truncate (image-root "tmp-root")) (sql-schema #$schema)