Skip to content

systemd: errors in unmounting file systems with option x-initrd.mount at shutdown #35268

@ghost

Description

Issue description

Systemd tries to unmount filesystems with option x-initrd.mount at shutdown producing such errors:

[  OK  ] Unmounted /run/user/0.
[  OK  ] Unmounted /run/wrappers.
[  OK  ] Unmounted /run/keys.
systemd[1]: Failed unmounting /firmware.
[FAILED] Failed unmounting /firmware.
[  OK  ] Stopped Load/Save Random Seed.
[  OK  ] Stopped Update UTMP about System Boot/Shutdown.
[  OK  ] Stopped Journal Service.
[  OK  ] Reached target Unmount All Filesystems.

The issue is first seen in NixOS systemd v233 and still exists now (current systemd version is v237). It was already fixed in upstream systemd (see systemd/systemd#4817) but still exists in NixOS.

Steps to reproduce

Following systemd/systemd#4817 (comment) gives

[root@NIXOS:~]# systemctl --version
systemd 234
+PAM +AUDIT -SELINUX +IMA +APPARMOR -SMACK -SYSVINIT +UTMP -LIBCRYPTSETUP +GCRYPT -GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN default-hierarchy=hybrid

[root@NIXOS:~]# mount --version
mount from util-linux 2.31.1 (libmount 2.31.1: btrfs, assert, debug)

[root@NIXOS:~]# mkdir -p /test

[root@NIXOS:~]# mount -t tmpfs -o x-initrd.mount tmpfs /test

[root@NIXOS:~]# cat /run/mount/utab
SRC=tmpfs TARGET=/test ROOT=/ OPTS=x-initrd.mount

[root@NIXOS:~]# systemctl show --property=Conflicts test.mount
Conflicts=umount.target

[root@NIXOS:~]#

So, the bug does still exist, although it has already been fixed in the upstream systemd since v233.

Proposed fix

There is a code duplication in current NixOS' systemd. Please, take a look:

https://github.com/NixOS/systemd/blob/nixos-v237/src/core/mount.c#L446
https://github.com/NixOS/systemd/blob/nixos-v237/src/core/mount.c#L413

Lines 454..475 here are almost identical to lines 421..441, except the x-initrd.mount mount option check. There is a patch, accepted in upstream systemd since v233, that fixes this situation:

systemd/systemd@ad2706d#diff-a55dd3f995e0ee0a2ba83f24f9492eebL405

but it was not accompanied into NixOS' systemd yet. Thus we need to patch current systemd with the diff:

--- systemd-237-nixos/src/core/mount.c	1970-01-01 03:00:01.000000000 +0300
+++ systemd-237/src/core/mount.c	2018-01-28 18:58:17.000000000 +0300
@@ -454,20 +452,10 @@
         if (!UNIT(m)->default_dependencies)
                 return 0;
 
-        if (!MANAGER_IS_SYSTEM(UNIT(m)->manager))
-                return 0;
-
-        /* We do not add any default dependencies to /, /usr or
-         * /run/initramfs/, since they are guaranteed to stay
-         * mounted the whole time, since our system is on it.
-         * Also, don't bother with anything mounted below virtual
-         * file systems, it's also going to be virtual, and hence
-         * not worth the effort. */
-        if (PATH_IN_SET(m->where, "/", "/usr", "/nix", "/nix/store") ||
-            path_startswith(m->where, "/run/initramfs") ||
-            path_startswith(m->where, "/proc") ||
-            path_startswith(m->where, "/sys") ||
-            path_startswith(m->where, "/dev"))
+        /* We do not add any default dependencies to /, /usr or /run/initramfs/, since they are guaranteed to stay
+         * mounted the whole time, since our system is on it.  Also, don't bother with anything mounted below virtual
+         * file systems, it's also going to be virtual, and hence not worth the effort. */
+        if (mount_is_extrinsic(m))
                 return 0;
 
         p = get_mount_parameters(m);

for x-initrd.mount mount option to work correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions