kdump-load: Improve vmlinux binary path obtaining

Currently we just look the command-line for the systemd BOOT_IMAGE
entry and try to load the vmlinux as described there.

But in the field we noticed we have 2 patterns: either this cmdline
entry is complete/correct and maps to the vmlinux binary, OR it shows
the name of the file but not the full path (Arch case). So, let's
hereby attempt prepending /boot in case the validation for the first
case fails - if both ways don't work, we just fail kdump for now.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
This commit is contained in:
Guilherme G. Piccoli
2023-01-19 10:35:51 -03:00
parent 5859628dbd
commit 293ff98b12

View File

@ -182,7 +182,18 @@ grub_update kdump
KDUMP_CMDLINE=$(sed -re 's/(^| )(crashkernel|hugepages|hugepagesz)=[^ ]*//g;s/"/\\\\"/' /proc/cmdline) KDUMP_CMDLINE=$(sed -re 's/(^| )(crashkernel|hugepages|hugepagesz)=[^ ]*//g;s/"/\\\\"/' /proc/cmdline)
KDUMP_CMDLINE="${KDUMP_CMDLINE} panic=-1 oops=panic fsck.mode=force fsck.repair=yes nr_cpus=1 reset_devices" KDUMP_CMDLINE="${KDUMP_CMDLINE} panic=-1 oops=panic fsck.mode=force fsck.repair=yes nr_cpus=1 reset_devices"
# To obtain the vmlinux binary path, try first using directly the command-line
# 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="$(grep -o 'BOOT_IMAGE=[^ ]*' /proc/cmdline)"
VMLINUX="${VMLINUX#*BOOT_IMAGE=}"
if [ ! -s "${VMLINUX}" ]; then
VMLINUX="/boot/${VMLINUX}"
if [ ! -s "${VMLINUX}" ]; then
logger "kdump: couldn't find the kernel image"
exit 1
fi
fi
# In case we don't have a valid initrd, for some reason, try creating # In case we don't have a valid initrd, for some reason, try creating
# one before loading kdump (or else it will fail). # one before loading kdump (or else it will fail).
@ -191,7 +202,7 @@ if [ ! -s "${INITRD_FNAME}" ]; then
create_initrd create_initrd
fi fi
if ! kexec -s -p "${VMLINUX#*BOOT_IMAGE=}" --initrd "${INITRD_FNAME}" --append="${KDUMP_CMDLINE}"; then if ! kexec -s -p "${VMLINUX}" --initrd "${INITRD_FNAME}" --append="${KDUMP_CMDLINE}"; then
logger "kdump: kexec load failed" logger "kdump: kexec load failed"
exit 1 exit 1
fi fi