File kdump-pre-generate-mount-units.patch of Package kdump.17334

From: Petr Tesarik <ptesarik@suse.com>
Subject: Pre-generate kdump mount units
References: bsc#942895
Upstream: v0.8.17
Git-commit: a7e47cdf9cb7db385bc30fce59abce1dc2b5cc11

SUSE version of dracut intentionally modifies the initrd to run
systemd-fstab-generator only after the root filesystem is mounted.
This breaks kdump-save.service, because mount units for /kdump/*
do not yet exist when kdump needs them.

Solve this by pre-generating the required mount units in the primary
system, so kdump no longer depends on running the fstab generator in
initrd context.

Note that I had to write a temporary /etc/fstab, because dracut
creates this file only after all modules have been processed.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 init/module-setup.sh |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

--- a/init/module-setup.sh
+++ b/init/module-setup.sh
@@ -108,6 +108,39 @@ kdump_cmdline_ip() {
     esac
 }
 
+kdump_gen_mount_units() {
+    local line
+    local fstab="$initdir/etc/fstab"
+
+    [ -e "$fstab" ] && mv "$fstab" "$fstab.kdumpsave"
+    for line in "${fstab_lines[@]}"
+    do
+	line=($line)
+	[ "${line[1]#/kdump}" = "${line[1]}" ] && continue
+	[ -z "${line[3]}" ] && line[3]="defaults"
+	[ -z "${line[4]}" ] && line[4]="0"
+	[ -z "${line[5]}" ] && line[5]="2"
+	echo "${line[@]}" >> "$fstab"
+    done
+
+    echo "root=kdump" > "$initdir/proc/cmdline"
+    inst_binary -l \
+	"$systemdutildir/system-generators/systemd-fstab-generator" \
+	"/tmp/systemd-fstab-generator"
+    chroot "$initdir" "/tmp/systemd-fstab-generator" \
+	"$systemdsystemunitdir" \
+	"$systemdsystemunitdir" \
+	"$systemdsystemunitdir"
+    rm -f "$initdir/tmp/systemd-fstab-generator"
+    rm -f "$initdir/proc/cmdline"
+
+    if [ -e "$fstab.kdumpsave" ]; then
+	mv "$fstab.kdumpsave" "$fstab"
+    else
+	rm "$fstab"
+    fi
+}
+
 cmdline() {
     kdump_cmdline_ip
 }
@@ -155,6 +188,8 @@ install() {
 	    "$initdir/$systemdsystemunitdir"/kdump-save.service
 	ln_r "$systemdsystemunitdir"/kdump-save.service \
 	    "$systemdsystemunitdir"/initrd.target.wants/kdump-save.service
+
+	kdump_gen_mount_units
     else
 	[ "$KDUMP_FADUMP" != yes ] && \
 	    inst_hook mount 30 "$moddir/mount-kdump.sh"
openSUSE Build Service is sponsored by