File kdump-systemd-support.patch of Package kdump.624

From: Petr Tesarik <ptesarik@suse.cz>
Date: Thu Sep 18 15:40:37 2014 +0200
Subject: Dracut-systemd support
References: bnc#883883
Patch-mainline: v0.8.16
Git-commit: 9940475e501273ddac4a13fa2f4284b4121415de
    
Adjust the dracut module to work with the systemd module.

A new service is added to the initrd. I could not use a pre-pivot
hook, because dracut-pre-pivot.service does not send the output
to the terminal, so dump progress was not visible.

It is also necessary to avoid mounting the root filesystem. All
filesystems needed by kdump are mounted under /kdump and set up
with the --mount dracut option.

The system root mount can be generated in two ways:

a. by initrd-fstab-generator (if "root=" is passed on the kernel
   command line)

b. by dracut-rootfs-generator (if the root option is stored in
   /etc/cmdline.d/*)

The root= parameter is already removed from the command line, but
it is always saved to /etc/cmdline.d/95root-dev.conf if dracut is
called with --hostonly-cmdline. This is the default in SLES (cf.
/etc/dracut.conf.d/01-dist.conf) and it is required to get correct
configuration for many setups.

So, the only way to avoid mounting /sysroot is to remove the
appropriate systemd generator from the initrd.

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

diff --git a/init/CMakeLists.txt b/init/CMakeLists.txt
index 662197c..9cc8b71 100644
--- a/init/CMakeLists.txt
+++ b/init/CMakeLists.txt
@@ -79,4 +79,15 @@ INSTALL(
         WORLD_READ WORLD_EXECUTE
 )
 
+INSTALL(
+    FILES
+        ${CMAKE_CURRENT_SOURCE_DIR}/kdump-save.service
+    DESTINATION
+        /usr/lib/dracut/modules.d/99kdump
+    PERMISSIONS
+        OWNER_READ OWNER_WRITE
+        GROUP_READ
+        WORLD_READ
+)
+
 # vim: set sw=4 ts=4 et:
diff --git a/init/kdump-save.service b/init/kdump-save.service
new file mode 100644
index 0000000..ac527f4
--- /dev/null
+++ b/init/kdump-save.service
@@ -0,0 +1,31 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+# See systemd.special(7) for details
+
+[Unit]
+Description=save kernel crash dump
+Documentation=man:kdump(7)
+Wants=dracut-mount.service dracut-pre-pivot.service
+After=dracut-mount.service dracut-pre-pivot.service
+After=initrd.target
+Before=initrd-cleanup.service
+ConditionPathExists=/etc/initrd-release
+ConditionPathExists=/proc/vmcore
+
+[Service]
+Type=oneshot
+ExecStart=/lib/kdump/save_dump.sh
+StandardInput=tty
+StandardOutput=tty
+StandardError=tty
+KillMode=process
+RemainAfterExit=yes
+
+# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash
+# terminates cleanly.
+KillSignal=SIGHUP
diff --git a/init/mkdumprd b/init/mkdumprd
index 334786f..bb818d2 100755
--- a/init/mkdumprd
+++ b/init/mkdumprd
@@ -122,7 +122,7 @@ function run_dracut()
 {
     local modules="kdump"
 
-    DRACUT_ARGS="--force --hostonly --omit 'systemd plymouth resume usrmount'"
+    DRACUT_ARGS="--force --hostonly --omit 'plymouth resume usrmount'"
     DRACUT_ARGS="$DRACUT_ARGS --compress='xz -0 --check=crc32'"
 
     # add mount points
diff --git a/init/module-setup.sh b/init/module-setup.sh
index 06f9775..690de38 100644
--- a/init/module-setup.sh
+++ b/init/module-setup.sh
@@ -18,8 +18,18 @@ install() {
 
     kdump_setup_files "$initdir" "${!host_fs_types[*]}"
 
-    inst_hook mount 30 "$moddir/mount-kdump.sh"
-    inst_hook pre-pivot 90 /lib/kdump/save_dump.sh
+    if dracut_module_included "systemd" ; then
+	rm -f "${initdir}/$systemdutildir"/system-generators/dracut-rootfs-generator
+	inst_simple /lib/kdump/save_dump.sh
+	inst_simple "$moddir/kdump-save.service" \
+	    "$systemdsystemunitdir"/kdump-save.service
+	ln_r "$systemdsystemunitdir"/kdump-save.service \
+	    "$systemdsystemunitdir"/initrd.target.wants/kdump-save.service
+    else
+	inst_hook mount 30 "$moddir/mount-kdump.sh"
+	inst_hook pre-pivot 90 /lib/kdump/save_dump.sh
+    fi
+
     inst_multiple makedumpfile makedumpfile-R.pl kdumptool \
 	$KDUMP_REQUIRED_PROGRAMS
     inst_simple /etc/resolv.conf