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