summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-02 18:57:04 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-03-03 12:16:32 +0900
commit725ad3b06288b2beeaaf178120010612a30646e4 (patch)
treeed62db87f169bc887b495d327696270862554b44 /src/fstab-generator
parentab05bee1dd9e59a34c2f4866a1285dc29c010904 (diff)
downloadsystemd-725ad3b06288b2beeaaf178120010612a30646e4.tar.gz
fstab-generator: add new root=tmpfs option
It's useful to be able to combine a regular /usr/ file system with a tmpfs as root, for an OS that boots up in volatile mode on every single boot. Let's add explicit support for this via root=tmpfs. Note the relationship to the existing systemd.volatile= option: 1. The kernel command line "root=/dev/… systemd.volatile=yes" will mount the specified root fs, and then hide everything at the top by overmounting it with a tmpfs, except for the /usr subtree. 2. The kernel command line "root=tmpfs mount.usr=/dev/…" otoh will mount a toot fs at the top (just like the case above), but will then mount the top-level dir of the fs specified in mount.usr= directly below it. Or to say this differently: in the first case /usr/ from the physical storage fs is going to become /usr/ of the hierarchy ultimately booted, while in the second case / from the physical storage fs is going to become /usr of the hierarchy booted. Philosophically I figure systemd.volatile= is more an option for "one-off" boots, while root=tmpfs is something to have as default mode of operation for suitable images. This is currently hard to test reasonably, since Dracut refuses to accept root=tmpfs. This needs to be addressed separately though.
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index a526d6e8fa..6df7fa5328 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 */