summaryrefslogtreecommitdiffstats
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-07-26 02:39:23 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-07-26 17:50:15 +0200
commit22f5a825e40ad9c8eeae18b763676759d24bb434 (patch)
tree02dd882a7534f9033c7affa25fabd1e85a58188c /src/fstab-generator
parentfstab-generator: read both credentials in initrd (diff)
downloadsystemd-22f5a825e40ad9c8eeae18b763676759d24bb434.tar.xz
systemd-22f5a825e40ad9c8eeae18b763676759d24bb434.zip
fstab-generator: add a flag to accept entry for "/" in initrd
When both prefix_sysroot and accept_root is true, the entry for "/" will be accepted and converted to "/sysroot/". Why? If the entry is read from the main system's fstab, then we already mounted /sysroot/, hence it is not and should not re-add the .mount unit for /sysroot/. However, if we want to specify the root mount through the kernel command line or credential, without this change, we need to specify the same entry in the two options. E.g. === systemd.mount-extra=/dev/sda1:/:auto:defaults rd.systemd.mount-extra=/dev/sda1:/sysroot:auto:defaults === That's inconvenient. Of course, we can dedup that by using traditional options, but cannot when defined in credential.
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index e414529ed8..103c55c7c7 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -314,9 +314,9 @@ static bool mount_is_network(const char *fstype, const char *options) {
(fstype && fstype_is_network(fstype));
}
-static bool mount_in_initrd(const char *where, const char *options) {
+static bool mount_in_initrd(const char *where, const char *options, bool accept_root) {
return fstab_test_option(options, "x-initrd.mount\0") ||
- (where && path_equal(where, "/usr"));
+ (where && PATH_IN_SET(where, "/usr", accept_root ? "/" : NULL));
}
static int write_timeout(
@@ -851,6 +851,7 @@ static int parse_fstab_one(
const char *options,
int passno,
bool prefix_sysroot,
+ bool accept_root, /* This takes an effect only when prefix_sysroot is true. */
bool use_swap_enabled) {
_cleanup_free_ char *what = NULL, *where = NULL;
@@ -862,7 +863,7 @@ static int parse_fstab_one(
assert(fstype);
assert(options);
- if (prefix_sysroot && !mount_in_initrd(where_original, options))
+ if (prefix_sysroot && !mount_in_initrd(where_original, options, accept_root))
return 0;
is_swap = streq_ptr(fstype, "swap");
@@ -982,7 +983,9 @@ static int parse_fstab(bool prefix_sysroot) {
while ((me = getmntent(f))) {
r = parse_fstab_one(fstab,
me->mnt_fsname, me->mnt_dir, me->mnt_type, me->mnt_opts, me->mnt_passno,
- prefix_sysroot, /* use_swap_enabled = */ true);
+ prefix_sysroot,
+ /* accept_root = */ false,
+ /* use_swap_enabled = */ true);
if (r < 0 && ret >= 0)
ret = r;
if (arg_sysroot_check && r > 0)
@@ -1301,6 +1304,7 @@ static int add_mounts_from_cmdline(void) {
m->options,
/* passno = */ 0,
/* prefix_sysroot = */ !m->for_initrd && in_initrd(),
+ /* accept_root = */ true,
/* use_swap_enabled = */ false);
if (r < 0 && ret >= 0)
ret = r;
@@ -1337,6 +1341,7 @@ static int add_mounts_from_creds(bool prefix_sysroot) {
me->mnt_opts,
me->mnt_passno,
/* prefix_sysroot = */ prefix_sysroot,
+ /* accept_root = */ true,
/* use_swap_enabled = */ true);
if (r < 0 && ret >= 0)
ret = r;