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:
Guilherme G. Piccoli
2022-12-21 13:17:29 -03:00
parent e24d6d9b46
commit b834754cf9
13 changed files with 348 additions and 76 deletions

View File

@ -41,17 +41,15 @@ grub_update() {
# This function is responsible for creating the kdump initrd, either
# via command-line call or in case initrd doesn't exist during kdump load.
# It accounts for both mkinitcpio and dracut users.
create_initrd() {
rm -f "${MOUNT_FOLDER}/kdump-initrd-$(uname -r).img"
echo "Creating the kdump initramfs for kernel \"$(uname -r)\" ..."
DRACUT_NO_XATTR=1 dracut --no-early-microcode --host-only -q -m\
"bash systemd systemd-initrd systemd-sysusers modsign dbus-daemon kdump dbus udev-rules dracut-systemd base fs-lib shutdown"\
--kver "$(uname -r)" "${MOUNT_FOLDER}/kdump-initrd-$(uname -r).img"
/usr/lib/kdump/kdump-mkinitcpio-hook.sh "$(uname -r)"
/usr/lib/kdump/kdump-dracut-hook.sh "$(uname -r)"
}
# This routine performs a clean-up by deleting the old/useless remaining
# kdump initrd files.
# kdump initrd files. Even with alpm-hooks, users might install kernels
# manually so it makes sense to have this fallback to avoid storage waste.
cleanup_unused_initrd() {
INSTALLED_KERNELS="${MOUNT_FOLDER}/.installed_kernels"