diff --git a/kdump.conf.5 b/kdump.conf.5 index e3e9900..ec28552 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -28,9 +28,8 @@ understand how this configuration file affects the behavior of kdump. .B auto_reset_crashkernel .RS -determine whether to reset kernel crashkernel to new default value -or not when kexec-tools updates the default crashkernel value and -existing kernels using the old default kernel crashkernel value +determine whether to reset kernel crashkernel parameter to the default value +or not when kexec-tools is updated or a new kernel is installed. .B raw .RS diff --git a/kdumpctl b/kdumpctl index 61cdfe0..bd3e8fc 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1735,72 +1735,37 @@ _is_bootloader_installed() fi } -# update the crashkernel value in GRUB_ETC_DEFAULT if necessary -# -# called by reset_crashkernel_after_update and inherit its array variable -# _crashkernel_vals -update_crashkernel_in_grub_etc_default_after_update() +_update_crashkernel() { - local _crashkernel _fadump_val - local _dump_mode _old_default_crashkernel _new_default_crashkernel + local _kernel _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg - if [[ $(uname -m) == s390x ]]; then - return - 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" + _kernel=$1 + _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 } + # shellcheck disable=SC2154 # false positive when dereferencing an array reset_crashkernel_after_update() { - local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel - declare -A _crashkernel_vals + local _kernel if ! _is_bootloader_installed; then return 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 - _crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) - 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 + _update_crashkernel "$_kernel" done - - update_crashkernel_in_grub_etc_default_after_update } # read the value of an environ variable from given environ file path @@ -1824,8 +1789,7 @@ _is_osbuild() reset_crashkernel_for_installed_kernel() { - local _installed_kernel _running_kernel _crashkernel _crashkernel_running - local _dump_mode_running _fadump_val_running + local _installed_kernel # During package install, only try to reset crashkernel for osbuild # thus to avoid calling grubby when installing os via anaconda @@ -1844,23 +1808,7 @@ reset_crashkernel_for_installed_kernel() return fi - if ! _running_kernel=$(_get_current_running_kernel_path); then - 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 - elif [[ $_crashkernel == auto ]]; then - reset_crashkernel "--kernel=$_installed_kernel" - fi + _update_crashkernel "$_installed_kernel" } if [[ ! -f $KDUMP_CONFIG_FILE ]]; then diff --git a/kexec-tools.spec b/kexec-tools.spec index e4f7d97..04248bd 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -278,21 +278,6 @@ chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpini 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/ -%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 # Initial installation %systemd_post kdump.service @@ -359,21 +344,15 @@ do done %posttrans -# Try to reset kernel crashkernel value to new default value based on the old -# default value or set up crasherkernel value for osbuild +# Try to reset kernel crashkernel value to new default value or set up +# crasherkernel value for new install # # Note # 1. Skip ostree systems as they are not supported. -# 2. "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade. The -# former case is used to set up crashkernel for osbuild -if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then +# 2. For Fedora 36 and RHEL9, "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade; +# For Fedora > 36, "[ $1 == 1 ]" only means install and "[ $1 == 2 ]" means upgrade +if [ ! -f /run/ostree-booted ] && [ $1 == 1 -o $1 == 2 ]; then 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