From a0fe51b32e5bf1a8c7b5e093683328f8b2f58d29 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 10 Jun 2021 13:06:22 +0800 Subject: [PATCH] kdumpctl: Add kdumpctl reset-crashkernel Resolves: bz1974638 Upstream: Fedora Conflict: None commit 86130ec10fda37cc283f717eaacb56a4cbf76418 Author: Kairui Song 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 Acked-by: Baoquan He Signed-off-by: Kairui Song --- kdumpctl | 41 +++++++++++++++++++++++++++++++++++++++-- kdumpctl.8 | 9 +++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index d24fe5f..fdd8d67 100755 --- a/kdumpctl +++ b/kdumpctl @@ -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 $? diff --git a/kdumpctl.8 b/kdumpctl.8 index a32a972..74be062 100644 --- a/kdumpctl.8 +++ b/kdumpctl.8 @@ -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//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//crashkernel.default doesn't exist, will +simply exit return 1. + .SH "SEE ALSO" .BR kdump.conf (5),