Skip to content

Commit dfd1054

Browse files
committed
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.
1 parent 45c535d commit dfd1054

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/fstab-generator/fstab-generator.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,14 +1309,16 @@ static int add_mounts_from_cmdline(void) {
13091309
return ret;
13101310
}
13111311

1312-
static int add_mounts_from_creds(void) {
1312+
static int add_mounts_from_creds(bool prefix_sysroot) {
13131313
_cleanup_free_ void *b = NULL;
13141314
struct mntent *me;
13151315
int r, ret = 0;
13161316
size_t bs;
13171317

1318+
assert(in_initrd() || !prefix_sysroot);
1319+
13181320
r = read_credential_with_decryption(
1319-
in_initrd() ? "fstab.extra.initrd" : "fstab.extra",
1321+
in_initrd() && !prefix_sysroot ? "fstab.extra.initrd" : "fstab.extra",
13201322
&b, &bs);
13211323
if (r <= 0)
13221324
return r;
@@ -1334,7 +1336,7 @@ static int add_mounts_from_creds(void) {
13341336
me->mnt_type,
13351337
me->mnt_opts,
13361338
me->mnt_passno,
1337-
/* prefix_sysroot = */ false,
1339+
/* prefix_sysroot = */ prefix_sysroot,
13381340
/* use_swap_enabled = */ true);
13391341
if (r < 0 && ret >= 0)
13401342
ret = r;
@@ -1575,10 +1577,16 @@ static int run_generator(void) {
15751577
if (r < 0 && ret >= 0)
15761578
ret = r;
15771579

1578-
r = add_mounts_from_creds();
1580+
r = add_mounts_from_creds(/* prefix_sysroot = */ false);
15791581
if (r < 0 && ret >= 0)
15801582
ret = r;
15811583

1584+
if (in_initrd()) {
1585+
r = add_mounts_from_creds(/* prefix_sysroot = */ true);
1586+
if (r < 0 && ret >= 0)
1587+
ret = r;
1588+
}
1589+
15821590
return ret;
15831591
}
15841592

0 commit comments

Comments
 (0)