diff --git a/man/systemd-fstab-generator.xml b/man/systemd-fstab-generator.xml index ec8f5c988e1..3c5a5cc50a3 100644 --- a/man/systemd-fstab-generator.xml +++ b/man/systemd-fstab-generator.xml @@ -82,9 +82,20 @@ root= - Takes the root filesystem to mount in the - initrd. root= is honored by the - initrd. + Configures the operating system's root filesystem to mount when running in the + initrd. This accepts a device node path (usually /dev/disk/by-uuid/… or + /dev/disk/by-label/… or similar), or the special values gpt-auto + and tmpfs. + + Use gpt-auto to explicitly request automatic root file system discovery via + systemd-gpt-auto-generator8. + + Use tmpfs in order to mount a tmpfs5 file + system as root file system of the OS. This is useful in combination with + mount.usr= (see below) in order to combine a volatile root file system with a + separate, immutable /usr/ file system. Also see + systemd.volatile= below. @@ -193,10 +204,19 @@ or any other resources stored in the root file system are physically removed. It's thus safe to boot a system that is normally operated in non-volatile mode temporarily into volatile mode, without losing data. - Note that with the exception of overlay mode, enabling this setting will only work - correctly on operating systems that can boot up with only /usr/ mounted, and are able to - automatically populate /etc/, and also /var/ in case of - systemd.volatile=yes. + Note that with the exception of overlay mode, enabling this setting will + only work correctly on operating systems that can boot up with only /usr/ + mounted, and are able to automatically populate /etc/, and also + /var/ in case of systemd.volatile=yes. + + Also see root=tmpfs above, for a method to combine a + tmpfs file system with a regular /usr/ file system (as + configured via mount.usr=). The main distinction between + systemd.volatile=yes, and root=tmpfs in combination + mount.usr= is that the former operates on top of a regular root file system and + temporarily obstructs the files and directories above its /usr/ subdirectory, + while the latter does not hide any files, but simply mounts a unpopulated tmpfs as root file system + and combines it with a user picked /usr/ file system. @@ -218,6 +238,7 @@ systemd.mount5, systemd.swap5, systemd-cryptsetup-generator8, + systemd-gpt-auto-generator8, kernel-command-line7 diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index a526d6e8fa8..6df7fa53289 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -671,7 +671,8 @@ static int parse_fstab(bool initrd) { static int add_sysroot_mount(void) { _cleanup_free_ char *what = NULL; - const char *opts; + const char *opts, *fstype; + bool default_rw; int r; if (isempty(arg_root_what)) { @@ -691,12 +692,29 @@ static int add_sysroot_mount(void) { return 0; } - what = fstab_node_to_udev_node(arg_root_what); - if (!what) - return log_oom(); + if (streq(arg_root_what, "tmpfs")) { + /* If root=tmpfs is specified, then take this as shortcut for a writable tmpfs mount as root */ + + what = strdup("rootfs"); /* just a pretty name, to show up in /proc/self/mountinfo */ + if (!what) + return log_oom(); + + fstype = arg_root_fstype ?: "tmpfs"; /* tmpfs, unless overriden */ + + default_rw = true; /* writable, unless overriden */; + } else { + + what = fstab_node_to_udev_node(arg_root_what); + if (!what) + return log_oom(); + + fstype = arg_root_fstype; /* if not specified explicitly, don't default to anything here */ + + default_rw = false; /* read-only, unless overriden */ + } if (!arg_root_options) - opts = arg_root_rw > 0 ? "rw" : "ro"; + opts = arg_root_rw > 0 || (arg_root_rw < 0 && default_rw) ? "rw" : "ro"; else if (arg_root_rw >= 0 || !fstab_test_option(arg_root_options, "ro\0" "rw\0")) opts = strjoina(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro"); @@ -715,7 +733,7 @@ static int add_sysroot_mount(void) { what, "/sysroot", NULL, - arg_root_fstype, + fstype, opts, is_device_path(what) ? 1 : 0, /* passno */ 0, /* makefs off, growfs off, noauto off, nofail off, automount off */