unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#73612] [PATCH 0/2] Add btrfs support and vfat file system options
@ 2024-10-03 12:11 Roman Scherer
  2024-10-03 12:13 ` [bug#73612] [PATCH 1/2] image: Use file system options in make-vfat-image Roman Scherer
  2024-10-03 12:13 ` [bug#73612] [PATCH 2/2] image: Add support for btrfs Roman Scherer
  0 siblings, 2 replies; 3+ messages in thread
From: Roman Scherer @ 2024-10-03 12:11 UTC (permalink / raw)
  To: 73612; +Cc: Roman Scherer, Florian Pelz, Ludovic Court?s, Maxim Cournoyer

Hello Guix,

I'm building a disk image for the Asahi Linux installer using Guix.

The Asahi Linux installer has 2 requirements for its disk image:

- It needs a btrfs root partition, so the installer can resize it.
- The block sizes of the vfat and btrfs filesystems need to be 4k.

To create this image, I created my own image type like this:

```
(define asahi-efi-partition
  (partition
   (size (* 500 (expt 2 20)))
   (offset root-offset)
   (label "EFI")
   (file-system "vfat")
   (file-system-options (list "-S" "4096"))
   (flags '(esp))
   (initializer (with-extensions (list guile-zlib)
                  (with-imported-modules (source-module-closure
                                          '((asahi guix build bootloader m1n1))
                                          #:select? import-asahi-module?)
                    #~(lambda* (root . args)
                        (use-modules (asahi guix build bootloader m1n1))
                        (apply m1n1-initialize-efi-partition root args)))))))

(define asahi-root-partition
  (partition
   (size 'guess)
   (label root-label)
   (file-system "btrfs")
   (file-system-options (list "-s" "4096"))
   (flags '(boot))
   (uuid "fef23143-fe46-4f7f-bbb9-efc46a2a5e48")
   (initializer (gexp initialize-root-partition))))
```

Unfortuanatly Guix does not support setting file system options for vfat
partitions, nor btrfs as the root file system of an image. The following 2
patches add support for this.

The first one adds support for file-system-options on vfat file systems. The
code works the same as before, defaulting to 512 block size if no -S option is
provided and the file system is an EFI partition, otherwise it uses the user
provided block size.

The 2nd patch adds support for btrfs to Guix disk images.

With those 2 patches I was able to build a disk image that is compatible with
the Asahi Linux installer. I tested the code by building this image, putting
it on a web server, and then using it with the Asahi Linux installer to
install a Guix system.

Could you please review the patch series and help me to get this into Guix?

Thanks, Roman.

Roman Scherer (2):
  image: Use file system options in make-vfat-image.
  image: Add support for btrfs.

 doc/guix.texi        |  5 +++--
 gnu/build/image.scm  | 43 +++++++++++++++++++++++++++++++++----------
 gnu/system/image.scm |  8 ++++++--
 3 files changed, 42 insertions(+), 14 deletions(-)


base-commit: b522b468cbefcae6170e260ffadadb57f6f5ca54
--
2.46.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [bug#73612] [PATCH 1/2] image: Use file system options in make-vfat-image.
  2024-10-03 12:11 [bug#73612] [PATCH 0/2] Add btrfs support and vfat file system options Roman Scherer
@ 2024-10-03 12:13 ` Roman Scherer
  2024-10-03 12:13 ` [bug#73612] [PATCH 2/2] image: Add support for btrfs Roman Scherer
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Scherer @ 2024-10-03 12:13 UTC (permalink / raw)
  To: 73612; +Cc: Roman Scherer, Florian Pelz, Ludovic Court?s, Maxim Cournoyer

* gnu/build/image.scm (make-vfat-image): Use file system options.

Change-Id: I791aadd2803d1ef96fc79cf8910a74a0083d2b6e
---
 doc/guix.texi       |  3 ++-
 gnu/build/image.scm | 24 ++++++++++++++----------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 52e36e4354..87904761f0 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -47918,7 +47918,8 @@ partition Reference
 @item @code{file-system-options} (default: @code{'()})
 The partition file system creation options that should be passed to the
 partition creation tool, as a list of strings.  This is only supported
-when creating @code{"ext4"} partitions.
+when creating @code{"vfat"}, @code{"fat16"}, @code{"fat32"} or
+@code{"ext4"} partitions.
 
 See the @code{"extended-options"} man page section of the
 @code{"mke2fs"} tool for a more complete reference.
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index 6ca0a428e0..50518585f8 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -105,17 +105,21 @@ (define* (make-vfat-image partition target root fs-bits)
   "Handle the creation of VFAT partition images.  See 'make-partition-image'."
   (let ((size (partition-size partition))
         (label (partition-label partition))
-        (flags (partition-flags partition)))
+        (flags (partition-flags partition))
+        (fs-options (partition-file-system-options partition)))
     (apply invoke "fakeroot" "mkdosfs" "-n" label "-C" target
-                          "-F" (number->string fs-bits)
-                          (size-in-kib
-                           (if (eq? size 'guess)
-                               (estimate-partition-size root)
-                               size))
-                    ;; u-boot in particular needs the formatted block
-                    ;; size and the physical block size to be equal.
-                    ;; TODO: What about 4k blocks?
-                    (if (member 'esp flags) (list "-S" "512") '()))
+           "-F" (number->string fs-bits)
+           (size-in-kib
+            (if (eq? size 'guess)
+                (estimate-partition-size root)
+                size))
+           ;; u-boot in particular needs the formatted block
+           ;; size and the physical block size to be equal.
+           ;; TODO: What about 4k blocks?
+           (if (and (member 'esp flags)
+                    (not (member "-S" fs-options)))
+               (append (list "-S" "512") fs-options)
+               fs-options))
     (for-each (lambda (file)
                 (unless (member file '("." ".."))
                   (invoke "mcopy" "-bsp" "-i" target
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [bug#73612] [PATCH 2/2] image: Add support for btrfs.
  2024-10-03 12:11 [bug#73612] [PATCH 0/2] Add btrfs support and vfat file system options Roman Scherer
  2024-10-03 12:13 ` [bug#73612] [PATCH 1/2] image: Use file system options in make-vfat-image Roman Scherer
@ 2024-10-03 12:13 ` Roman Scherer
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Scherer @ 2024-10-03 12:13 UTC (permalink / raw)
  To: 73612; +Cc: Roman Scherer, Florian Pelz, Ludovic Court?s, Maxim Cournoyer

* gnu/build/image.scm (make-btrfs-image): New variable.
* gnu/system/image.scm (system-disk-image): Support btrfs.

Change-Id: I80a5b52ec478ce5927d6208e324cbb70282c647a
---
 doc/guix.texi        |  2 +-
 gnu/build/image.scm  | 19 +++++++++++++++++++
 gnu/system/image.scm |  8 ++++++--
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 87904761f0..34970fa398 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -47910,7 +47910,7 @@ partition Reference
 The partition file system as a string, defaulting to @code{"ext4"}.
 
 The supported values are @code{"vfat"}, @code{"fat16"}, @code{"fat32"},
-and @code{"ext4"}.
+@code{"btrfs"}, and @code{"ext4"}.
 
 @code{"vfat"}, @code{"fat16"}, and @code{"fat32"} partitions without the
 @code{'esp} flag are by default LBA compatible.
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index 50518585f8..2332b72b17 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -73,6 +73,23 @@ (define (estimate-partition-size root)
   (max (ash 1 20)
        (* 1.25 (file-size root))))
 
+(define* (make-btrfs-image partition target root)
+  "Handle the creation of BTRFS partition images. See
+'make-partition-image'."
+  (let ((size (partition-size partition))
+        (fs-options (partition-file-system-options partition))
+        (label (partition-label partition))
+        (uuid (partition-uuid partition)))
+    (apply invoke
+           `("fakeroot" "mkfs.btrfs" "-r" ,root
+             "-L" ,label
+             ,@(if uuid
+                   `("-U" ,(uuid->string uuid))
+                   '())
+             "--shrink"
+             ,@fs-options
+             ,target))))
+
 (define* (make-ext-image partition target root
                          #:key
                          (owner-uid 0)
@@ -141,6 +158,8 @@ (define* (make-partition-image partition-sexp target root)
   (let* ((partition (sexp->partition partition-sexp))
          (type (partition-file-system partition)))
     (cond
+     ((string=? "btrfs" type)
+      (make-btrfs-image partition target root))
      ((string-prefix? "ext" type)
       (make-ext-image partition target root))
      ((or (string=? type "vfat") (string=? type "fat16"))
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index b0c96c60f0..af0f3eb354 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -402,7 +402,8 @@ (define* (system-disk-image image
             (file-system (partition-file-system partition)))
         (cond
          ((member 'esp flags) "0xEF")
-         ((string-prefix? "ext" file-system) "0x83")
+         ((or (string=? file-system "btrfs")
+              (string-prefix? "ext" file-system)) "0x83")
          ((or (string=? file-system "vfat")
               (string=? file-system "fat16")) "0x0E")
          ((string=? file-system "fat32") "0x0C")
@@ -421,7 +422,8 @@ (define* (system-disk-image image
             (file-system (partition-file-system partition)))
         (cond
          ((member 'esp flags) "U")
-         ((string-prefix? "ext" file-system) "L")
+         ((or (string=? file-system "btrfs")
+              (string-prefix? "ext" file-system)) "L")
          ((or (string=? file-system "vfat")
               (string=? file-system "fat16")
               (string=? file-system "fat32")) "F")
@@ -453,6 +455,8 @@ (define* (system-disk-image image
                (let ((initializer (or #$(partition-initializer partition)
                                       initialize-root-partition))
                      (inputs '#+(cond
+                                  ((string=? type "btrfs")
+                                   (list btrfs-progs fakeroot))
                                   ((string-prefix? "ext" type)
                                    (list e2fsprogs fakeroot))
                                   ((or (string=? type "vfat")
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-03 12:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-03 12:11 [bug#73612] [PATCH 0/2] Add btrfs support and vfat file system options Roman Scherer
2024-10-03 12:13 ` [bug#73612] [PATCH 1/2] image: Use file system options in make-vfat-image Roman Scherer
2024-10-03 12:13 ` [bug#73612] [PATCH 2/2] image: Add support for btrfs Roman Scherer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).