Open yan12125 opened 1 year ago
In https://github.com/systemd/systemd/pull/16992#issuecomment-691852234, @msekletar said:
Hence both keydev mount unit and unmount service will be pulled in and keydev FS will be mounted and then unmounted immediately.
Looks like it does not work as intended. According to my logs, both the mount unit and the unmount service are queued after the LUKS partition is unlocked:
6月 13 21:50:38 systemd[1]: run-systemd-cryptsetup-keydev\x2dArchLinux.mount: Installed new job run-systemd-cryptsetup-keydev\x2dArchLinux.mount/start as 97
6月 13 21:50:38 systemd[1]: keydev-ArchLinux-umount.service: Installed new job keydev-ArchLinux-umount.service/start as 107
While the umount service is never started before switching root:
6月 13 21:50:38 systemd[1]: keydev-ArchLinux-umount.service: starting held back, waiting for: run-systemd-cryptsetup-keydev\x2dArchLinux.mount
confirmed on 256.4-1
But i don't think it "remains", but is mounted again later.
...
Aug 08 17:21:13 archlinux systemd[1]: Found device STORAGE_DEVICE 2.
Aug 08 17:21:13 archlinux systemd[1]: Mounting /run/systemd/cryptsetup/keydev-cryptroot...
Aug 08 17:21:13 archlinux kernel: EXT4-fs (x): mounted filesystem
Aug 08 17:21:13 archlinux systemd[1]: Mounted /run/systemd/cryptsetup/keydev-cryptroot.
Aug 08 17:21:13 archlinux systemd[1]: Starting Cryptography Setup for cryptroot...
...
Aug 08 17:21:17 archlinux kernel: Key type encrypted registered
Aug 08 17:21:17 archlinux systemd[1]: Found device /dev/mapper/cryptroot.
Aug 08 17:21:17 archlinux systemd[1]: Reached target Initrd Root Device.
Aug 08 17:21:17 archlinux systemd[1]: Starting File System Check on /dev/mapper/cryptroot...
Aug 08 17:21:17 archlinux systemd[1]: Finished Cryptography Setup for cryptroot.
Aug 08 17:21:17 archlinux systemd[1]: Reached target Local Encrypted Volumes.
Aug 08 17:21:17 archlinux systemd[1]: Reached target System Initialization.
Aug 08 17:21:17 archlinux systemd[1]: Reached target Basic System.
Aug 08 17:21:17 archlinux systemd[1]: Started keydev-cryptroot-umount.service.
Aug 08 17:21:17 archlinux systemd[1]: run-systemd-cryptsetup-keydev\x2dcryptroot.mount: Deactivated successfully.
Aug 08 17:21:17 archlinux systemd[1]: keydev-cryptroot-umount.service: Deactivated successfully.
Aug 08 17:21:17 archlinux kernel: EXT4-fs (x): unmounting filesystem 123
...
Aug 08 17:21:18 archlinux systemd[1]: Mounted /sysroot.
Aug 08 17:21:18 archlinux systemd[1]: Reached target Initrd Root File System.
Aug 08 17:21:18 archlinux systemd[1]: Starting Mountpoints Configured in the Real Root...
Aug 08 17:21:18 archlinux systemd[1]: initrd-parse-etc.service: Deactivated successfully.
Aug 08 17:21:18 archlinux systemd[1]: Finished Mountpoints Configured in the Real Root.
Aug 08 17:21:18 archlinux systemd[1]: Reached target Initrd File Systems.
Aug 08 17:21:18 archlinux systemd[1]: Reached target Initrd Default Target.
Aug 08 17:21:18 archlinux systemd[1]: Starting Cleaning Up and Shutting Down Daemons...
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Initrd Default Target.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Basic System.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Initrd Root Device.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Path Units.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Slice Units.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Socket Units.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target System Initialization.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Local Encrypted Volumes.
Aug 08 17:21:18 archlinux systemd[1]: systemd-ask-password-console.path: Deactivated successfully.
Aug 08 17:21:18 archlinux systemd[1]: Stopped Dispatch Password Requests to Console Directory Watch.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Local File Systems.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Preparation for Local File Systems.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Swaps.
Aug 08 17:21:18 archlinux systemd[1]: Stopped target Timer Units.
Aug 08 17:21:18 archlinux systemd[1]: Mounting /run/systemd/cryptsetup/keydev-cryptroot...
Thank you, yes the keydev is re-mounted. Hopefully the new issue title is accurate.
@msekletar: pinging as you're the author of the relevant pull request https://github.com/systemd/systemd/pull/16992. You mentioned an issue for the mount unit:
since mount units can't have
RemainAfterExit=
I think the proposed solution is the only way to go.
Is it simpler to use a .service
instead of .mount
for mounting the keydev?
Sorry for bothering if you no longer work on this area.
I just realized my system shutsdown in a random time (from minutes to hours) after I remove the physical disk which holds the key. Maybe the re-mount is a hacky workaround for whatever is causing this?
I couldn't find it documented anywhere!
systemd version the issue has been seen with
253.5-1
Used distribution
Arch Linux
Linux kernel version used
6.3.7-arch1-1
CPU architectures issue was seen on
x86_64
Component
systemd-cryptsetup
Expected behaviour you didn't see
The cryptsetup keydev is properly unmounted
Unexpected behaviour you saw
The cryptsetup keydev is unmounted and mounted again, and remains mounted after switching root.
mount | grep keydev
shows:Steps to reproduce the problem
Setup a keydev to unlock LUKS.
rd.luks.*
to the kernel cmdline. The is the final cmdline on my system:mount | grep keydev
Additional program output to the terminal or log subsystem illustrating the issue