Files
kdumpst/initramfs/kdump-collect.sh
Guilherme G. Piccoli b834754cf9 initramfs: Switch to the alpm-hooks approach, supporting both initcpio/dracut
This is one of the major changes/refactors so far, touches a lot of
files, and more important, it completely changes some premises.
With this patch, we now support fully both dracut-based and initcpio
initramfs systems.

For that to happen, we needed to decouple the initramfs creation from
scripts, by using alpm-hooks. These hooks allow scripts to be run on
events like kernel package installation or in the installation of the very
package responsible to create the initramfs image. We still have the
"kdump-load create-initrd" command though.

One of the biggest modifications here was in the Makefile, that now
composes multiple files by changing keywords (like INITRD) to the
respective initramfs system (dracut or mkinitcpio). Notice that this
brought some extra complexity to the package.

The logic used for supporting both initramfs systems was basically
de-duplicate all possible code (having dup code in common files),
using Makefile tricks to merge such files and have the unique
bits in dracut/initcpio specific files. We currently support dracut
and both mkinitcpio and mkinitcpio-git packages.

Caveats: currently the initramfs specific package removal is not handled
here. So, if the user has dracut and installs kdump, we install the
dracut hooks. In case this user decides to remove dracut and installs
mkinitcpio, we install the mkinitcpio hooks and all should work, but
the previous dracut hooks installed are not unistalled by us; likely
the dracut package removal would drop the files itself.

This was a deliberate move to avoid even more alpm-hooks, should be
a rare case and as said, the package removal should clear the files
itself, without requiring our interaction. Also, by using the
alpm-hooks, we see "errors" (warnings really) about the other
initramfs package not being present - not sure if it's possible to
disable this behavior.

Finally, while at it:

* Added a new approach to dracut initramfs creation to pick the most
common block drivers - since it's hostonly, it doesn't add the ones
that aren't loaded, hence image is not bloated by that.

* Chenged the "command -v makedumpfile" validation to something
more elegant - thanks for the suggestion Clayton (@craftyguy).

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2023-03-31 15:34:42 -03:00

62 lines
1.9 KiB
Bash

#!/bin/sh
#
# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright (c) 2022 Valve.
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
#
# Script for effectively collecting the core dump/dmesg from
# within a minimal initrd - part of the kdump/pstore tooling.
# The most fail-prone operations are guarded with conditionals to
# bail in case we indeed fail - worst thing here would be to have
# a bad condition and get stuck in this minimal initrd with no
# output for the user. Notice that the script is used in both
# dracut and initcpio cases.
#
#ENTRY POINT
# Bail out in case we don't have a vmcore, i.e. either we're not kdumping
# or something is pretty wrong and we wouldn't be able to progress.
VMCORE="/proc/vmcore"
if [ ! -f "$VMCORE" ]; then
reboot -f
fi
# We have a more controlled situation with regards the config
# files here, since we manually added them in the initrd and
# the validation also happened there, during such addition,
# hence not requiring checks here.
for cfg in "/usr/share/kdump.d"/*; do
. "$cfg"
done
KDUMP_TIMESTAMP=$(date -u +"%Y%m%d%H%M")
MOUNT_POINT="$(cat /usr/lib/kdump/kdump.mnt)"
BASE_FOLDER="$(cat /usr/lib/kdump/kdump.dir)"
KDUMP_FOLDER="/kdump_path/${BASE_FOLDER}/crash/${KDUMP_TIMESTAMP}"
mkdir -p "/kdump_path"
if ! mount "${MOUNT_POINT}" /kdump_path; then
reboot -f
fi
mkdir -p "${KDUMP_FOLDER}"
# we want to split on spaces, it's a set of parameters!
# shellcheck disable=SC2086
/usr/bin/makedumpfile ${MAKEDUMPFILE_DMESG_CMD} $VMCORE "${KDUMP_FOLDER}/dmesg.txt"
sync "${KDUMP_FOLDER}/dmesg.txt"
if [ "${FULL_COREDUMP}" -ne 0 ]; then
# shellcheck disable=SC2086
/usr/bin/makedumpfile ${MAKEDUMPFILE_COREDUMP_CMD} $VMCORE "${KDUMP_FOLDER}/vmcore.compressed"
sync "${KDUMP_FOLDER}/vmcore.compressed"
fi
umount "${MOUNT_POINT}"
sync
reboot -f
#END