]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: drop nofail and noauto options for critical mounts
authorMichal Sekletar <msekleta@redhat.com>
Wed, 25 Oct 2023 11:17:18 +0000 (13:17 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 26 Oct 2023 23:07:54 +0000 (00:07 +0100)
Setting nofail for /usr mount doesn't make sense because without /usr we
can't really boot. However, having the flag set might cause races in
initrd where we could try to switchroot into rootfs before /usr is
actually mounted. Let's just ignore it so that we always have proper
mount unit ordering for /sysroot/usr mount.

src/fstab-generator/fstab-generator.c

index 5a5c05df0c22547aacc4d3c0d860a59cb30b3354..7617f2b2a5f5fb59796570dd2cfcf7147fef1f22 100644 (file)
@@ -853,7 +853,7 @@ static int parse_fstab_one(
                 bool accept_root, /* This takes an effect only when prefix_sysroot is true. */
                 bool use_swap_enabled) {
 
-        _cleanup_free_ char *what = NULL, *where = NULL;
+        _cleanup_free_ char *what = NULL, *where = NULL, *opts = NULL;
         MountPointFlags flags;
         bool is_swap, where_changed;
         int r;
@@ -936,6 +936,17 @@ static int parse_fstab_one(
                         mount_is_network(fstype, options) ? SPECIAL_REMOTE_FS_TARGET :
                                                             SPECIAL_LOCAL_FS_TARGET;
 
+        /* nofail or noauto don't make sense for critical filesystems we must mount in initrd. */
+        if ((is_sysroot || is_sysroot_usr) && ((flags & (MOUNT_NOFAIL|MOUNT_NOAUTO)) != 0)) {
+                flags &= ~(MOUNT_NOFAIL|MOUNT_NOAUTO);
+                r = fstab_filter_options(options, "noauto\0nofail\0", NULL, NULL, NULL, &opts);
+                if (r < 0)
+                        return r;
+
+                log_debug("'noauto' and 'nofail' options are ignored for /sysroot/ and /sysroot/usr/ mounts.");
+                options = opts;
+        }
+
         r = add_mount(source,
                       arg_dest,
                       what,