guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/04: linux-boot: Refactor boot-system.


From: guix-commits
Subject: 01/04: linux-boot: Refactor boot-system.
Date: Wed, 20 May 2020 08:38:47 -0400 (EDT)

apteryx pushed a commit to branch master
in repository guix.

commit 281d80d8e547fe663aaacb3226119166dd3100f9
Author: Maxim Cournoyer <address@hidden>
AuthorDate: Tue Feb 11 14:00:06 2020 -0500

    linux-boot: Refactor boot-system.
    
    The --root option can now be omitted, and inferred from the root file system
    declaration instead.
    
    * gnu/build/file-systems.scm (canonicalize-device-spec): Extend to support 
NFS
    directly, and...
    * gnu/build/linux-boot.scm (boot-system): ...remove NFS special casing from
    here.  Remove nested definitions for root-fs-type, root-fs-flags and
    root-fs-options, and bind those inside the let* instead.  Make "--root" take
    precedence over the device field string representation of the root file
    system.
    * doc/guix.texi (Initial RAM Disk): Document that "--root" can be left
    unspecified.
---
 doc/guix.texi              |  7 +++---
 gnu/build/file-systems.scm |  6 +++--
 gnu/build/linux-boot.scm   | 63 +++++++++++++++++++++-------------------------
 3 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index eef5b70..4e02993 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -26534,9 +26534,10 @@ service activation programs and then spawns the 
GNU@tie{}Shepherd, the
 initialization system.
 
 @item --root=@var{root}
-Mount @var{root} as the root file system.  @var{root} can be a
-device name like @code{/dev/sda1}, a file system label, or a file system
-UUID.
+Mount @var{root} as the root file system.  @var{root} can be a device
+name like @code{/dev/sda1}, a file system label, or a file system UUID.
+When unspecified, the device name from the root file system of the
+operating system declaration is used.
 
 @item --system=@var{system}
 Have @file{/run/booted-system} and @file{/run/current-system} point to
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index b920e8f..ad92d8a 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -661,8 +661,10 @@ were found."
 
   (match spec
     ((? string?)
-     ;; Nothing to do, but wait until SPEC shows up.
-     (resolve identity spec identity))
+     (if (string-contains spec ":/")
+         spec                  ; do not resolve NFS devices
+         ;; Nothing to do, but wait until SPEC shows up.
+         (resolve identity spec identity)))
     ((? file-system-label?)
      ;; Resolve the label.
      (resolve find-partition-by-label
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index c6f9df5..f08bb11 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -498,25 +498,13 @@ upon error."
   (define (root-mount-point? fs)
     (string=? (file-system-mount-point fs) "/"))
 
-  (define root-fs-type
-    (or (any (lambda (fs)
-               (and (root-mount-point? fs)
-                    (file-system-type fs)))
-             mounts)
-        "ext4"))
-
-  (define root-fs-flags
-    (mount-flags->bit-mask (or (any (lambda (fs)
-                                      (and (root-mount-point? fs)
-                                           (file-system-flags fs)))
-                                    mounts)
-                               '())))
-
-  (define root-fs-options
-    (any (lambda (fs)
-           (and (root-mount-point? fs)
-                (file-system-options fs)))
-         mounts))
+  (define (device-string->file-system-device device-string)
+    ;; The "--root=SPEC" kernel command-line option always provides a
+    ;; string, but the string can represent a device, a UUID, or a
+    ;; label.  So check for all three.
+    (cond ((string-prefix? "/" device-string) device-string)
+          ((uuid device-string) => identity)
+          (else (file-system-label device-string))))
 
   (display "Welcome, this is GNU's early boot Guile.\n")
   (display "Use '--repl' for an initrd REPL.\n\n")
@@ -526,7 +514,21 @@ upon error."
       (mount-essential-file-systems)
       (let* ((args    (linux-command-line))
              (to-load (find-long-option "--load" args))
-             (root    (find-long-option "--root" args)))
+             (root-fs (find root-mount-point? mounts))
+             (root-fs-type (or (and=> root-fs file-system-type)
+                               "ext4"))
+             (root-fs-device (and=> root-fs file-system-device))
+             (root-fs-flags (mount-flags->bit-mask
+                             (or (and=> root-fs file-system-flags)
+                                 '())))
+             (root-options (if root-fs
+                               (file-system-options root-fs)
+                               #f))
+             ;; --root takes precedence over the 'device' field of the root
+             ;; <file-system> record.
+             (root-device (or (and=> (find-long-option "--root" args)
+                                     device-string->file-system-device)
+                              root-fs-device)))
 
         (when (member "--repl" args)
           (start-repl))
@@ -561,21 +563,12 @@ upon error."
 
         (setenv "EXT2FS_NO_MTAB_OK" "1")
 
-        (if root
-            ;; The "--root=SPEC" kernel command-line option always provides a
-            ;; string, but the string can represent a device, a UUID, or a
-            ;; label.  So check for all three.
-            (let ((device-spec (cond ((string-prefix? "/" root) root)
-                                     ((uuid root) => identity)
-                                     ((string-contains root ":/") #f) ; nfs
-                                     (else (file-system-label root)))))
-              (mount-root-file-system (if device-spec
-                                          (canonicalize-device-spec 
device-spec)
-                                          root)
-                                      root-fs-type
-                                      #:volatile-root? volatile-root?
-                                      #:flags root-fs-flags
-                                      #:options root-fs-options))
+        (if root-device
+            (mount-root-file-system (canonicalize-device-spec root-device)
+                                    root-fs-type
+                                    #:volatile-root? volatile-root?
+                                    #:flags root-fs-flags
+                                    #:options root-options)
             (mount "none" "/root" "tmpfs"))
 
         ;; Mount the specified file systems.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]