diff --git a/kdumpctl b/kdumpctl index e4334c5..c5b210c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1330,6 +1330,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 @@ -1388,8 +1422,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 } @@ -1399,6 +1436,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),