Skip to content

Commit 7ab1d00

Browse files
rmetrichjohannbg
authored andcommitted
fix(dracut-shutdown): add cleanup handler on failure
It may happen that dracut-shutdown.service fails, for example on timeout due to very low bandwidth. In such case, for hardening purposes, a new dracut-shutdown-onfailure.service unit doing dracut-shutdown.service cleanup needs to execute to make sure switching root to an incomplete initramfs won't occur later. See also RHBZ #1924587 (https://bugzilla.redhat.com/show_bug.cgi?id=1924587).
1 parent d40c49a commit 7ab1d00

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ ifneq ($(enable_documentation),no)
178178
endif
179179
if [ -n "$(systemdsystemunitdir)" ]; then \
180180
mkdir -p $(DESTDIR)$(systemdsystemunitdir); \
181+
ln -srf $(DESTDIR)$(pkglibdir)/modules.d/98dracut-systemd/dracut-shutdown-onfailure.service $(DESTDIR)$(systemdsystemunitdir)/dracut-shutdown-onfailure.service; \
181182
ln -srf $(DESTDIR)$(pkglibdir)/modules.d/98dracut-systemd/dracut-shutdown.service $(DESTDIR)$(systemdsystemunitdir)/dracut-shutdown.service; \
182183
mkdir -p $(DESTDIR)$(systemdsystemunitdir)/sysinit.target.wants; \
183184
ln -s ../dracut-shutdown.service \
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is part of dracut.
2+
#
3+
# See dracut.bootup(7) for details
4+
5+
[Unit]
6+
Description=Service executing upon dracut-shutdown failure to perform cleanup
7+
Documentation=man:dracut-shutdown.service(8)
8+
DefaultDependencies=no
9+
10+
[Service]
11+
Type=oneshot
12+
ExecStart=-/bin/rm /run/initramfs/shutdown
13+
StandardError=null

modules.d/98dracut-systemd/dracut-shutdown.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Wants=local-fs.target
1010
Conflicts=shutdown.target umount.target
1111
DefaultDependencies=no
1212
ConditionPathExists=!/run/initramfs/bin/sh
13+
OnFailure=dracut-shutdown-onfailure.service
1314

1415
[Service]
1516
RemainAfterExit=yes

modules.d/98dracut-systemd/dracut-shutdown.service.8.asc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ by injecting "rd.break=pre-shutdown rd.shell" or "rd.break=shutdown rd.shell".
4040
# touch /run/initramfs/.need_shutdown
4141
----
4242

43+
In case the unpack of the initramfs fails, dracut-shutdown-onfailure.service
44+
executes to make sure switch root doesn't happen, since it would result in
45+
switching to an incomplete initramfs.
4346

4447
AUTHORS
4548
-------

pkgbuild/dracut.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ echo 'dracut_rescue_image="yes"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/
416416
%dir %{_sharedstatedir}/initramfs
417417
%if %{defined _unitdir}
418418
%{_unitdir}/dracut-shutdown.service
419+
%{_unitdir}/dracut-shutdown-onfailure.service
419420
%{_unitdir}/sysinit.target.wants/dracut-shutdown.service
420421
%{_unitdir}/dracut-cmdline.service
421422
%{_unitdir}/dracut-initqueue.service

0 commit comments

Comments
 (0)