From 85c9a49e6355c00671d121da8a975de2f64ce6ca Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Tue, 3 Aug 2021 18:53:34 +0200 Subject: [PATCH] zipl: Add dracut module for NGDump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NGDump dracut module is required to build an initramfs image to be used with NGDump stand-alone dump. NGDump stand-alone dump does not use a pre-built initramfs image in contrast to SCSI stand-alone dump. Instead, an initramfs image is built with dracut if NGDump stand-alone dump is installed on a NVMe partition. The NGDump dracut module ensures that all necessary tools are present within the built initramfs and a dump of /proc/vmcore is initiated to the chosen NVMe partition when the installed dumper is IPLed. The NGDump dracut module installs a new systemd service and a dump script into dumper initramfs. The systemd init process starts the NGDump service at boot shortly after the initialization of the dump target device. The NGDump systemd service, in its turn, starts the dump script provided by the new dracut module. The dump script mounts then the dump target device, creates a copy of /proc/vmcore with the makedumpfile tool on it, and then shuts down the system. The NGDump dracut module can be used on any Linux distribution which supports dracut. But the primary targets are: - Fedora - RHEL - SLES Signed-off-by: Alexander Egorenkov Acked-by: Alexander Gordeev Tested-by: Alexander Gordeev Signed-off-by: Jan Höppner --- zipl/Makefile | 1 + zipl/dracut/99ngdump/module-setup.sh | 40 ++++++++++++++++ zipl/dracut/99ngdump/ngdump-reipl.sh | 20 ++++++++ zipl/dracut/99ngdump/ngdump.service | 35 ++++++++++++++ zipl/dracut/99ngdump/ngdump.sh | 72 ++++++++++++++++++++++++++++ zipl/dracut/Makefile | 28 +++++++++++ 6 files changed, 196 insertions(+) create mode 100755 zipl/dracut/99ngdump/module-setup.sh create mode 100755 zipl/dracut/99ngdump/ngdump-reipl.sh create mode 100644 zipl/dracut/99ngdump/ngdump.service create mode 100755 zipl/dracut/99ngdump/ngdump.sh create mode 100644 zipl/dracut/Makefile diff --git a/zipl/Makefile b/zipl/Makefile index 0a087e2f..a2d101a3 100644 --- a/zipl/Makefile +++ b/zipl/Makefile @@ -8,6 +8,7 @@ all: install: all $(MAKE) -C src install $(MAKE) -C man install + $(MAKE) -C dracut install $(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 doc/zipl.conf.minimal $(DESTDIR)$(TOOLS_LIBDIR)/zipl.conf ifeq ($(wildcard $(DESTDIR)$(SYSCONFDIR)/ziplenv),) $(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 doc/ziplenv.minimal $(DESTDIR)$(SYSCONFDIR)/ziplenv diff --git a/zipl/dracut/99ngdump/module-setup.sh b/zipl/dracut/99ngdump/module-setup.sh new file mode 100755 index 00000000..f406d8cd --- /dev/null +++ b/zipl/dracut/99ngdump/module-setup.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Copyright IBM Corp. 2021 +# +# s390-tools is free software; you can redistribute it and/or modify +# it under the terms of the MIT license. See LICENSE for details. +# + +check() { + require_binaries sync poweroff || return 1 + require_binaries cut sha256sum findmnt makedumpfile || return 1 + # Only include the dracut module, if another module requires it + # or if explicitly specified in the config file or on the argument list. + return 255 +} + +depends() { + echo "base shutdown systemd" +} + +installkernel() { + instmods nvme ext4 +} + +install() { + mkdir -p "${initdir}/ngdump" + + inst sync + inst poweroff + inst cut + inst sha256sum + inst findmnt + inst makedumpfile + + inst "$moddir/ngdump.sh" "/usr/bin/ngdump.sh" + inst "$moddir/ngdump-reipl.sh" "/usr/bin/ngdump-reipl.sh" + inst "$moddir/ngdump.service" "$systemdsystemunitdir/ngdump.service" + + systemctl -q --root "$initdir" add-wants initrd.target ngdump.service +} diff --git a/zipl/dracut/99ngdump/ngdump-reipl.sh b/zipl/dracut/99ngdump/ngdump-reipl.sh new file mode 100755 index 00000000..ec769b82 --- /dev/null +++ b/zipl/dracut/99ngdump/ngdump-reipl.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# Copyright IBM Corp. 2021 +# +# s390-tools is free software; you can redistribute it and/or modify +# it under the terms of the MIT license. See LICENSE for details. +# + +# +# The following steps make the firmware IPL the production system again. +# Otherwise, the firmware will boot the dumper again. +# + +dir=$(findmnt -n -o TARGET debugfs) +if [ -z "$dir" ]; then + dir=/sys/kernel/debug + mount -t debugfs none "$dir" +fi +echo 1 > "$dir/zcore/reipl" +poweroff diff --git a/zipl/dracut/99ngdump/ngdump.service b/zipl/dracut/99ngdump/ngdump.service new file mode 100644 index 00000000..ae4b0057 --- /dev/null +++ b/zipl/dracut/99ngdump/ngdump.service @@ -0,0 +1,35 @@ +# 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. +# +# man bootup(7) +# man systemd.service(5) +# man systemd.special(7) +# + +[Unit] +Description=NGDump +After=initrd.target initrd-parse-etc.service +After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service +Before=initrd-cleanup.service +ConditionPathExists=/etc/initrd-release +OnFailure=emergency.target +OnFailureJobMode=isolate + +[Service] +Environment=DRACUT_SYSTEMD=1 +Type=oneshot +ExecStart=/usr/bin/ngdump.sh +ExecStopPost=/usr/bin/ngdump-reipl.sh +StandardInput=null +StandardOutput=journal+console +StandardError=journal+console +KillMode=process +RemainAfterExit=yes + +# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash +# terminates cleanly. +KillSignal=SIGHUP diff --git a/zipl/dracut/99ngdump/ngdump.sh b/zipl/dracut/99ngdump/ngdump.sh new file mode 100755 index 00000000..bc6b48f0 --- /dev/null +++ b/zipl/dracut/99ngdump/ngdump.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Copyright IBM Corp. 2021 +# +# s390-tools is free software; you can redistribute it and/or modify +# it under the terms of the MIT license. See LICENSE for details. +# + +. /lib/dracut-lib.sh + +MNTDIR="/ngdump" +DUMP="dump.elf" +META="ngdump.meta" +VMCORE="/proc/vmcore" + +is_dump_part_ok() +{ + ismounted "$MNTDIR" && [ -e "$MNTDIR/$META" ] +} + +save_logs() +{ + is_dump_part_ok || return + [ -e "$VMCORE" ] && makedumpfile -f --dump-dmesg "$VMCORE" "$MNTDIR/crash.log" + journalctl -b >"$MNTDIR/boot.log" +} + +cleanup() +{ + sync + umount "$MNTDIR" +} + +bail_out() +{ + warn "$1" + save_logs + cleanup + exit 1 +} + +save_meta() +{ + local hash=$(sha256sum "$MNTDIR/$DUMP" | cut -f1 -d ' ') + + cat >"$MNTDIR/$META" <