diff --git a/zipl/Makefile b/zipl/Makefile index a2d101a3..aa7af702 100644 --- a/zipl/Makefile +++ b/zipl/Makefile @@ -9,6 +9,7 @@ install: all $(MAKE) -C src install $(MAKE) -C man install $(MAKE) -C dracut install + $(MAKE) -C initramfs-tools 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/initramfs-tools/Makefile b/zipl/initramfs-tools/Makefile new file mode 100644 index 00000000..aa65fce8 --- /dev/null +++ b/zipl/initramfs-tools/Makefile @@ -0,0 +1,24 @@ + +include ../../common.mak + +INITRAMFSTOOLSDIR := /usr/share/initramfs-tools +HOOKSDIR := $(INITRAMFSTOOLSDIR)/hooks +INITPREMOUNTDIR := $(INITRAMFSTOOLSDIR)/scripts/init-premount + +# HAVE_INITRAMFS +# +# This install time parameter determines whether the ngdump initramfs-tools +# support is installed (HAVE_INITRAMFS=1) or not (default). When installed, +# the module performs the following functions when mkinitramfs is run: +# +# - install the configuration file containing the name of a dump partition +# - install the dump script that is run at boot +# +ifeq ($(HAVE_INITRAMFS),1) +install: + $(INSTALL) -m 755 -d $(DESTDIR)$(HOOKSDIR) + $(INSTALL) -m 755 -d $(DESTDIR)$(INITPREMOUNTDIR) + $(INSTALL) -m 755 hooks/ngdump $(DESTDIR)$(HOOKSDIR)/ + $(INSTALL) -m 755 scripts/init-premount/ngdump \ + $(DESTDIR)$(INITPREMOUNTDIR) +endif diff --git a/zipl/initramfs-tools/hooks/ngdump b/zipl/initramfs-tools/hooks/ngdump new file mode 100755 index 00000000..c7c30ec5 --- /dev/null +++ b/zipl/initramfs-tools/hooks/ngdump @@ -0,0 +1,50 @@ +#!/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. +# + +OPTION=NGDUMP +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +# +# Install required kernel modules +# +manual_add_modules nvme ext4 +block_dev_mod_add "$NGDUMP_DEVICE" + +# +# Installs required tools +# +for tool in logsave findmnt sha256sum makedumpfile; do + path=$(command -v "$tool") + if [ ! -e "$path" ]; then + echo "$tool not found" >&2 + exit 1 + fi + copy_exec $path +done + +force_load nvme + +# +# Store the dump partition in a config file within initramfs. +# The config file will be included by the dump script. +# +echo "NGDUMP_DEVICE=${NGDUMP_DEVICE}" > "${DESTDIR}/conf/conf.d/ngdump" diff --git a/zipl/initramfs-tools/scripts/init-premount/ngdump b/zipl/initramfs-tools/scripts/init-premount/ngdump new file mode 100755 index 00000000..7ad3e22b --- /dev/null +++ b/zipl/initramfs-tools/scripts/init-premount/ngdump @@ -0,0 +1,108 @@ +#!/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. +# + +OPTION=NGDUMP +PREREQ="udev" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions +. /conf/conf.d/ngdump + +MNTDIR="/ngdump" +DUMP="dump.elf" +META="ngdump.meta" +VMCORE="/proc/vmcore" + +is_dump_part_ok() +{ + findmnt "$MNTDIR" >/dev/null 2>&1 && [ -e "$MNTDIR/$META" ] +} + +save_logs() +{ + is_dump_part_ok || return + [ -e "$VMCORE" ] && makedumpfile -f --dump-dmesg "$VMCORE" "$MNTDIR/crash.log" + dmesg >"$MNTDIR/boot.log" +} + +# +# The following steps make the firmware IPL the production system again. +# Otherwise, the firmware will boot the dumper again. +# +reipl() +{ + 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" + sleep 5 # To give console enough time to display last messages + halt +} + +quit() +{ + log_end_msg + sync + umount "$MNTDIR" + reipl +} + +bail_out() +{ + log_failure_msg "$1" + save_logs + quit +} + +save_meta() +{ + local hash=$(sha256sum "$MNTDIR/$DUMP" | cut -f1 -d ' ') + + cat >"$MNTDIR/$META" <