Skip to content

feature: safely close devices on shutdown

Teej Tj requested to merge Iam_Tj/initramfs-tools:feature-shutdown-initrd into master

Implement a tiny and simple in-memory file-system to reverse the operations that were required to mount the root file-system. That means unmounting the root-file system and safely closing any underlying (virtual) devices such as device-mapper, LUKS, LVM and allowing correct shutdown of devices such as NVME.

systemd-shutdown has provided support for this for some time and dracut uses it. This script is generic enough to be used with other init systems.

If demand arises it can be extended to install shell scripts and their supporting resources using the mkinitramfs conf/hooks logic for complex scenarios, but lets start with something that works for the majority of installs.

Closes: bug #778849


I put this together today after reading the Bookworm release notes and following the Known Severe Bugs trail about kexec-tools (bug #1028416) which leads to the bug dealt with here. I was specifically interested in the apparent affects on NVME unsafe_shutdown when using LVM, LUKS, and other virtual devices underneath the root file-system.

Although it implements functionality defined and supported by systemd I've tried to make the script generic enough for use with alternative init systems.

I've deliberately kept it simple and small - if there's demand for support that cannot be handled via /usr/lib/systemd/system-shutdown/ then the mkinitramfs conf/hook/scripts infrastructure could be added, but I tried to avoid that approach and the one implemented in bug #778849.

I've tested this on my workstation which uses a complex layout and it works for kexec, reboot, and poweroff.

sda -> LUKS_A -> PV ------------------|                 |-> LV-RAID1-0 -|
nvme0n1 -> nvme0n1p3 -> LUKS_B -> PV --> VG -> LV-RAID1---> LV-RAID1-1 ---> ext4 -> /

The only functionality I haven't included in this commit is enabling shutdown-initrd.service in the postinst script.

Merge request reports

Loading