kdumpctl: Add kdumpctl reset-crashkernel

Resolves: bz1974638
Upstream: Fedora
Conflict: None

commit 86130ec10f
Author: Kairui Song <kasong@redhat.com>
Date:   Thu Jun 10 13:06:22 2021 +0800

    kdumpctl: Add kdumpctl reset-crashkernel

    In newer kernel, crashkernel.default will contain the default
    crashkernel value of a kernel build. So introduce a new sub command
    to help user reset kernel crashkernel size to the default value.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Baoquan He <bhe@redhat.com>

Signed-off-by: Kairui Song <kasong@redhat.com>
This commit is contained in:
Kairui Song 2021-06-10 13:06:22 +08:00
parent 80c1913e4a
commit a0fe51b32e
2 changed files with 48 additions and 2 deletions

View File

@ -1308,6 +1308,40 @@ do_estimate() {
fi
}
reset_crashkernel() {
local kernel=$1 entry crashkernel_default
local grub_etc_default="/etc/default/grub"
[[ -z "$kernel" ]] && kernel=$(uname -r)
crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null)
if [[ -z "$crashkernel_default" ]]; then
derror "$kernel doesn't have a crashkernel.default"
exit 1
fi
if is_atomic; then
if rpm-ostree kargs | grep -q "crashkernel="; then
rpm-ostree --replace="crashkernel=$crashkernel_default"
else
rpm-ostree --append="crashkernel=$crashkernel_default"
fi
else
entry=$(grubby --info ALL | grep "^kernel=.*$kernel")
entry=${entry#kernel=}
entry=${entry#\"}
entry=${entry%\"}
if [[ -f "$grub_etc_default" ]]; then
sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default"
fi
[[ -f /etc/zipl.conf ]] && zipl_arg="--zipl"
grubby --args "$crashkernel_default" --update-kernel "$entry" $zipl_arg
[[ $zipl_arg ]] && zipl > /dev/null
fi
}
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
derror "Error: No kdump config file found!"
exit 1
@ -1366,8 +1400,11 @@ main ()
estimate)
do_estimate
;;
reset-crashkernel)
reset_crashkernel "$2"
;;
*)
dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|propagate|showmem}"
dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}"
exit 1
esac
}
@ -1377,6 +1414,6 @@ single_instance_lock
# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main.
# So that fd isn't leaking when main is invoking a subshell.
(exec 9<&-; main $1)
(exec 9<&-; main "$@")
exit $?

View File

@ -49,6 +49,15 @@ Prints the size of reserved memory for crash kernel in megabytes.
Estimate a suitable crashkernel value for current machine. This is a
best-effort estimate. It will print a recommanded crashkernel value
based on current kdump setup, and list some details of memory usage.
.TP
.I reset-crashkernel [KERNEL]
Reset crashkernel value to default value. kdumpctl will try to read
from /usr/lib/modules/<KERNEL>/crashkernel.default and reset specified
kernel's crashkernel cmdline value. If no kernel is
specified, will reset current running kernel's crashkernel value.
If /usr/lib/modules/<KERNEL>/crashkernel.default doesn't exist, will
simply exit return 1.
.SH "SEE ALSO"
.BR kdump.conf (5),