zipl: Add dracut module for NGDump

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 <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Alexander Egorenkov
2021-08-03 18:53:34 +02:00
committed by Jan Höppner
parent 4939531fe5
commit 85c9a49e63
6 changed files with 196 additions and 0 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

72
zipl/dracut/99ngdump/ngdump.sh Executable file
View File

@@ -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" <<EOF
version=1
file=$DUMP
sha256sum=$hash
EOF
}
info "NGDump started"
is_dump_part_ok || { bail_out "Dump partition not found"; }
#
# We must save the dump as ELF format, because
# kdump compressed format is not supported by zgetdump yet
#
makedumpfile -f -E --message-level 7 -d 31 "$VMCORE" "$MNTDIR/$DUMP"
[ $? -eq 0 ] || { bail_out "makedumpfile failed"; }
#
# Create a file containing meta information for zgetdump
#
save_meta
cleanup
exit 0

28
zipl/dracut/Makefile Normal file
View File

@@ -0,0 +1,28 @@
include ../../common.mak
MODULESDIR := /usr/lib/dracut/modules.d/
NGDUMPDIR := 99ngdump
# HAVE_DRACUT
#
# This install time parameter determines whether the ngdump dracut module is
# installed (HAVE_DRACUT=1) or not (default). When installed, the module
# performs the following functions when dracut is run:
#
# - install the systemd service that initiates the dump at boot
# - install the dump script that is run by the new systemd service at boot
#
ifeq ($(HAVE_DRACUT),1)
install:
$(INSTALL) -m 755 -d $(DESTDIR)$(MODULESDIR)
$(INSTALL) -m 755 -d $(DESTDIR)$(MODULESDIR)/$(NGDUMPDIR)
$(INSTALL) -m 755 $(NGDUMPDIR)/module-setup.sh \
$(DESTDIR)$(MODULESDIR)/$(NGDUMPDIR)/
$(INSTALL) -m 644 $(NGDUMPDIR)/ngdump.service \
$(DESTDIR)$(MODULESDIR)/$(NGDUMPDIR)/
$(INSTALL) -m 755 $(NGDUMPDIR)/ngdump.sh \
$(DESTDIR)$(MODULESDIR)/$(NGDUMPDIR)/
$(INSTALL) -m 755 $(NGDUMPDIR)/ngdump-reipl.sh \
$(DESTDIR)$(MODULESDIR)/$(NGDUMPDIR)/
endif