File kdump-rebuild-initrd-service.patch of Package kdump

From: Petr Tesarik <ptesarik@suse.com>
Date: Fri Sep 16 20:12:09 2016 +0200
Subject: Add a separate systemd service to rebuild kdumprd at boot
References: bsc#943214
Patch-mainline: v0.8.16
Git-commit: 5c1ffe9562ffeaa16d99be9c812ca56d767b3e24

The kdump service does two things:

  1. Refresh the initrd if needed.
  2. Load the kdump kernel and initrd.

While the latter should be done as soon as possible, the former should
be delayed until kdump dependencies are up and running.

Of course, kdump may still use an outdated initrd if the system crashes
between kdump.service and kdump-rebuild-initrd.service, but better than
nothing.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>

---
 init/CMakeLists.txt               |    1 +
 init/kdump-rebuild-initrd.service |   12 ++++++++++++
 init/kdump.service                |    1 +
 init/load.sh                      |   14 +++++++++++++-
 4 files changed, 27 insertions(+), 1 deletion(-)

--- a/init/CMakeLists.txt
+++ b/init/CMakeLists.txt
@@ -39,6 +39,7 @@ INSTALL(
 INSTALL(
     FILES
         ${CMAKE_CURRENT_SOURCE_DIR}/kdump.service
+        ${CMAKE_CURRENT_SOURCE_DIR}/kdump-rebuild-initrd.service
     DESTINATION
         /usr/lib/systemd/system
     PERMISSIONS
--- /dev/null
+++ b/init/kdump-rebuild-initrd.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Reload kdump kernel and updated initrd after the network is configured
+After=local-fs.target network.service YaST2-Second-Stage.service YaST2-Firstboot.service
+
+[Service]
+Type=oneshot
+ExecStart=/lib/kdump/load.sh --update
+ExecStop=/lib/kdump/unload.sh
+RemainAfterExit=true
+
+[Install]
+WantedBy=multi-user.target
--- a/init/kdump.service
+++ b/init/kdump.service
@@ -1,6 +1,7 @@
 [Unit]
 Description=Load kdump kernel on startup
 After=local-fs.target
+Wants=kdump-rebuild-initrd.service
 
 [Service]
 Type=oneshot
--- a/init/load.sh
+++ b/init/load.sh
@@ -299,7 +299,19 @@ if [ $((${KDUMP_VERBOSE:-0} & 16)) -gt 0
 fi
 
 find_kernel || exit 6
-rebuild_kdumprd || exit 1
+if [ "$1" = "--update" ] ; then
+    before=$(stat -c %Y $kdump_initrd 2> /dev/null)
+    rebuild_kdumprd || exit 1
+    after=$(stat -c %Y $kdump_initrd)
+
+    # If the initial ram disk was not updated,
+    # do not execute kexec again. This script
+    # is called from kdump.service and
+    # kdump-rebuild-initrd.service.
+    if [ "$before" = "$after" ] ; then
+        exit 0
+    fi
+fi
 
 if [ "$KDUMP_FADUMP" = "yes" ] ; then
     load_kdump_fadump
openSUSE Build Service is sponsored by