Skip to content

Commit

Permalink
fstab-generator: allow overriding path to /sysroot/etc/fstab too
Browse files Browse the repository at this point in the history
This adds $SYSTEMD_SYSROOT_FSTAB analoguous to $SYSTEMD_FSTAB.
  • Loading branch information
keszybz committed Jul 15, 2022
1 parent 7772c17 commit 99e3d47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 3 additions & 3 deletions man/systemd-fstab-generator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
10 changes: 9 additions & 1 deletion src/fstab-generator/fstab-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 99e3d47

Please sign in to comment.