fstab-generator: allow overriding path to /sysroot/etc/fstab too

This adds $SYSTEMD_SYSROOT_FSTAB analoguous to $SYSTEMD_FSTAB.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-07-14 13:29:06 +02:00
parent 7772c177b8
commit 99e3d47679
3 changed files with 15 additions and 4 deletions

View file

@ -51,6 +51,9 @@ All tools:
* `$SYSTEMD_FSTAB` — if set, use this path instead of `/etc/fstab`. Only useful
for debugging.
* `$SYSTEMD_SYSROOT_FSTAB` — if set, use this path instead of
`/sysroot/etc/fstab`. Only useful for debugging `systemd-fstab-generator`.
* `$SYSTEMD_CRYPTTAB` — if set, use this path instead of `/etc/crypttab`. Only
useful for debugging. Currently only supported by
`systemd-cryptsetup-generator`.

View file

@ -46,7 +46,7 @@
for more information about special <filename>/etc/fstab</filename>
mount options this generator understands.</para>
<para>One special topic is handling of symbolic links. Historical init
<para>One special topic is handling of symbolic links. Historical init
implementations supported symlinks in <filename>/etc/fstab</filename>.
Because mount units will refuse mounts where the target is a symbolic link,
this generator will resolve any symlinks as far as possible when processing
@ -251,8 +251,8 @@
<citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-cryptsetup-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
<ulink url="https://systemd.io/ENVIRONMENT/">Known Environment Variables</ulink>
</para>
</refsect1>
</refentry>

View file

@ -570,13 +570,21 @@ static int add_mount(
return 0;
}
static const char* sysroot_fstab_path(void) {
return getenv("SYSTEMD_SYSROOT_FSTAB") ?: "/sysroot/etc/fstab";
}
static int parse_fstab(bool initrd) {
_cleanup_endmntent_ FILE *f = NULL;
const char *fstab;
struct mntent *me;
int r = 0;
fstab = initrd ? "/sysroot/etc/fstab" : fstab_path();
if (initrd)
fstab = sysroot_fstab_path();
else
fstab = fstab_path();
log_debug("Parsing %s...", fstab);
f = setmntent(fstab, "re");