Simplify the management of the kernel parameter crashkernel
Currently, kexec-tools only updates the crashkernel to a new default value only when both two conditions are met, - auto_reset_crashkernel=yes in kdump.conf - existing kernels or current running kernel should use the old default value. To address seen corner cases, the logic to tell if the second condition is met becomes quite complex. Instead of making the logic more complex to support aarch64-64k, this patch drops the second condition to simplify the management of the crashkernel kernel parameter. Another change brought by this simplification is kexec-tools will also set up the kernel crashkernel parameter for a fresh install (previously it's limited to osbuild). Note 1. This patch also stop trying to update /etc/default/grub because a) it only affects the static file /boot/grub2/grub.cfg b) grubby is recommended to change the kernel command-line parameters for both Fedora [1] and RHEL9 [2][3] c) For the cases of aarch64 and POWER, different kernels could have different default crashkernel value. 2. Starting with Fedora 37, posttrans rpm scriplet distinguish between package install and upgrade. [1] https://fedoraproject.org/wiki/GRUB_2 [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/configuring-kernel-command-line-parameters_managing-monitoring-and-updating-the-kernel#changing-kernel-command-line-parameters-for-all-boot-entries_configuring-kernel-command-line-parameters [3] https://access.redhat.com/solutions/1136173 Signed-off-by: Coiby Xu <coxu@redhat.com> Reviewed-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
parent
cdc0253a3c
commit
5b31b099ae
@ -28,9 +28,8 @@ understand how this configuration file affects the behavior of kdump.
|
|||||||
|
|
||||||
.B auto_reset_crashkernel <yes|no>
|
.B auto_reset_crashkernel <yes|no>
|
||||||
.RS
|
.RS
|
||||||
determine whether to reset kernel crashkernel to new default value
|
determine whether to reset kernel crashkernel parameter to the default value
|
||||||
or not when kexec-tools updates the default crashkernel value and
|
or not when kexec-tools is updated or a new kernel is installed.
|
||||||
existing kernels using the old default kernel crashkernel value
|
|
||||||
|
|
||||||
.B raw <partition>
|
.B raw <partition>
|
||||||
.RS
|
.RS
|
||||||
|
84
kdumpctl
84
kdumpctl
@ -1675,72 +1675,37 @@ _is_bootloader_installed()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# update the crashkernel value in GRUB_ETC_DEFAULT if necessary
|
_update_crashkernel()
|
||||||
#
|
|
||||||
# called by reset_crashkernel_after_update and inherit its array variable
|
|
||||||
# _crashkernel_vals
|
|
||||||
update_crashkernel_in_grub_etc_default_after_update()
|
|
||||||
{
|
{
|
||||||
local _crashkernel _fadump_val
|
local _kernel _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg
|
||||||
local _dump_mode _old_default_crashkernel _new_default_crashkernel
|
|
||||||
|
|
||||||
if [[ $(uname -m) == s390x ]]; then
|
_kernel=$1
|
||||||
return
|
_dump_mode=$(get_dump_mode_by_kernel "$_kernel")
|
||||||
|
_old_default_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
|
||||||
|
_new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode")
|
||||||
|
if [[ $_old_default_crashkernel != "$_new_default_crashkernel" ]]; then
|
||||||
|
_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
|
||||||
|
if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then
|
||||||
|
_msg="For kernel=$_kernel, crashkernel=$_new_default_crashkernel now. Please reboot the system for the change to take effet."
|
||||||
|
_msg+=" Note if you don't want kexec-tools to manage the crashkernel kernel parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf."
|
||||||
|
dinfo "$_msg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel)
|
|
||||||
|
|
||||||
if [[ -z $_crashkernel ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
_fadump_val=$(_read_kernel_arg_in_grub_etc_default fadump)
|
|
||||||
_dump_mode=$(get_dump_mode_by_fadump_val "$_fadump_val")
|
|
||||||
|
|
||||||
_old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]}
|
|
||||||
_new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]}
|
|
||||||
|
|
||||||
if [[ $_crashkernel == auto ]] ||
|
|
||||||
[[ $_crashkernel == "$_old_default_crashkernel" &&
|
|
||||||
$_new_default_crashkernel != "$_old_default_crashkernel" ]]; then
|
|
||||||
_update_kernel_arg_in_grub_etc_default crashkernel "$_new_default_crashkernel"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# shellcheck disable=SC2154 # false positive when dereferencing an array
|
# shellcheck disable=SC2154 # false positive when dereferencing an array
|
||||||
reset_crashkernel_after_update()
|
reset_crashkernel_after_update()
|
||||||
{
|
{
|
||||||
local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel
|
local _kernel
|
||||||
declare -A _crashkernel_vals
|
|
||||||
|
|
||||||
if ! _is_bootloader_installed; then
|
if ! _is_bootloader_installed; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_crashkernel_vals[old_kdump]=$(cat /tmp/old_default_crashkernel 2> /dev/null)
|
|
||||||
_crashkernel_vals[old_fadump]=$(cat /tmp/old_default_crashkernel_fadump 2> /dev/null)
|
|
||||||
_crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump)
|
|
||||||
_crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump)
|
|
||||||
|
|
||||||
for _kernel in $(_get_all_kernels_from_grubby ALL); do
|
for _kernel in $(_get_all_kernels_from_grubby ALL); do
|
||||||
_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
|
_update_crashkernel "$_kernel"
|
||||||
if [[ $_crashkernel == auto ]]; then
|
|
||||||
reset_crashkernel "--kernel=$_kernel"
|
|
||||||
elif [[ -n $_crashkernel ]]; then
|
|
||||||
_dump_mode=$(get_dump_mode_by_kernel "$_kernel")
|
|
||||||
_old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]}
|
|
||||||
_new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]}
|
|
||||||
if [[ $_crashkernel == "$_old_default_crashkernel" ]] &&
|
|
||||||
[[ $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then
|
|
||||||
_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
|
|
||||||
if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then
|
|
||||||
echo "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
update_crashkernel_in_grub_etc_default_after_update
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# read the value of an environ variable from given environ file path
|
# read the value of an environ variable from given environ file path
|
||||||
@ -1764,8 +1729,7 @@ _is_osbuild()
|
|||||||
|
|
||||||
reset_crashkernel_for_installed_kernel()
|
reset_crashkernel_for_installed_kernel()
|
||||||
{
|
{
|
||||||
local _installed_kernel _running_kernel _crashkernel _crashkernel_running
|
local _installed_kernel
|
||||||
local _dump_mode_running _fadump_val_running
|
|
||||||
|
|
||||||
# During package install, only try to reset crashkernel for osbuild
|
# During package install, only try to reset crashkernel for osbuild
|
||||||
# thus to avoid calling grubby when installing os via anaconda
|
# thus to avoid calling grubby when installing os via anaconda
|
||||||
@ -1784,21 +1748,7 @@ reset_crashkernel_for_installed_kernel()
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _running_kernel=$(_get_current_running_kernel_path); then
|
_update_crashkernel "$_installed_kernel"
|
||||||
ddebug "Couldn't find current running kernel"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
_crashkernel=$(get_grub_kernel_boot_parameter "$_installed_kernel" crashkernel)
|
|
||||||
_crashkernel_running=$(get_grub_kernel_boot_parameter "$_running_kernel" crashkernel)
|
|
||||||
_dump_mode_running=$(get_dump_mode_by_kernel "$_running_kernel")
|
|
||||||
_fadump_val_running=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
|
|
||||||
|
|
||||||
if [[ $_crashkernel != "$_crashkernel_running" ]]; then
|
|
||||||
if _update_kernel_cmdline "$_installed_kernel" "$_crashkernel_running" "$_dump_mode_running" "$_fadump_val_running"; then
|
|
||||||
echo "kexec-tools has reset $_installed_kernel to use the new default crashkernel value $_crashkernel_running"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -260,21 +260,6 @@ chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpini
|
|||||||
mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
|
mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
|
||||||
mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
|
mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
|
||||||
|
|
||||||
%pre
|
|
||||||
# Save the old default crashkernel values to /tmp/ when upgrading the package
|
|
||||||
# so kdumpctl later can tell if it should update the kernel crashkernel
|
|
||||||
# parameter in the posttrans scriptlet. Note this feauture of auto-updating
|
|
||||||
# the kernel crashkernel parameter currently doesn't support ostree, so skip it
|
|
||||||
# for ostree.
|
|
||||||
if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then
|
|
||||||
kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel 2>/dev/null
|
|
||||||
%ifarch ppc64 ppc64le
|
|
||||||
kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null
|
|
||||||
%endif
|
|
||||||
fi
|
|
||||||
# don't block package update
|
|
||||||
:
|
|
||||||
|
|
||||||
%post
|
%post
|
||||||
# Initial installation
|
# Initial installation
|
||||||
%systemd_post kdump.service
|
%systemd_post kdump.service
|
||||||
@ -341,21 +326,15 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
%posttrans
|
%posttrans
|
||||||
# Try to reset kernel crashkernel value to new default value based on the old
|
# Try to reset kernel crashkernel value to new default value or set up
|
||||||
# default value or set up crasherkernel value for osbuild
|
# crasherkernel value for new install
|
||||||
#
|
#
|
||||||
# Note
|
# Note
|
||||||
# 1. Skip ostree systems as they are not supported.
|
# 1. Skip ostree systems as they are not supported.
|
||||||
# 2. "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade. The
|
# 2. For Fedora 36 and RHEL9, "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade;
|
||||||
# former case is used to set up crashkernel for osbuild
|
# For Fedora > 36, "[ $1 == 1 ]" only means install and "[ $1 == 2 ]" means upgrade
|
||||||
if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then
|
if [ ! -f /run/ostree-booted ] && [ $1 == 1 -o $1 == 2 ]; then
|
||||||
kdumpctl _reset-crashkernel-after-update
|
kdumpctl _reset-crashkernel-after-update
|
||||||
rm /tmp/old_default_crashkernel 2>/dev/null
|
|
||||||
%ifarch ppc64 ppc64le
|
|
||||||
rm /tmp/old_default_crashkernel_fadump 2>/dev/null
|
|
||||||
%endif
|
|
||||||
# dnf would complain about the exit code not being 0. To keep it happy,
|
|
||||||
# always return 0
|
|
||||||
:
|
:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user