diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index 7caa951814..fc173289d9 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 21fa85da7d..21c3ea94a7 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 b4bcc89132..84d7edb922 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");