Skip to contentSkip to conversation

No way to set FS independent mount flags for rootfs

PATCH New Greg Depoire--Ferrer 1 participant 2 messages Jun 30, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

This old thread[1] describes the issue:
* The kernel already supports setting filesystem dependent mount data using rootflags=... but it doesn't support setting the filesystem independent mount flags (the fourth parameter in mount(2)).
* Fortunately, most initrds have custom parsing for rootflags= and understand additional flags: for instance they convert noatime into MS_NOATIME.
* But even then there is the issue of flags that can't be reset later by initrd like MS_NODEV or MS_NOSUID (not sure if this changed since then).

It seems like it would make sense for the kernel to add a command line parameter for this because for those that don't use an initrd, it seems arbitrary that the kernel already supports setting one type of flags (the fifth parameter in mount(2)) for rootfs but not the other.

In reply to this message, there is a patch that implements what was suggested in that thread: adding a 'rootopts=' parameter that takes a bitmap value for the mount flags. The name is not ideal: it would make more sense for it to be named rootflags= and the actual rootflags= to be named rootdata= according to mount(2). It works for me but I don't know if this is the right solution.

[1]: https://lkml.org/lkml/2003/8/12/203

#1 lore raw

PATCH 1/1 init: add rootopts=%d for rootfs mount flags

Add the rootopts command line parameter to specify mount flags for the root filesystem.

The kernel provides the rootflags parameter to specify filesystem dependent options when mouting the root filesystem but did not provide any way to set the filesystem independent flags.

This is not an issue on systems using an initrd because on these systems, the rootflags parameter is passed to the /sbin/mount binary which understands filesystem independent flags in the option string, such as noatime (MS_NOATIME) or nodev (MS_NODEV).

---
 Documentation/admin-guide/kernel-parameters.txt |  2 ++
 init/do_mounts.c                                | 11 +++++++++++
 2 files changed, 13 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +2 -0
index 26453f250683..01e1217583f5 100644
@@ -4851,6 +4851,8 @@
 
 	rootfstype=	[KNL] Set root filesystem type
 
+	rootopts=	[KNL] Set root filesystem mount flags bitmap
+
 	rootwait	[KNL] Wait (indefinitely) for root device to show up.
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
init/do_mounts.c +11 -0
index a78e44ee6adb..ebe51fc7cf86 100644
@@ -326,6 +326,16 @@ static int __init root_data_setup(char *str)
 	return 1;
 }
 
+static int __init root_flags_setup(char *str)
+{
+	int flags;
+
+	if (kstrtoint(str, 0, &flags))
+		return 0;
+	root_mountflags |= flags;
+	return 1;
+}
+
 static char * __initdata root_fs_names;
 static int __init fs_names_setup(char *str)
 {
@@ -341,6 +351,7 @@ static int __init root_delay_setup(char *str)
 }
 
 __setup("rootflags=", root_data_setup);
+__setup("rootopts=", root_flags_setup);
 __setup("rootfstype=", fs_names_setup);
 __setup("rootdelay=", root_delay_setup);
 
Signature · 1 line
2.31.1