From: Zbigniew Jędrzejewski-Szmek Date: Thu, 14 Jul 2022 11:29:06 +0000 (+0200) Subject: fstab-generator: allow overriding path to /sysroot/etc/fstab too X-Git-Tag: v252-rc1~627^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99e3d4767932bce5febb45e8543162d729d17425;p=thirdparty%2Fsystemd.git fstab-generator: allow overriding path to /sysroot/etc/fstab too This adds $SYSTEMD_SYSROOT_FSTAB analoguous to $SYSTEMD_FSTAB. --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 7caa9518145..fc173289d96 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -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`. diff --git a/man/systemd-fstab-generator.xml b/man/systemd-fstab-generator.xml index 21fa85da7d8..21c3ea94a70 100644 --- a/man/systemd-fstab-generator.xml +++ b/man/systemd-fstab-generator.xml @@ -46,7 +46,7 @@ for more information about special /etc/fstab mount options this generator understands. - One special topic is handling of symbolic links. Historical init + One special topic is handling of symbolic links. Historical init implementations supported symlinks in /etc/fstab. 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 @@ systemd.swap5, systemd-cryptsetup-generator8, systemd-gpt-auto-generator8, - kernel-command-line7 + kernel-command-line7, + Known Environment Variables - diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b4bcc891327..84d7edb9223 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -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");