Make the service a oneshot service, which remains after exit. This
ensures, that the ExecStop is executed later on, if a shutdown occurs.
set -e
+# do some sanity checks first
+[ -e /run/initramfs/bin/sh ] && exit 0
+[ -e /run/initramfs/.need_shutdown ] || exit 0
+
KERNEL_VERSION="$(uname -r)"
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
[Unit]
Description=Restore /run/initramfs on shutdown
Documentation=man:dracut-shutdown.service(8)
-After=local-fs.target
+After=local-fs.target boot.mount boot.automount
Wants=local-fs.target
-Before=systemd-reboot.service shutdown.target
+Conflicts=shutdown.target umount.target
DefaultDependencies=no
-ConditionPathExists=/run/initramfs/.need_shutdown
ConditionPathExists=!/run/initramfs/bin/sh
[Service]
+RemainAfterExit=yes
+Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/lib/dracut/dracut-initramfs-restore