]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: add SYSTEMD_SYSFS_CHECK env var
authorLily Foster <lily@lily.flowers>
Wed, 25 Jan 2023 23:52:06 +0000 (18:52 -0500)
committerLily Foster <lily@lily.flowers>
Thu, 26 Jan 2023 00:05:11 +0000 (19:05 -0500)
This forces processing of /dev entries in fstab when running in a
container is detected (checked as the existence of read-only /sys).

docs/ENVIRONMENT.md
src/fstab-generator/fstab-generator.c

index ef0141e1a6343e90db95dac368da7f0d2549c19f..9f5666c0194e8fef8b242bb9d45e2a341d711719 100644 (file)
@@ -54,6 +54,10 @@ All tools:
 * `$SYSTEMD_SYSROOT_FSTAB` — if set, use this path instead of
   `/sysroot/etc/fstab`. Only useful for debugging `systemd-fstab-generator`.
 
+* `$SYSTEMD_SYSFS_CHECK` — takes a boolean. If set, overrides sysfs container
+  detection that ignores `/dev/` entries in 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`.
index 2ad86a898021b4eae8ab1d3920576b0d40f910b4..3288e117d7fec3e7d03c2cf0cd968ac9c13dd10c 100644 (file)
@@ -9,6 +9,7 @@
 #include "bus-locator.h"
 #include "chase-symlinks.h"
 #include "efi-loader.h"
+#include "env-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fstab-util.h"
@@ -667,7 +668,7 @@ static int parse_fstab(bool initrd) {
         _cleanup_endmntent_ FILE *f = NULL;
         const char *fstab;
         struct mntent *me;
-        int r = 0;
+        int r = 0, sysfs_check = -1;
 
         if (initrd)
                 fstab = sysroot_fstab_path();
@@ -705,7 +706,14 @@ static int parse_fstab(bool initrd) {
                                 continue;
                         }
 
-                        if (is_device_path(what)) {
+                        if (sysfs_check < 0) {
+                                r = getenv_bool_secure("SYSTEMD_SYSFS_CHECK");
+                                if (r < 0 && r != -ENXIO)
+                                        log_debug_errno(r, "Failed to parse $SYSTEMD_SYSFS_CHECK, ignoring: %m");
+                                sysfs_check = r != 0;
+                        }
+
+                        if (sysfs_check && is_device_path(what)) {
                                 log_info("/sys/ is read-only (running in a container?), ignoring fstab device entry for %s.", what);
                                 continue;
                         }