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>
This commit is contained in:
29
initramfs/initcpio/initcpio-common.sh
Normal file
29
initramfs/initcpio/initcpio-common.sh
Normal file
@ -0,0 +1,29 @@
|
||||
# Functions to deal with initcpio specifics, both for building
|
||||
# the initramfs for mkinitcpio users, but also with regards to
|
||||
# installing its specific hooks.
|
||||
#
|
||||
# IMPORTANT: it is assumed that kdump configuration was loaded
|
||||
# before running any of these functions!
|
||||
#
|
||||
create_initramfs_mkinitcpio() {
|
||||
rm -f "${MOUNT_FOLDER}/kdump-initrd-$1.img"
|
||||
|
||||
mkinitcpio -A kdump -g "${MOUNT_FOLDER}/kdump-initrd-$1.img" "$1" 1>/dev/null
|
||||
|
||||
if [ -s "${MOUNT_FOLDER}/kdump-initrd-$1.img" ]; then
|
||||
logger "kdump: created initcpio minimal initramfs"
|
||||
fi
|
||||
}
|
||||
|
||||
mkinitcpio_installation() {
|
||||
KDUMP_HOOKS_DIR="/usr/lib/kdump/initcpio/"
|
||||
INITCPIO_HOOKS="/usr/lib/initcpio/hooks"
|
||||
INITCPIO_INST="/usr/lib/initcpio/install"
|
||||
|
||||
if [ ! -e "${INITCPIO_HOOKS}"/kdump ] || [ ! -e "${INITCPIO_INST}"/kdump ]; then
|
||||
install -D -m0644 "${KDUMP_HOOKS_DIR}"/kdump.hook "${INITCPIO_HOOKS}"/kdump
|
||||
install -D -m0644 "${KDUMP_HOOKS_DIR}"/kdump.install "${INITCPIO_INST}"/kdump
|
||||
logger "kdump: initcpio hooks installed"
|
||||
fi
|
||||
}
|
||||
|
||||
9
initramfs/initcpio/kdump.install.header
Normal file
9
initramfs/initcpio/kdump.install.header
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: LGPL-2.1+
|
||||
#
|
||||
# Copyright (c) 2022 Valve.
|
||||
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
||||
#
|
||||
# Kdump-initrd module construction/inclusion script for
|
||||
# initcpio-based initramfs.
|
||||
#
|
||||
51
initramfs/initcpio/kdump.install.in
Normal file
51
initramfs/initcpio/kdump.install.in
Normal file
@ -0,0 +1,51 @@
|
||||
build() {
|
||||
load_kdump_config
|
||||
|
||||
# A valid makedumpfile is essential for the kdump initrd creation.
|
||||
if ! command -v makedumpfile 1>/dev/null; then
|
||||
logger "kdump: failed to create minimal initrd, makedumpfile is missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
add_binary /usr/bin/date
|
||||
add_binary /usr/bin/sync
|
||||
add_binary "$(command -v makedumpfile)"
|
||||
|
||||
# Copying kdump config/lib files is essential for a functional kdump.
|
||||
add_full_dir /usr/share/kdump.d/
|
||||
add_full_dir /usr/lib/kdump/
|
||||
|
||||
# We need to derive the proper place to save the dump from the
|
||||
# config files, in a way that makes possible to mount it in early boot.
|
||||
DEVNODE="$(findmnt -n -o SOURCE --target "${MOUNT_FOLDER}")"
|
||||
if [ -z "${DEVNODE}" ]; then
|
||||
logger "kdump: error on devnode discovery"
|
||||
exit 1
|
||||
fi
|
||||
echo "${DEVNODE}" > "${BUILDROOT}"/usr/lib/kdump/kdump.mnt
|
||||
|
||||
TGT="$(findmnt -n -o TARGET --target "${MOUNT_FOLDER}")"
|
||||
if [ -z "${TGT}" ]; then
|
||||
logger "kdump: error on base folder discovery"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_FLD="${MOUNT_FOLDER#*$TGT}"
|
||||
echo "${BASE_FLD}" > "${BUILDROOT}"/usr/lib/kdump/kdump.dir
|
||||
|
||||
# Finally, we shouldn't have DRM/GPU drivers and firmwares here,
|
||||
# but...just in case, let's remove all of that nevertheless.
|
||||
# Our list includes the most common FWs/drivers (amd, i915, nvidia).
|
||||
rm -rf "${BUILDROOT}"/usr/lib/firmware/{amdgpu,i915,nvidia,radeon}
|
||||
rm -rf "${BUILDROOT}"/usr/lib/modules/*/kernel/drivers/gpu/drm/{amd,i915,nouveau,radeon}
|
||||
|
||||
add_runscript
|
||||
}
|
||||
|
||||
help() {
|
||||
cat <<HELPEOF
|
||||
This hook is responsible for creating the minimal kdump initramfs.
|
||||
HELPEOF
|
||||
}
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
Reference in New Issue
Block a user