{"action":"closed","issue":{"url":"https://api.github.com/repos/NixOS/nixpkgs/issues/35268","repository_url":"https://api.github.com/repos/NixOS/nixpkgs","labels_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/35268/labels{/name}","comments_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/35268/comments","events_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/35268/events","html_url":"https://github.com/NixOS/nixpkgs/issues/35268","id":298915589,"number":35268,"title":"systemd: errors in unmounting file systems with option `x-initrd.mount` at shutdown","user":{"login":"tk-ecotelecom","id":15086713,"avatar_url":"https://avatars1.githubusercontent.com/u/15086713?v=4","gravatar_id":"","url":"https://api.github.com/users/tk-ecotelecom","html_url":"https://github.com/tk-ecotelecom","followers_url":"https://api.github.com/users/tk-ecotelecom/followers","following_url":"https://api.github.com/users/tk-ecotelecom/following{/other_user}","gists_url":"https://api.github.com/users/tk-ecotelecom/gists{/gist_id}","starred_url":"https://api.github.com/users/tk-ecotelecom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tk-ecotelecom/subscriptions","organizations_url":"https://api.github.com/users/tk-ecotelecom/orgs","repos_url":"https://api.github.com/users/tk-ecotelecom/repos","events_url":"https://api.github.com/users/tk-ecotelecom/events{/privacy}","received_events_url":"https://api.github.com/users/tk-ecotelecom/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-02-21T10:29:54Z","updated_at":"2018-03-03T09:44:12Z","closed_at":"2018-03-03T09:44:12Z","author_association":"CONTRIBUTOR","body":"## Issue description\r\n\r\nSystemd tries to unmount filesystems with option `x-initrd.mount` at shutdown producing such errors:\r\n\r\n```\r\n[  OK  ] Unmounted /run/user/0.\r\n[  OK  ] Unmounted /run/wrappers.\r\n[  OK  ] Unmounted /run/keys.\r\nsystemd[1]: Failed unmounting /firmware.\r\n[FAILED] Failed unmounting /firmware.\r\n[  OK  ] Stopped Load/Save Random Seed.\r\n[  OK  ] Stopped Update UTMP about System Boot/Shutdown.\r\n[  OK  ] Stopped Journal Service.\r\n[  OK  ] Reached target Unmount All Filesystems.\r\n```\r\n\r\nThe 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 https://github.com/systemd/systemd/issues/4817) but still exists in NixOS.\r\n\r\n### Steps to reproduce\r\n\r\nFollowing https://github.com/systemd/systemd/issues/4817#issuecomment-266612756 gives\r\n\r\n```\r\n[root@NIXOS:~]# systemctl --version\r\nsystemd 234\r\n+PAM +AUDIT -SELINUX +IMA +APPARMOR -SMACK -SYSVINIT +UTMP -LIBCRYPTSETUP +GCRYPT -GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN default-hierarchy=hybrid\r\n\r\n[root@NIXOS:~]# mount --version\r\nmount from util-linux 2.31.1 (libmount 2.31.1: btrfs, assert, debug)\r\n\r\n[root@NIXOS:~]# mkdir -p /test\r\n\r\n[root@NIXOS:~]# mount -t tmpfs -o x-initrd.mount tmpfs /test\r\n\r\n[root@NIXOS:~]# cat /run/mount/utab\r\nSRC=tmpfs TARGET=/test ROOT=/ OPTS=x-initrd.mount\r\n\r\n[root@NIXOS:~]# systemctl show --property=Conflicts test.mount\r\nConflicts=umount.target\r\n\r\n[root@NIXOS:~]#\r\n```\r\n\r\nSo, the bug does still exist, although it has already been fixed in the upstream systemd since v233.\r\n\r\n## Proposed fix\r\n\r\nThere is a code duplication in current NixOS' systemd. Please, take a look:\r\n\r\nhttps://github.com/NixOS/systemd/blob/nixos-v237/src/core/mount.c#L446\r\nhttps://github.com/NixOS/systemd/blob/nixos-v237/src/core/mount.c#L413\r\n\r\nLines 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:\r\n\r\nhttps://github.com/systemd/systemd/commit/ad2706db7cceba69203f3ac2b6ef65d7490c5f29#diff-a55dd3f995e0ee0a2ba83f24f9492eebL405\r\n\r\nbut it was not accompanied into NixOS' systemd yet. Thus we need to patch current systemd with the diff:\r\n\r\n```\r\n--- systemd-237-nixos/src/core/mount.c\t1970-01-01 03:00:01.000000000 +0300\r\n+++ systemd-237/src/core/mount.c\t2018-01-28 18:58:17.000000000 +0300\r\n@@ -454,20 +452,10 @@\r\n         if (!UNIT(m)->default_dependencies)\r\n                 return 0;\r\n \r\n-        if (!MANAGER_IS_SYSTEM(UNIT(m)->manager))\r\n-                return 0;\r\n-\r\n-        /* We do not add any default dependencies to /, /usr or\r\n-         * /run/initramfs/, since they are guaranteed to stay\r\n-         * mounted the whole time, since our system is on it.\r\n-         * Also, don't bother with anything mounted below virtual\r\n-         * file systems, it's also going to be virtual, and hence\r\n-         * not worth the effort. */\r\n-        if (PATH_IN_SET(m->where, \"/\", \"/usr\", \"/nix\", \"/nix/store\") ||\r\n-            path_startswith(m->where, \"/run/initramfs\") ||\r\n-            path_startswith(m->where, \"/proc\") ||\r\n-            path_startswith(m->where, \"/sys\") ||\r\n-            path_startswith(m->where, \"/dev\"))\r\n+        /* We do not add any default dependencies to /, /usr or /run/initramfs/, since they are guaranteed to stay\r\n+         * mounted the whole time, since our system is on it.  Also, don't bother with anything mounted below virtual\r\n+         * file systems, it's also going to be virtual, and hence not worth the effort. */\r\n+        if (mount_is_extrinsic(m))\r\n                 return 0;\r\n \r\n         p = get_mount_parameters(m);\r\n```\r\n\r\nfor `x-initrd.mount` mount option to work correctly."}}
{"actor":{"display_login":"aszlig"}}