Hi Lichen,
I think a cleaner approach to extract the logic of determine
KDUMP_KERNEL from prepare_kdump_bootinfo into a function. This function
will return KDUMP_KERNEL given a kernel version.
On Tue, May 17, 2022 at 09:08:33AM +0800, Lichen Liu wrote:
Kdump uses currently running kernel as default, but when currently
running kernel is a debug kernel, it will consume more memory,
which may cause out-of-memory and fail to collect vmcore.
Now we will try to use non-debug kernels first if possible.
You can still specify the kernel by setting the KDUMP_KERNELVER in
/etc/sysconfig/kdump.
This patch may only works for Fedora and RHEL, since we rely on the
"+debug" suffix to determine if the currently running kernel is a
debug version. For other distros, fallback to using the currently
running kernel.
Btw, kexec(a)lists.fedoraproject.org targets Fedora/RHEL. There is no need
to consider other distros.
Signed-off-by: Lichen Liu <lichliu(a)redhat.com>
---
kdump-lib.sh | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index b137c89..bd4eeed 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -642,11 +642,21 @@ prepare_kexec_args()
#
prepare_kdump_bootinfo()
{
- local boot_img boot_imglist boot_dirlist boot_initrdlist
+ local boot_img boot_imglist boot_dirlist boot_initrdlist nondebug_kernelver
debug_kernelver debug_imglist
local machine_id dir img default_initrd_base var_target_initrd_dir
if [[ -z $KDUMP_KERNELVER ]]; then
KDUMP_KERNELVER="$(uname -r)"
+ nondebug_kernelver="$(echo -n "$KDUMP_KERNELVER" | sed -n -e
's/\(.*\)+debug$/\1/p')"
+ fi
+
+
+ # Use nondebug kernel if possible, because debug kernel will consume more memory and may
oom.
+ if [[ -n $nondebug_kernelver ]]; then
+ dinfo "Trying to use $nondebug_kernelver."
+ debug_kernelver="$KDUMP_KERNELVER"
+ debug_imglist="$KDUMP_IMG-$debug_kernelver$KDUMP_IMG_EXT
$machine_id/$debug_kernelver/$KDUMP_IMG"
+ KDUMP_KERNELVER="$nondebug_kernelver"
fi
read -r machine_id < /etc/machine-id
@@ -656,7 +666,11 @@ prepare_kdump_bootinfo()
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in
(hd0,gpt1) format
boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/"
/proc/cmdline)"
if [[ -n $boot_img ]]; then
- boot_imglist="$boot_img $boot_imglist"
+ if [[ "$boot_img" == *"+debug"* ]]; then
+ debug_imglist="$boot_img $debug_imglist"
+ else
+ boot_imglist="$boot_img $boot_imglist"
+ fi
fi
for dir in $boot_dirlist; do
@@ -668,6 +682,21 @@ prepare_kdump_bootinfo()
done
done
+ if ! [[ -e $KDUMP_KERNEL ]]; then
+ if [[ -n $debug_kernelver ]]; then
+ dinfo "Fallback to using debug kernel"
+ for dir in $boot_dirlist; do
+ for img in $debug_imglist; do
+ if [[ -f "$dir/$img" ]]; then
+ KDUMP_KERNEL=$(echo "$dir/$img" | tr -s '/')
+ KDUMP_KERNELVER="$debug_kernelver"
+ break 2
+ fi
+ done
+ done
+ fi
+ fi
+
if ! [[ -e $KDUMP_KERNEL ]]; then
derror "Failed to detect kdump kernel location"
return 1
--
2.27.0
_______________________________________________
kexec mailing list -- kexec(a)lists.fedoraproject.org
To unsubscribe send an email to kexec-leave(a)lists.fedoraproject.org
Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives:
https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Do not reply to spam on the list, report it:
https://pagure.io/fedora-infrastructure
--
Best regards,
Coiby