Mount options ignored for root file system

  • Done
  • quality assurance status badge
Details
2 participants
  • Guillaume Le Vaillant
  • Ludovic Courtès
Owner
unassigned
Submitted by
Guillaume Le Vaillant
Severity
normal
G
G
Guillaume Le Vaillant wrote on 29 Oct 2019 11:22
(address . bug-guix@gnu.org)
87pnif6ec0.fsf@yamatai
The filesystem options declared for the root file system are apparently
ignored. This happens for a btrfs root filesystem on a LUKS volume.


Exerpt from '/etc/config.scm":

Toggle snippet (28 lines)
(mapped-devices
(list (mapped-device
(source
(uuid "ee90b2aa-97e8-4ae5-ac72-9bf9058cc949"))
(target "cryptroot")
(type luks-device-mapping))
(mapped-device
(source
(uuid "ec9cd327-0370-4e20-baa4-254d03b1901e"))
(target "cryptguillaume")
(type luks-device-mapping))))
(file-systems
(cons* (file-system
(mount-point "/")
(device "/dev/mapper/cryptroot")
(type "btrfs")
(options "autodefrag,compress=lzo")
(dependencies mapped-devices))
(file-system
(mount-point "/home/guillaume")
(device "/dev/mapper/cryptguillaume")
(type "btrfs")
(options "autodefrag,compress=lzo")
(dependencies mapped-devices))
%base-file-systems))


Exerpt from '/etc/fstab':

Toggle snippet (5 lines)
/dev/mapper/cryptroot / btrfs autodefrag,compress=lzo
/dev/mapper/cryptguillaume /home/guillaume btrfs autodefrag,compress=lzo


Exerpt from '/etc/mtab':

Toggle snippet (13 lines)
/dev/mapper/cryptroot / btrfs
rw,relatime,ssd,space_cache,subvolid=5,subvol=/
0 0

/dev/mapper/cryptguillaume /home/guillaume btrfs
rw,relatime,compress=lzo,ssd,space_cache,autodefrag,subvolid=5,subvol=/
0 0

/dev/mapper/cryptroot /gnu/store btrfs
ro,relatime,ssd,space_cache,subvolid=5,subvol=/gnu/store
0 0

Here we see that the options 'autodefrag' and 'compress=lzo' have
disappeared on the root filesystem. Maybe it has something to do with
the new '/gnu/store' subvolume that appeared?
G
G
Guillaume Le Vaillant wrote on 7 Nov 2019 19:28
(address . 37977@debbugs.gnu.org)
87eeyjils5.fsf@yamatai
Guillaume Le Vaillant skribis:

Toggle quote (3 lines)
> The filesystem options declared for the root file system are apparently
> ignored. This happens for a btrfs root filesystem on a LUKS volume.

This also happens on a basic btrfs root file system (without LUKS).

I tried adding "rootflags=defaults,autodefrag,compress=lzo" in kernel
arguments, but it didn't have any effect.

I then tried adding a one-shot service that remounts the root file
system, and it works, the options declared in '/etc/fstab' are taken
into consideration. This service just does 'mount -o remount /'.

Toggle snippet (22 lines)
(define remount-rootfs-service-type
(shepherd-service-type
'remount-rootfs
(const
(shepherd-service
(documentation "Remount rootfs with correct options.")
(requirement '(udev))
(provision '(remount-rootfs))
(one-shot? #t)
(start #~(lambda _
(invoke (string-append #$util-linux "/bin/mount")
"-o" "remount" "/")))))))

(operating-system
...
(services
(cons* ...
(service remount-rootfs-service-type #f)
...)))


I saw that the 'start' function of 'root-file-system-service-type'
doesn't do anything. Is it on purpose? Or could we make it remount the
root filesystem?
L
L
Ludovic Courtès wrote on 17 Nov 2019 11:43
Re: bug#37977: Mount options ignored for root file system
(name . Guillaume Le Vaillant)(address . glv@posteo.net)(address . 37977@debbugs.gnu.org)
87bltapyuc.fsf@gnu.org
Hi Guillaume,

Guillaume Le Vaillant <glv@posteo.net> skribis:

Toggle quote (10 lines)
> Guillaume Le Vaillant skribis:
>
>> The filesystem options declared for the root file system are apparently
>> ignored. This happens for a btrfs root filesystem on a LUKS volume.
>
> This also happens on a basic btrfs root file system (without LUKS).
>
> I tried adding "rootflags=defaults,autodefrag,compress=lzo" in kernel
> arguments, but it didn't have any effect.

[...]

Toggle quote (4 lines)
> I saw that the 'start' function of 'root-file-system-service-type'
> doesn't do anything. Is it on purpose? Or could we make it remount the
> root filesystem?

By definition, when shepherd is started, the root file system is already
mounted; that’s why the ‘start’ method of the ‘root-file-system-service’
does nothing.

The root file system is mounted by ‘mount-root-file-system’ in
linux-boot.scm, and you’re right: it happily ignores any options in the
<file-system> object for “/”. :-)

A solution would be to have ‘boot-system’ take an additional
#:root-file-system-options parameter that it would pass down to
‘mount-root-file-system’, which would honor it.

Would you like to give it a try?

Thanks,
Ludo’.
G
G
Guillaume Le Vaillant wrote on 17 Nov 2019 15:17
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 37977@debbugs.gnu.org)
87pnhqy4cr.fsf@yamatai
Ludovic Courtès skribis:

Toggle quote (10 lines)
> The root file system is mounted by ‘mount-root-file-system’ in
> linux-boot.scm, and you’re right: it happily ignores any options in the
> <file-system> object for “/”. :-)
>
> A solution would be to have ‘boot-system’ take an additional
> #:root-file-system-options parameter that it would pass down to
> ‘mount-root-file-system’, which would honor it.
>
> Would you like to give it a try?

The attached patch adds an 'options' parameter to
'mount-root-file-system' and makes 'boot-system' use it with the
content of the 'options' field of the <file-system> object for "/".

It's not exactly the solution you described (adding a keyword argument
to 'boot-system'), but I think it should work. What do you think?

I tried it with my btrfs root file system, and it is correctly mounted
with the options declared in my '/etc/config.scm' file.
From 3597f0fda6f6a13bf1fdab0fcde4f72ece688d93 Mon Sep 17 00:00:00 2001
From: Guillaume Le Vaillant <glv@posteo.net>
Date: Sun, 17 Nov 2019 14:15:21 +0100
Subject: [PATCH] linux-boot: Don't ignore options when mounting root file
system.

* gnu/build/linux-boot.scm (mount-root-file-system): Add the 'options'
keyword argument and use it when mounting the root file system.
(boot-system): Pass the root file system options to
'mount-root-file-system'.
---
gnu/build/linux-boot.scm | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

Toggle diff (66 lines)
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 84a5447977..a8a9c2e2c8 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 <ludo@gnu.org>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -357,15 +358,16 @@ the last argument of `mknod'."
(filter-map string->number (scandir "/proc")))))
(define* (mount-root-file-system root type
- #:key volatile-root?)
+ #:key volatile-root? options)
"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."
+using the kernel built-in overlayfs. OPTIONS indicates the options to use
+to mount ROOT."
(if volatile-root?
(begin
(mkdir-p "/real-root")
- (mount root "/real-root" type MS_RDONLY)
+ (mount root "/real-root" type MS_RDONLY options)
(mkdir-p "/rw-root")
(mount "none" "/rw-root" "tmpfs")
@@ -382,7 +384,7 @@ 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 0 options)))
;; Make sure /root/etc/mtab is a symlink to /proc/self/mounts.
(false-if-exception
@@ -472,6 +474,12 @@ upon error."
mounts)
"ext4"))
+ (define root-fs-options
+ (any (lambda (fs)
+ (and (root-mount-point? fs)
+ (file-system-options fs)))
+ mounts))
+
(display "Welcome, this is GNU's early boot Guile.\n")
(display "Use '--repl' for an initrd REPL.\n\n")
@@ -524,7 +532,8 @@ upon error."
(else (file-system-label root)))))
(mount-root-file-system (canonicalize-device-spec root)
root-fs-type
- #:volatile-root? volatile-root?))
+ #:volatile-root? volatile-root?
+ #:options root-fs-options))
(mount "none" "/root" "tmpfs"))
;; Mount the specified file systems.
--
2.24.0
L
L
Ludovic Courtès wrote on 18 Nov 2019 11:32
(name . Guillaume Le Vaillant)(address . glv@posteo.net)(address . 37977-done@debbugs.gnu.org)
878sodlbkf.fsf@gnu.org
Hello Guillaume,

Guillaume Le Vaillant <glv@posteo.net> skribis:

Toggle quote (7 lines)
> The attached patch adds an 'options' parameter to
> 'mount-root-file-system' and makes 'boot-system' use it with the
> content of the 'options' field of the <file-system> object for "/".
>
> It's not exactly the solution you described (adding a keyword argument
> to 'boot-system'), but I think it should work. What do you think?

It looks great to me.

Toggle quote (11 lines)
> From 3597f0fda6f6a13bf1fdab0fcde4f72ece688d93 Mon Sep 17 00:00:00 2001
> From: Guillaume Le Vaillant <glv@posteo.net>
> Date: Sun, 17 Nov 2019 14:15:21 +0100
> Subject: [PATCH] linux-boot: Don't ignore options when mounting root file
> system.
>
> * gnu/build/linux-boot.scm (mount-root-file-system): Add the 'options'
> keyword argument and use it when mounting the root file system.
> (boot-system): Pass the root file system options to
> 'mount-root-file-system'.

Applied, thanks!

Ludo’.
Closed
?