Compare commits

...

11 Commits

Author SHA1 Message Date
84d682ea8c Fix kdumpst-load.sh.in with btrfs subvolumes 2026-02-19 22:04:58 -08:00
782d912471 Merge branch 'main' into 'main'
initramfs/initcpio: create MOUNT_FOLDER if it doesn't exist

See merge request gpiccoli/kdumpst!1
2025-12-18 13:39:08 -03:00
9c22feadfa initramfs/initcpio: create MOUNT_FOLDER if it doesn't exist
/usr/lib/kdumpst/kdump-mkinitcpio-hook.sh is run by the kernel hook
when using mkinitcpio and a new kernel is installed.

If MOUNT_FOLDER does not exist it will fail with the following error
message:

==> ERROR: Invalid option -g -- '<MOUNT_FOLDER>/<IMG_FILE>' must be writable
2025-12-15 11:54:37 +01:00
92afdc48d6 initramfs: Effectively disable GPU drivers from kdump kernel
The gitlab issue https://gitlab.freedesktop.org/gpiccoli/kdumpst/-/issues/19
was first reported by Saurabh, regarding GPU drivers getting included on
the kdump initrd. We've managed to improve the code a bit, but the solution
we proposed there was both wrong (for initcpio) *and* incomplete.

The user Ethanell reopened the issue, mentioning that even after the
patch that allegedly fixed the problem, they were getting amdgpu driver
included in the kdump initrd. That was the "wrong" portion of the fix:
in my naivety, I thought we could just remove the modules in the kdump
install hook. But...happens that initcpio works with a lazy approach: some
install hooks execute add_module(), and that signals to the later effective
inclusion of the modules by mkinitcpio; so in other words, the kdump
install hook was deleting no modules at all.

Special thanks to Foxboron and noclaf for the discussion about that on
IRC, which was very enlightening.

Now, the proper approach is simple: just to skip hooks that add the GPU
drivers, like plymouth and kms. Also took the opportunity to include the
microcode hook in the ban list, since we don't want kernel updating CPU
ucode in case of the microcode packages were updated (would be rare, but
why not save a bit of space dropping that?). Finally, I've removed the
GPU drivers delete code from the initcpio kdump install hook, since it
was a nop in the end.

That's it, right? No. Still there's the part two of my statement above:
the prior approach was wrong, but not only, it was also *incomplete*. That
is due to cases like Ethanell's: users that manually include GPU drivers
in their initramfs images, for things like crypto or splash screen. It's
also hard or better saying, *impossible*, to guess all hooks that add GPU
drivers to the initramfs.

So to cover manual inclusions or other hooks, we also add hereby extra
kdump command-line flags to avoid the DRM and some GFX drivers probe
during the kdump kernel boot. In order to not grow the drivers ban list
too much, my attempt was to add common in-tree GPU drivers, but also block
the DRM init call. Hopefully this time this is enough to disable GFX on kdump!

Fixes: 4767b8095f ("initramfs: Fix the removal of GPU drivers from the minimal initrd")
Reported-by: Ethanell (@flifloo)
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-08-08 10:17:18 -03:00
585f92b30e README: Add instructions / reminder for users about enabling the systemd service
The README currently doesn't include explicit instructions for users to
enable/load the systemd service - Arch Linux philosophy is that services
shouldn't autoload, so that action is required from the user. Thanks to
the very useful report from Antonio, let's fix that.

Closes: https://gitlab.freedesktop.org/gpiccoli/kdumpst/-/issues/20
Reported-by: Antonio Tigri (@BlessedLongsword)
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-05-11 13:13:45 -03:00
4767b8095f initramfs: Fix the removal of GPU drivers from the minimal initrd
Thanks to the great report from Saurabh Charde, we noticed that the
removal command used in the minimal initrd creation for deleting the
GPU/DRM drivers wasn't working. Fix that so now GPU drivers aren't
included for real (both for space and boot "issue-prone" criteria).

Closes: https://gitlab.freedesktop.org/gpiccoli/kdumpst/-/issues/19
Reported-by: Saurabh Charde (@schardev)
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-05-06 15:20:38 -03:00
6141e3c4cb config/doc: Fix memory unit in the config file
In the description we have in the 00-default config file, both
Pstore memory configs are presented as if they're in MB. They
are in *bytes* indeed, so fix the braino.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-03-31 10:30:21 -03:00
462eef9828 initramfs: Refactor alpm hooks to prevent harmless errors on kernel installation
Based on the way kdumpst alpm hooks were coded, we have currently one hook
per initrd system supported (mkinitcpio, mkinitcpio-git, dracut). When a
kernel package is installed/upgraded/removed, all of them are triggered;
but usually users only have one initrd system (enough headaches with just
one, imagine having more heh).

The net effect of this, due to the "verbiage" of alpm, is that harmless
error messages were shown, like the following one:

"error: unable to run hook 99-kdump-dracut.hook: could not satisfy
dependencies"

This one was quite common since the vast majority of Arch users rely
on mkinitcpio. And this message would show at *every* kernel package
operation, leading users to wonder what's wrong (may they pay attention
to error messages, of course).

In order to fix that, we hereby follow a great and simple suggestion from
Antiz at #archlinux-projects/Libera (thanks!): let's use a shell call to
encompass the tests for different initrd systems. With that, was easy also
to remove the redundant mkinitcpio-git hook. No functional change should
be expected from this change.

Closes: #14 ("Minimal initramfs pacman hooks should not present error messages on different init systems")
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-01-05 17:08:16 -03:00
512cd8ff4a initramfs: Prevent creating the minimal initrd if kernel was uninstalled
This condition should be a unusual, but it's possible if users are
installing kdumpst right after a kernel upgrade, without rebooting
for example. To achieve this, just check if the modules dir exists.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-01-05 17:08:16 -03:00
c83ad9a83e initramfs/initcpio: Fix minimal initrd creation
Due to a brainfart, forgot the "-k" modifier on mkinitcpio call. It
happened to work by coincidence - without this flag, "uname -r" was
used and worked most of times, but that's clearly a bug.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2024-01-05 17:08:16 -03:00
b19a940fbd kdumpst-load: Guard initrd creation against failures
Though rare, they might happen and then journal show non-handled
errors - better sanitize a bit the message.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2023-12-23 17:02:47 -03:00
10 changed files with 66 additions and 35 deletions

View File

@ -14,8 +14,8 @@
# If USE_PSTORE_RAM is set to 1, Kdump won't be loaded. Instead, the Pstore
# RAM backend will be configured. In order to have success, this operation
# relies in having an available RAM buffer on /proc/iomem with at least
# PSTORE_MEM_AMOUNT (decimal, in MB) in size. Also, kernel must be able to
# allocate a contiguous memory amount of PSTORE_RECORD_SZ (decimal, MB).
# PSTORE_MEM_AMOUNT (decimal, bytes) in size. Also, kernel must be able to
# allocate a contiguous memory amount of PSTORE_RECORD_SZ (decimal, bytes).
# If there is no such RAM buffer, there is a possibility to make use of
# the crash kernel area for that. There are risks: such memory area could
# have its address mapped differently across kernel updates; also if both
@ -50,7 +50,7 @@ MOUNT_FOLDER="/var/crash/kdumpst"
FULL_COREDUMP=1
MAKEDUMPFILE_COREDUMP_CMD="-z -d 31"
MAKEDUMPFILE_DMESG_CMD="--dump-dmesg"
KDUMP_APPEND_CMDLINE="panic=-1 oops=panic fsck.mode=force fsck.repair=yes nr_cpus=1 reset_devices"
KDUMP_APPEND_CMDLINE="panic=-1 oops=panic fsck.mode=force fsck.repair=yes nr_cpus=1 reset_devices initcall_blacklist=drm_core_init module_blacklist=amdgpu,i915,nouveau"
#
#
# GRUB-related settings
@ -68,3 +68,7 @@ GRUB_AUTOSET=1
GRUB_BOOT_FILE="/boot/grub/grub.cfg"
GRUB_CFG_FILE="/etc/default/grub"
GRUB_CMDLINE="crashkernel=256M "
# If the BOOT_IMAGE kernel command line parameter begins with this, it will be
# removed. For example, if you use btrfs and have a root sub-volume called "@",
# set this to "/@"
GRUB_BOOT_IMAGE_PREFIX=""

View File

@ -16,7 +16,7 @@ kdumpst-load.sh: kdumpst-load.header common.sh kdumpst-load.sh.in
save-dumps.sh: save-dumps.header common.sh save-dumps.sh.in
cat $^ > $@
99-kdump-dracut.hook: initramfs/alpm-hook.generic
99-kdump-dracut.hook: initramfs/alpm-hook.INITRD
sed 's/INITRD/dracut/g' $^ > initramfs/$@
kdump-dracut-hook.sh: common.sh initramfs/dracut/dracut-common.sh
@ -31,12 +31,9 @@ module-setup.sh: initramfs/dracut/module-setup.header common.sh initramfs/dracut
.PHONY: dracut
dracut: 99-kdump-dracut.hook kdump-dracut-hook.sh module-setup.sh
99-kdump-mkinitcpio.hook: initramfs/alpm-hook.generic
99-kdump-mkinitcpio.hook: initramfs/alpm-hook.INITRD
sed 's/INITRD/mkinitcpio/g' $^ > initramfs/$@
99-kdump-mkinitcpio-git.hook: initramfs/alpm-hook.generic
sed 's/INITRD/mkinitcpio-git/g' $^ > initramfs/$@
kdump-mkinitcpio-hook.sh: common.sh initramfs/initcpio/initcpio-common.sh
sed 's/INITRD/mkinitcpio/g' initramfs/alpm-script.header > initramfs/alpm-header-initcpio
sed 's/INITRD/mkinitcpio/g' initramfs/alpm-script.sh.in > initramfs/alpm-script.sh.in-initcpio
@ -51,7 +48,7 @@ kdump.install: initramfs/initcpio/kdump.install.header common.sh initramfs/initc
cat $^ > initramfs/initcpio/$@
.PHONY: mkinitcpio
mkinitcpio: 99-kdump-mkinitcpio.hook 99-kdump-mkinitcpio-git.hook kdump-mkinitcpio-hook.sh kdump.hook kdump.install
mkinitcpio: 99-kdump-mkinitcpio.hook kdump-mkinitcpio-hook.sh kdump.hook kdump.install
all: kdumpst-load.sh save-dumps.sh dracut mkinitcpio
@ -64,17 +61,16 @@ install: all
install -D -m0644 00-default.conf $(DESTDIR)$(sharedir)/kdumpst.d/00-default
install -D -m0644 initramfs/99-kdump-dracut.hook $(DESTDIR)$(alpmhooksdir)/99-kdump-dracut.hook
install -D -m0644 initramfs/99-kdump-mkinitcpio.hook $(DESTDIR)$(alpmhooksdir)/99-kdump-mkinitcpio.hook
install -D -m0644 initramfs/99-kdump-mkinitcpio-git.hook $(DESTDIR)$(alpmhooksdir)/99-kdump-mkinitcpio-git.hook
install -D -m0644 initramfs/99-kdump-kernel.hook $(DESTDIR)$(alpmhooksdir)/99-kdump-kernel.hook
install -D -m0755 initramfs/dracut/kdump-dracut-hook.sh $(DESTDIR)$(libdir)/kdumpst/kdump-dracut-hook.sh
install -D -m0755 initramfs/kdump-collect.sh $(DESTDIR)$(libdir)/kdumpst/dracut/kdump-collect.sh
install -D -m0755 initramfs/dracut/module-setup.sh $(DESTDIR)$(libdir)/kdumpst/dracut/module-setup.sh
install -D -m0755 initramfs/initcpio/kdump-mkinitcpio-hook.sh $(DESTDIR)$(libdir)/kdumpst/kdump-mkinitcpio-hook.sh
install -D -m0755 initramfs/initcpio/kdump-mkinitcpio-hook.sh $(DESTDIR)$(libdir)/kdumpst/kdump-mkinitcpio-git-hook.sh
install -D -m0644 initramfs/initcpio/kdump.hook $(DESTDIR)$(libdir)/kdumpst/initcpio/kdump.hook
install -D -m0644 initramfs/initcpio/kdump.install $(DESTDIR)$(libdir)/kdumpst/initcpio/kdump.install
clean:
rm -f kdumpst-load.sh save-dumps.sh
rm -f initramfs/99-kdump-*
rm -f initramfs/99-kdump-{mkinitcpio,dracut}.hook
rm -f initramfs/dracut/{kdump-dracut-hook.sh,module-setup.sh}
rm -f initramfs/initcpio/kdump{-mkinitcpio-hook.sh,.hook,.install}

View File

@ -17,8 +17,8 @@
#
# 1. Install the package with pacman if not available in your system; to check
# if it's already installed look the pacman installed package list. Also, be
# sure the systemd service was properly loaded by checking
# 'systemctl status kdumpst-init.service'.
# sure to properly enable/load the systemd service, since the services on Arch
# Linux do not autoload - for that, just run 'systemctl enable --now kdumpst-init.service'.
#
# 2. In a crash event, the dmesg log is collected, and by default this happens
# via the pstore mechanism, i.e., no crashkernel memory needs to be reserved

View File

@ -4,8 +4,8 @@
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
#
# alpm hook to deal with the kdump initramfs creation/deletion
# for INITRD users. This hook would act upon kernel installation,
# upgrade and removal, also on INITRD package installation.
# for initcpio or dracut. This hook would act upon kernel
# installation, upgrade and removal.
#
[Trigger]
Type = Path
@ -14,14 +14,8 @@ Operation = Remove
Operation = Upgrade
Target = usr/lib/modules/*/vmlinuz
[Trigger]
Type = Package
Operation = Install
Target = INITRD
[Action]
Description = Managing kdump minimal initramfs and INITRD hooks...
Depends=INITRD
Description = Managing kdump minimal initramfs
When = PostTransaction
Exec = /usr/lib/kdumpst/kdump-INITRD-hook.sh
Exec =/bin/bash -s -c 'if command -v mkinitcpio > /dev/null; then /usr/lib/kdumpst/kdump-mkinitcpio-hook.sh; fi && if command -v dracut > /dev/null; then /usr/lib/kdumpst/kdump-dracut-hook.sh; fi'
NeedsTargets

View File

@ -0,0 +1,18 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Copyright (c) 2022 Valve.
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
#
# alpm hook to deal with the kdump initramfs creation/deletion
# for INITRD. This hook would act upon INITRD package installation.
#
[Trigger]
Type = Path
Operation = Install
Target = usr/bin/INITRD
[Action]
Description = Managing kdump minimal initramfs for INITRD installation
When = PostTransaction
Exec = /usr/lib/kdumpst/kdump-INITRD-hook.sh
NeedsTargets

View File

@ -15,6 +15,19 @@ if [ -n "$1" ]; then
if command -v INITRD 1>/dev/null; then
INITRD_installation
# Worth noticing that it is possible (though unlikely) that during
# the kdumpst package installation, users are running a previously
# uninstalled kernel. Imagine if the user upgrades the kernel, and
# then install kdumpst before rebooting. With that, creating an
# initrd fails here since it relies on "uname -r". To prevent such
# unhandled error, check if this kernel's modules directory exists.
if [ ! -d "/lib/modules/$1" ]; then
logger "kdumpst: no kernel modules dir; defer initrd creation to next boot"
exit 0
fi
create_initramfs_INITRD "$1"
fi
exit 0

View File

@ -10,9 +10,10 @@ installkernel() {
# to reduce the size of the minimal initramfs being created - kdump
# is an non-graphical environment. This should have been already done
# via dracut cmdline arguments, but play safe and delete here as well.
# Our list includes the most common FWs/drivers (amd, i915, nvidia).
rm -rf "$initdir"/usr/lib/firmware/{amdgpu,i915,nvidia,radeon}
rm -rf "$initdir"/usr/lib/modules/*/kernel/drivers/gpu/drm/{amd,i915,nouveau,radeon}
# Our list includes the most common GFX FW blobs (AMD, i915, Nvidia)
# and all GPU/DRM drivers.
rm -rf "$initdir"/usr/lib/firmware/{amdgpu,i915,nvidia,radeon}/
rm -rf "$initdir"/usr/lib/modules/*/kernel/drivers/gpu/drm/*
FSMOD="$(findmnt -n -o FSTYPE --target "${MOUNT_FOLDER}")"
if [ -z "${FSMOD}" ]; then

View File

@ -6,9 +6,10 @@
# before running any of these functions!
#
create_initramfs_mkinitcpio() {
mkdir -p "${MOUNT_FOLDER}"
rm -f "${MOUNT_FOLDER}/kdump-initrd-$1.img"
mkinitcpio -A kdump -g "${MOUNT_FOLDER}/kdump-initrd-$1.img" "$1" 1>/dev/null
mkinitcpio -A kdump -S microcode,kms,plymouth -g "${MOUNT_FOLDER}/kdump-initrd-$1.img" -k "$1" 1>/dev/null
if [ -s "${MOUNT_FOLDER}/kdump-initrd-$1.img" ]; then
logger "kdumpst: created initcpio minimal initramfs"

View File

@ -33,12 +33,6 @@ build() {
BASE_FLD="${MOUNT_FOLDER#*$TGT}"
echo "${BASE_FLD}" > "${BUILDROOT}"/usr/lib/kdumpst/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
}

View File

@ -200,7 +200,7 @@ KDUMP_CMDLINE="${KDUMP_CMDLINE} ${KDUMP_APPEND_CMDLINE}"
# information. If it fails, then attempt prepending /boot into that (faced
# both situations in the field so far).
VMLINUX="$(grep -o 'BOOT_IMAGE=[^ ]*' /proc/cmdline)"
VMLINUX="${VMLINUX#*BOOT_IMAGE=}"
VMLINUX="${VMLINUX#*BOOT_IMAGE=${GRUB_BOOT_IMAGE_PREFIX}}"
if [ ! -s "${VMLINUX}" ]; then
VMLINUX="/boot/${VMLINUX}"
if [ ! -s "${VMLINUX}" ]; then
@ -214,6 +214,12 @@ fi
INITRD_FNAME="${MOUNT_FOLDER}/kdump-initrd-$(uname -r).img"
if [ ! -s "${INITRD_FNAME}" ]; then
create_initrd
# Check if create_initrd() succeeded.
if [ ! -s "${INITRD_FNAME}" ]; then
logger "kdumpst: failure on initrd creation - aborting."
exit 1
fi
fi
if ! kexec -s -p "${VMLINUX}" --initrd "${INITRD_FNAME}" --append="${KDUMP_CMDLINE}"; then
@ -221,3 +227,7 @@ if ! kexec -s -p "${VMLINUX}" --initrd "${INITRD_FNAME}" --append="${KDUMP_CMDLI
exit 1
fi
logger "kdumpst: panic kexec loaded successfully"
# Local Variables:
# indent-tabs-mode: t
# End: