From dfd10549ac5aec1379ee83d633aadd1296450dac Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 26 Jul 2023 04:25:57 +0900 Subject: [PATCH] fstab-generator: read both credentials in initrd This makes the behavior consistent with the way we already do for fstab and command line options. In initrd, entries read from fstab.extra are mounted under /sysroot. --- src/fstab-generator/fstab-generator.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 4bb727c0bb..e414529ed8 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -1309,14 +1309,16 @@ static int add_mounts_from_cmdline(void) { return ret; } -static int add_mounts_from_creds(void) { +static int add_mounts_from_creds(bool prefix_sysroot) { _cleanup_free_ void *b = NULL; struct mntent *me; int r, ret = 0; size_t bs; + assert(in_initrd() || !prefix_sysroot); + r = read_credential_with_decryption( - in_initrd() ? "fstab.extra.initrd" : "fstab.extra", + in_initrd() && !prefix_sysroot ? "fstab.extra.initrd" : "fstab.extra", &b, &bs); if (r <= 0) return r; @@ -1334,7 +1336,7 @@ static int add_mounts_from_creds(void) { me->mnt_type, me->mnt_opts, me->mnt_passno, - /* prefix_sysroot = */ false, + /* prefix_sysroot = */ prefix_sysroot, /* use_swap_enabled = */ true); if (r < 0 && ret >= 0) ret = r; @@ -1575,10 +1577,16 @@ static int run_generator(void) { if (r < 0 && ret >= 0) ret = r; - r = add_mounts_from_creds(); + r = add_mounts_from_creds(/* prefix_sysroot = */ false); if (r < 0 && ret >= 0) ret = r; + if (in_initrd()) { + r = add_mounts_from_creds(/* prefix_sysroot = */ true); + if (r < 0 && ret >= 0) + ret = r; + } + return ret; }