From b56aea9c62b015c8a8b48827f9587b1578c83af3 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 18 Jul 2019 04:59:25 +0900 Subject: [PATCH 4/4] linux-boot: Honor "rootflags" kernel argument. * gnu/build/linux-boot.scm (mount-root-file-system): Add the optional FLAGS and OPTIONS arguments; and document them. Pass those to the `mount' calls. (boot-system): Parse the "rootflags" kernel argument, and use it when calling `mount-root-file-system'. * doc/guix.texi (Initial RAM Disk): Document the use of the "rootflags" argument. --- doc/guix.texi | 19 +++++++++++++++++++ gnu/build/linux-boot.scm | 22 +++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index cc7c91ac92..1e093b38a0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -24761,6 +24761,25 @@ Instruct the initial RAM disk as well as the @command{modprobe} command must be a comma-separated list of module names---e.g., @code{usbkbd,9pnet}. +@item rootflags=@var{options}@dots{} +@cindex mount options, passed to initrd +@cindex rootflags, initrd +This argument allows passing one or multiple file system specific mount +options to the @code{mount} procedure used by the init script. @var{options} +must be a comma-separated list of option names or option-value pairs. The +following example instructs the initial RAM disk to mount the Btrfs subvolume +named ``rootfs'' as the root file system, and to enable automatic file +defragmentation: + +@example +rootflags=subvol=rootfs,autodefrag +@end example + +Specifying the subvolume to mount by its name, as shown above, is also used in +Guix to produce a working Grub configuration for the Grub-based bootloaders +when using a Btrfs subvolume for the root file system (@xref{Bootloader +Configuration}). + @item --repl Start a read-eval-print loop (REPL) from the initial RAM disk before it tries to load kernel modules and to mount the root file system. Our diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index b4e6421b27..b2d8f74a71 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe +;;; Copyright © 2019 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -360,15 +361,16 @@ the last argument of `mknod'." (filter-map string->number (scandir "/proc"))))) (define* (mount-root-file-system root type + #:optional (flags 0) options #:key volatile-root?) - "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? -is true, mount ROOT read-only and make it an overlay with a writable tmpfs -using the kernel built-in overlayfs." - + "Mount the root file system of type TYPE at device ROOT. The optional FLAGS +and OPTIONS arguments behave the same as for the `mount' procedure. If +VOLATILE-ROOT? is true, mount ROOT read-only and make it an overlay with a +writable tmpfs using the kernel built-in overlayfs." (if volatile-root? (begin (mkdir-p "/real-root") - (mount root "/real-root" type MS_RDONLY) + (mount root "/real-root" type (logior MS_RDONLY flags) options) (mkdir-p "/rw-root") (mount "none" "/rw-root" "tmpfs") @@ -385,11 +387,11 @@ using the kernel built-in overlayfs." "lowerdir=/real-root,upperdir=/rw-root/upper,workdir=/rw-root/work")) (begin (check-file-system root type) - (mount root "/root" type))) + (mount root "/root" type flags options))) ;; Make sure /root/etc/mtab is a symlink to /proc/self/mounts. (false-if-exception - (delete-file "/root/etc/mtab")) + (delete-file "/root/etc/mtab")) (mkdir-p "/root/etc") (symlink "/proc/self/mounts" "/root/etc/mtab")) @@ -483,7 +485,8 @@ 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 (find-long-option "--root" args)) + (rootflags (find-long-option "rootflags" args))) (when (member "--repl" args) (start-repl)) @@ -526,7 +529,8 @@ upon error." ((uuid root) => identity) (else (file-system-label root))))) (mount-root-file-system (canonicalize-device-spec root) - root-fs-type + root-fs-type 0 + rootflags #:volatile-root? volatile-root?)) (mount "none" "/root" "tmpfs")) -- 2.23.0