]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
systemd: Add plymouth-switch-root-initramfs.service to switch back to initramfs on...
authorRay Strode <rstrode@redhat.com>
Fri, 17 Jul 2020 20:06:44 +0000 (16:06 -0400)
committerHans de Goede <hdegoede@redhat.com>
Tue, 6 Apr 2021 11:45:41 +0000 (13:45 +0200)
Add a plymouth-switch-root-initramfs.service, which will call
"plymouth update-root-fs --new-root-dir=/run/initramfs" to switch back
to the initramfs (when applicable).

Systemd will run this service before plymouthd receives the SIGTERM on
shutdown, so this will cause the plymouthd-fd-escrow helper to run
from the initramfs.

This avoids the plymouthd-fd-escrow helper keeping the rootfs busy.

Changes by Hans de Goede:
- Fix a couple of typos
- Add Conflicts=dracut-shutdown.service to plymouth-switch-root-initramfs.service
  dracut-shutdown.service restores the initramfs when it is _stopped_
  use Conflicts to make sure its ExecStop has run before we do
- Add a check for switching back to the initramfs to on_newroot () and dump
  the debug-buffer before the switch (while we still have access to /var/log).
- Also add plymouth-switch-root-initramfs.service to kexec.target.wants.
  kexec.target.wants uses --mode=shutdown, so the plymouthd-fd-escrow helper
  will run, so we need to switch to the initramfs.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
configure.ac
scripts/plymouth-populate-initrd.in
src/main.c
systemd-units/Makefile.am
systemd-units/plymouth-switch-root-initramfs.service.in [new file with mode: 0644]

index a7b92994588b2f0d346930629328528e9c76995c..9c9a3e130ab4d54c3f032a2a249619b4bb7fb537 100644 (file)
@@ -342,6 +342,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in
            systemd-units/plymouth-reboot.service
            systemd-units/plymouth-start.service
            systemd-units/plymouth-switch-root.service
+           systemd-units/plymouth-switch-root-initramfs.service
            systemd-units/systemd-ask-password-plymouth.path
            systemd-units/systemd-ask-password-plymouth.service
            systemd-units/Makefile
index 616ecc4eedb9c22d26d25548e590ba8553218812..0ff1f12455c8fa2d9292e9f1c1086492482f43cc 100755 (executable)
@@ -22,6 +22,7 @@
 [ -z "$PLYMOUTH_POLICYDIR" ] && PLYMOUTH_POLICYDIR="@PLYMOUTH_POLICY_DIR@"
 [ -z "$PLYMOUTH_DAEMON_PATH" ] && PLYMOUTH_DAEMON_PATH="@PLYMOUTH_DAEMON_DIR@/plymouthd"
 [ -z "$PLYMOUTH_CLIENT_PATH" ] && PLYMOUTH_CLIENT_PATH="@PLYMOUTH_CLIENT_DIR@/plymouth"
+[ -z "$PLYMOUTH_DRM_ESCROW_PATH" ] && PLYMOUTH_DRM_ESCROW_PATH="@PLYMOUTH_LIBEXECDIR@/plymouth/plymouthd-fd-escrow"
 [ -z "$SYSTEMD_UNIT_DIR" ] && SYSTEMD_UNIT_DIR="@SYSTEMD_UNIT_DIR@"
 
 # Generic substring function.  If $2 is in $1, return 0.
@@ -416,6 +417,7 @@ ddebug "Running with PLYMOUTH_LDD_PATH=$PLYMOUTH_LDD_PATH"
 mkdir -p ${INITRDDIR}${PLYMOUTH_DATADIR}/plymouth/themes
 inst ${PLYMOUTH_DAEMON_PATH} $INITRDDIR
 inst ${PLYMOUTH_CLIENT_PATH} $INITRDDIR
+inst ${PLYMOUTH_DRM_ESCROW_PATH} $INITRDDIR
 inst ${PLYMOUTH_DATADIR}/plymouth/themes/text/text.plymouth $INITRDDIR
 inst ${PLYMOUTH_PLUGIN_PATH}/text.so $INITRDDIR
 inst ${PLYMOUTH_DATADIR}/plymouth/themes/details/details.plymouth $INITRDDIR
index 23319a1c8357aa1e84f990a7881a8162bce0ea7d..aa6f90b8040e57b0a63a13201f3bfa131423758f 100644 (file)
@@ -158,6 +158,7 @@ static void on_quit (state_t       *state,
 static bool sh_is_init (state_t *state);
 static void cancel_pending_delayed_show (state_t *state);
 static void prepare_logging (state_t *state);
+static void dump_debug_buffer_to_file (void);
 
 static void
 on_session_output (state_t    *state,
@@ -653,6 +654,12 @@ on_newroot (state_t    *state,
         }
 
         ply_trace ("new root mounted at \"%s\", switching to it", root_dir);
+
+        if (!strcmp (root_dir, "/run/initramfs") && debug_buffer != NULL) {
+                ply_trace ("switching back to initramfs, dumping debug-buffer now");
+                dump_debug_buffer_to_file ();
+        }
+
         chdir (root_dir);
         chroot (".");
         chdir ("/");
index b1d843b6a0864794eb4e6058f76765eb3c7a8783..cd2d7be5478adebb415b545696f7fa36df0da3f9 100644 (file)
@@ -1,5 +1,6 @@
 systemd_unit_templates =                                                     \
         plymouth-switch-root.service.in                                      \
+        plymouth-switch-root-initramfs.service.in                            \
         plymouth-start.service.in                                            \
         plymouth-read-write.service.in                                       \
         plymouth-quit.service.in                                             \
@@ -37,17 +38,25 @@ install-data-hook:
                $(LN_S) ../plymouth-quit.service &&                          \
                $(LN_S) ../plymouth-quit-wait.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/reboot.target.wants &&             \
-               rm -f plymouth-reboot.service &&                             \
-               $(LN_S) ../plymouth-reboot.service)
+               rm -f plymouth-reboot.service                                \
+                     plymouth-switch-root-initramfs.service &&              \
+               $(LN_S) ../plymouth-reboot.service &&                        \
+               $(LN_S) ../plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/kexec.target.wants &&              \
-               rm -f plymouth-kexec.service &&                              \
-               $(LN_S) ../plymouth-kexec.service)
+               rm -f plymouth-kexec.service                                 \
+                     plymouth-switch-root-initramfs.service &&              \
+               $(LN_S) ../plymouth-kexec.service &&                         \
+               $(LN_S) ../plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/poweroff.target.wants &&           \
-               rm -f plymouth-poweroff.service &&                           \
-               $(LN_S) ../plymouth-poweroff.service)
+               rm -f plymouth-poweroff.service                              \
+                     plymouth-switch-root-initramfs.service &&              \
+               $(LN_S) ../plymouth-poweroff.service &&                      \
+               $(LN_S) ../plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/halt.target.wants &&               \
-               rm -f plymouth-halt.service &&                               \
-               $(LN_S) ../plymouth-halt.service)
+               rm -f plymouth-halt.service                                  \
+                     plymouth-switch-root-initramfs.service &&              \
+               $(LN_S) ../plymouth-halt.service &&                          \
+               $(LN_S) ../plymouth-switch-root-initramfs.service)
 
 uninstall-hook:
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/initrd-switch-root.target.wants && \
@@ -57,13 +66,17 @@ uninstall-hook:
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/multi-user.target.wants &&         \
                rm -f plymouth-quit.service plymouth-quit-wait.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/reboot.target.wants &&             \
-               rm -f plymouth-reboot.service)
+               rm -f plymouth-reboot.service                                \
+                     plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/kexec.target.wants &&              \
-               rm -f plymouth-kexec.service)
+               rm -f plymouth-kexec.service                                 \
+                     plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/poweroff.target.wants &&           \
-               rm -f plymouth-poweroff.service)
+               rm -f plymouth-poweroff.service                              \
+                     plymouth-switch-root-initramfs.service)
        (cd $(DESTDIR)$(SYSTEMD_UNIT_DIR)/halt.target.wants &&               \
-               rm -f plymouth-halt.service)
+               rm -f plymouth-halt.service                                  \
+                     plymouth-switch-root-initramfs.service)
        rmdir --ignore-fail-on-non-empty                                     \
                $(DESTDIR)$(SYSTEMD_UNIT_DIR)/sysinit.target.wants           \
                $(DESTDIR)$(SYSTEMD_UNIT_DIR)/multi-user.target.wants        \
diff --git a/systemd-units/plymouth-switch-root-initramfs.service.in b/systemd-units/plymouth-switch-root-initramfs.service.in
new file mode 100644 (file)
index 0000000..0610803
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=Tell Plymouth To Jump To initramfs
+DefaultDependencies=no
+# dracut-shutdown.service restores the initramfs when it is _stopped_
+# use Conflicts to make sure its ExecStop has run before we do
+Conflicts=dracut-shutdown.service
+After=plymouth-halt.service plymouth-reboot.service plymouth-poweroff.service plymouth-kexec.service dracut-shutdown.service
+ConditionPathExists=/run/initramfs/bin/sh
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=-@PLYMOUTH_CLIENT_DIR@/plymouth update-root-fs --new-root-dir=/run/initramfs
+Type=oneshot
+RemainAfterExit=yes