From c1d08e1380de09f00356c1d139db1846d8fe74c8 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Thu, 12 Aug 2021 13:24:25 +0200 Subject: [PATCH] zipl: Add initramfs-tools module for NGDump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NGDump initramfs-tools 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 initramfs-tools if NGDump stand-alone dump is installed on a NVMe partition. The NGDump initramfs-tools 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 intramfs-tools module installs a configuration file and a dump script into dumper initramfs. This dump script starts at boot shortly after the initialization of the dump target device. It reads the aforementioned configuration file that contains the name of a dump partition to store a dump on. The dump script reads the configuration file, mounts then the dump target device, creates a copy of /proc/vmcore with the makedumpfile tool on it, and then shuts down the system. Ubuntu and Debian are the main Linux distributions targeted by this initramfs-tools module. Signed-off-by: Alexander Egorenkov Acked-by: Alexander Gordeev Tested-by: Alexander Gordeev Signed-off-by: Jan Höppner --- zipl/Makefile | 1 + zipl/initramfs-tools/Makefile | 24 ++++ zipl/initramfs-tools/hooks/ngdump | 50 ++++++++ .../scripts/init-premount/ngdump | 108 ++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 zipl/initramfs-tools/Makefile create mode 100755 zipl/initramfs-tools/hooks/ngdump create mode 100755 zipl/initramfs-tools/scripts/init-premount/ngdump 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" <