In RHEL, kernel supports a `crashkernel=auto` param and when it's used, kernel will use its built-in default value as the crashkernel value. But upstream doesn't like this idea. [1]
`crashkernel=auto` was introduced to provide user a default value, and make it possible to update the crashkernel value automatically as kernel package updates if user is using the default `auto` value.
After more discussion, `crashkernel=auto` will be dropped. To track the default crashkernel value, kernel package will include a crashkernel.default file with it[2], and kexec-tools can make use of that file, update kernel's boot cmdline accordingly, and help user to reset the crashkernel value to default value.
[1]: https://lore.kernel.org/linux-mm/20210507010432.IN24PudKT%25akpm@linux-found... [2]: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/1171
Update from V1: - Add support for ostree - Add a crashkernel-howto.txt - Change crashkernel.conf to crashkernel.default
Kairui Song (4): Revert "kdump-lib.sh: Remove is_atomic" kdumpctl: Add kdumpctl reset-crashkernel Add a new hook: 92-crashkernel.install Add a crashkernel-howto.conf doc
92-crashkernel.install | 131 +++++++++++++++++++++++++++++++++++++++++ crashkernel-howto.conf | 113 +++++++++++++++++++++++++++++++++++ kdump-lib.sh | 5 ++ kdumpctl | 41 ++++++++++++- kdumpctl.8 | 9 +++ kexec-tools.spec | 7 +++ 6 files changed, 304 insertions(+), 2 deletions(-) create mode 100755 92-crashkernel.install create mode 100644 crashkernel-howto.conf
Now we need this helper again, for `reset-crashkernel`
This reverts commit ff46cfb19e9bf944a114164e33203b1a532d35f6. --- kdump-lib.sh | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 8e618f8..df0aa02 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -341,6 +341,11 @@ kdump_get_persistent_dev() { echo $(get_persistent_dev "$dev") }
+is_atomic() +{ + grep -q "ostree" /proc/cmdline +} + is_ipv6_address() { echo $1 | grep -q ":"
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 --- kdumpctl | 41 +++++++++++++++++++++++++++++++++++++++-- kdumpctl.8 | 9 +++++++++ 2 files changed, 48 insertions(+), 2 deletions(-)
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/<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),
To track and manage kernel's crashkernel usage by kernel version, each kernel package will include a crashkernel.default containing the default `crashkernel=` value of that kernel. So we can use a hook to update the kernel cmdline of new installed kernel accordingly.
Put it after all other grub boot loader setup hooks, so it can simply call grubby to modify the kernel cmdline.
Signed-off-by: Kairui Song kasong@redhat.com --- 92-crashkernel.install | 131 +++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 4 ++ 2 files changed, 135 insertions(+) create mode 100755 92-crashkernel.install
diff --git a/92-crashkernel.install b/92-crashkernel.install new file mode 100755 index 0000000..2330344 --- /dev/null +++ b/92-crashkernel.install @@ -0,0 +1,131 @@ +#!/usr/bin/bash + +COMMAND="$1" +KERNEL_VERSION="$2" +KDUMP_INITRD_DIR_ABS="$3" +KERNEL_IMAGE="$4" + +grub_etc_default="/etc/default/grub" + +ver_lt() { + [[ "$(echo -e "$1\n$2" | sort -V)" == $1$'\n'* ]] && [[ $1 != "$2" ]] +} + +# Read crashkernel= value in /etc/default/grub +get_grub_default_ck() { + sed -n -e "s/^GRUB_CMDLINE_LINUX=.*(crashkernel=[^\ "]*)[\ "].*$/\1/p" $grub_etc_default +} + +# Read crashkernel.default value of specified kernel +get_ck_conf() { + ck_conf="/usr/lib/modules/$KERNEL_VERSION/crashkernel.default" + [[ -f "$ck_conf" ]] && cat "$ck_conf" +} + +# Get latest installed kernel that have a crashkernel.default, exclude current installing/removing kernel +# $1: If given, search for the kernel that have this value in crashkernel.default value +get_latest_ck_conf_kernel() { + for kernel in $(find /usr/lib/modules -maxdepth 1 -mindepth 1 -printf "%f\n" | sort --version-sort -r); do + [[ $kernel == "$KERNEL_VERSION" ]] && continue + [[ -f "/usr/lib/modules/$kernel/crashkernel.default" ]] || continue + + echo "$kernel" + return 0 + done + + return 1 +} + +update_grub_defaults() { + sed -i -e "s/^(GRUB_CMDLINE_LINUX=.*)crashkernel=[^\ "]*([\ "].*)$/\1$1\2/" "$grub_etc_default" +} + +# Update new installed kernel's crashkernel cmdline value, +# new installed kernel inherits boot kernel's cmdline by default, +update_new_kernel_ck() { + kernel=$KERNEL_VERSION + entry=$(grubby --info ALL | grep "^kernel=.*$kernel") + entry=${entry#kernel=} + entry=${entry#"} + entry=${entry%"} + + [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" + grubby --args "$new_ck_conf" --update-kernel "$entry" $zipl_arg + [[ $zipl_arg ]] && zipl > /dev/null +} + +case "$COMMAND" in +add) + # This install hook does following things: + # 1. Update new installed kernel's crashkernel value to its own default + # value, if current boot kernel is using default value. + # 2. Update /etc/default/grub's crashkernel value, if new installed + # kernel have a higher verison number and /etc/default/grub is using + # default value of latest installed kernel. + boot_kernel=$(uname -r) + boot_ck_cmdline=$(sed -n -e "s/^.*(crashkernel=\S*).*$/\1/p" /proc/cmdline) + new_ck_conf=$(get_ck_conf "$KERNEL_VERSION") + latest_ck_conf_kernel=$(get_latest_ck_conf_kernel) + latest_ck_conf=$(get_ck_conf "$latest_ck_conf_kernel") + + # If new installing kernel doesn't have a crashkernel.default, consider latest installed kernel's crashkernel.default as the default value. + new_ck_conf=${new_ck_conf:-$latest_ck_conf} + # If new installing kernel doesn't have a crashkernel.default, and none of installed kernel have one, nothing to do, just exit. + [[ -z "$new_ck_conf" ]] && exit 0 + + # If upgrading to a newer kernel, try update /etc/default/grub + # + # /etc/default/grub is only used by grub2-mkconfig and anaconda. + # When user trigger grub2-mkconfig, crashkernel value will be + # override with this config file. + # + # Only update it if it's default value or `auto`. + if [[ -e "$grub_etc_default" ]]; then + grub_etc_ck=$(get_grub_default_ck) + if [[ -z "$latest_ck_conf_kernel" ]] || ver_lt "$latest_ck_conf_kernel" "$KERNEL_VERSION"; then + if [[ "$grub_etc_ck" == "$latest_ck_conf" ]] || [[ "$grub_etc_ck" == "crashkernel=auto" ]]; then + [[ "$grub_etc_ck" != "$new_ck_conf" ]] && update_grub_defaults "$new_ck_conf" + fi + fi + fi + + # If crashkernel is not used in current cmdline, just exit + [[ -z "$boot_ck_cmdline" ]] && exit 0 + + # Get boot kernel's default value + boot_ck_conf=$(get_ck_conf "$boot_kernel") + # For legacy RHEL kernel + if [[ $boot_ck_cmdline == "crashkernel=auto" ]]; then + boot_ck_conf="$boot_ck_cmdline" + fi + + # If boot kernel doesn't have a crashkernel.default, check if it's using a previous kernel's crashkernel.default + if [[ -z "$boot_ck_conf" ]]; then + if [[ "$boot_ck_cmdline" != "$latest_ck_conf" ]]; then + boot_ck_conf=$(get_latest_ck_conf_kernel "$boot_ck_cmdline") + fi + fi + + # If boot kernel is using default crashkernel, new installed kernel also follow default value + if [[ "$boot_ck_cmdline" != "$new_ck_conf" ]] && [[ "$boot_ck_cmdline" == "$boot_ck_conf" ]]; then + update_new_kernel_ck "$new_ck_conf" + fi + + ;; +remove) + # If grub default value is upgraded when this kernel was installed, try downgrade it + [[ -e "$grub_etc_default" ]] || exit 0 + grub_etc_ck=$(get_grub_default_ck) + removing_ck_conf=$(get_ck_conf "$KERNEL_VERSION") + latest_ck_conf_kernel=$(get_latest_ck_conf_kernel) || exit 0 + latest_ck_conf=$(get_ck_conf "$latest_ck_conf_kernel") + + [[ "$latest_ck_conf" ]] || exit 0 + + if ver_lt "$latest_ck_conf_kernel" "$KERNEL_VERSION"; then + if [[ $grub_etc_ck == "$removing_ck_conf" ]] && [[ $grub_etc_ck != "$latest_ck_conf" ]]; then + update_grub_defaults "$latest_ck_conf" + fi + fi + ;; +esac diff --git a/kexec-tools.spec b/kexec-tools.spec index 8fed959..ec327da 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -40,6 +40,7 @@ Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd +Source33: 92-crashkernel.install
####################################### # These are sources for mkdumpramfs @@ -66,6 +67,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool +Requires: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext @@ -210,6 +212,7 @@ install -m 644 %{SOURCE15} $RPM_BUILD_ROOT%{_mandir}/man5/kdump.conf.5 install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install +install -m 755 -D %{SOURCE32} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install
%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile @@ -360,6 +363,7 @@ done %{_unitdir}/kdump.service %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install +%{_prefix}/lib/kernel/install.d/92-crashkernel.install %doc News %license COPYING %doc TODO
On 06/30/21 at 02:43pm, Kairui Song wrote:
To track and manage kernel's crashkernel usage by kernel version, each kernel package will include a crashkernel.default containing the default `crashkernel=` value of that kernel. So we can use a hook to update the kernel cmdline of new installed kernel accordingly.
Put it after all other grub boot loader setup hooks, so it can simply call grubby to modify the kernel cmdline.
Signed-off-by: Kairui Song kasong@redhat.com
92-crashkernel.install | 131 +++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 4 ++ 2 files changed, 135 insertions(+) create mode 100755 92-crashkernel.install
diff --git a/92-crashkernel.install b/92-crashkernel.install new file mode 100755 index 0000000..2330344 --- /dev/null +++ b/92-crashkernel.install @@ -0,0 +1,131 @@ +#!/usr/bin/bash
+COMMAND="$1" +KERNEL_VERSION="$2" +KDUMP_INITRD_DIR_ABS="$3" +KERNEL_IMAGE="$4"
+grub_etc_default="/etc/default/grub"
+ver_lt() {
- [[ "$(echo -e "$1\n$2" | sort -V)" == $1$'\n'* ]] && [[ $1 != "$2" ]]
+}
+# Read crashkernel= value in /etc/default/grub +get_grub_default_ck() {
- sed -n -e "s/^GRUB_CMDLINE_LINUX=.*(crashkernel=[^\ "]*)[\ "].*$/\1/p" $grub_etc_default
+}
+# Read crashkernel.default value of specified kernel +get_ck_conf() {
- ck_conf="/usr/lib/modules/$KERNEL_VERSION/crashkernel.default"
- [[ -f "$ck_conf" ]] && cat "$ck_conf"
+}
+# Get latest installed kernel that have a crashkernel.default, exclude current installing/removing kernel +# $1: If given, search for the kernel that have this value in crashkernel.default value
I guess you are saying the kernel which version is highest and owns a crashkernel.default, but not the latest on installing time.
Don't get what the given value is used for and its description.
+get_latest_ck_conf_kernel() {
- for kernel in $(find /usr/lib/modules -maxdepth 1 -mindepth 1 -printf "%f\n" | sort --version-sort -r); do
[[ $kernel == "$KERNEL_VERSION" ]] && continue
[[ -f "/usr/lib/modules/$kernel/crashkernel.default" ]] || continue
echo "$kernel"
return 0
- done
- return 1
+}
+update_grub_defaults() {
- sed -i -e "s/^(GRUB_CMDLINE_LINUX=.*)crashkernel=[^\ "]*([\ "].*)$/\1$1\2/" "$grub_etc_default"
+}
+# Update new installed kernel's crashkernel cmdline value,
These 'new installed kernel', 'new installing kernel', 'latest installed kernel' are too messy. We may need clean up them to unified the represented stuff.
+# new installed kernel inherits boot kernel's cmdline by default, +update_new_kernel_ck() {
- kernel=$KERNEL_VERSION
- entry=$(grubby --info ALL | grep "^kernel=.*$kernel")
- entry=${entry#kernel=}
- entry=${entry#"}
- entry=${entry%"}
- [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl"
- grubby --args "$new_ck_conf" --update-kernel "$entry" $zipl_arg
- [[ $zipl_arg ]] && zipl > /dev/null
+}
+case "$COMMAND" in +add)
- # This install hook does following things:
- # 1. Update new installed kernel's crashkernel value to its own default
- # value, if current boot kernel is using default value.
- # 2. Update /etc/default/grub's crashkernel value, if new installed
- # kernel have a higher verison number and /etc/default/grub is using
- # default value of latest installed kernel.
- boot_kernel=$(uname -r)
- boot_ck_cmdline=$(sed -n -e "s/^.*(crashkernel=\S*).*$/\1/p" /proc/cmdline)
- new_ck_conf=$(get_ck_conf "$KERNEL_VERSION")
- latest_ck_conf_kernel=$(get_latest_ck_conf_kernel)
- latest_ck_conf=$(get_ck_conf "$latest_ck_conf_kernel")
- # If new installing kernel doesn't have a crashkernel.default, consider latest installed kernel's crashkernel.default as the default value.
- new_ck_conf=${new_ck_conf:-$latest_ck_conf}
- # If new installing kernel doesn't have a crashkernel.default, and none of installed kernel have one, nothing to do, just exit.
- [[ -z "$new_ck_conf" ]] && exit 0
- # If upgrading to a newer kernel, try update /etc/default/grub
- #
- # /etc/default/grub is only used by grub2-mkconfig and anaconda.
- # When user trigger grub2-mkconfig, crashkernel value will be
- # override with this config file.
- #
- # Only update it if it's default value or `auto`.
- if [[ -e "$grub_etc_default" ]]; then
grub_etc_ck=$(get_grub_default_ck)
if [[ -z "$latest_ck_conf_kernel" ]] || ver_lt "$latest_ck_conf_kernel" "$KERNEL_VERSION"; then
if [[ "$grub_etc_ck" == "$latest_ck_conf" ]] || [[ "$grub_etc_ck" == "crashkernel=auto" ]]; then
[[ "$grub_etc_ck" != "$new_ck_conf" ]] && update_grub_defaults "$new_ck_conf"
fi
fi
- fi
- # If crashkernel is not used in current cmdline, just exit
- [[ -z "$boot_ck_cmdline" ]] && exit 0
- # Get boot kernel's default value
- boot_ck_conf=$(get_ck_conf "$boot_kernel")
- # For legacy RHEL kernel
- if [[ $boot_ck_cmdline == "crashkernel=auto" ]]; then
boot_ck_conf="$boot_ck_cmdline"
- fi
- # If boot kernel doesn't have a crashkernel.default, check if it's using a previous kernel's crashkernel.default
- if [[ -z "$boot_ck_conf" ]]; then
if [[ "$boot_ck_cmdline" != "$latest_ck_conf" ]]; then
boot_ck_conf=$(get_latest_ck_conf_kernel "$boot_ck_cmdline")
fi
- fi
- # If boot kernel is using default crashkernel, new installed kernel also follow default value
- if [[ "$boot_ck_cmdline" != "$new_ck_conf" ]] && [[ "$boot_ck_cmdline" == "$boot_ck_conf" ]]; then
update_new_kernel_ck "$new_ck_conf"
- fi
- ;;
+remove)
- # If grub default value is upgraded when this kernel was installed, try downgrade it
- [[ -e "$grub_etc_default" ]] || exit 0
- grub_etc_ck=$(get_grub_default_ck)
- removing_ck_conf=$(get_ck_conf "$KERNEL_VERSION")
- latest_ck_conf_kernel=$(get_latest_ck_conf_kernel) || exit 0
- latest_ck_conf=$(get_ck_conf "$latest_ck_conf_kernel")
- [[ "$latest_ck_conf" ]] || exit 0
- if ver_lt "$latest_ck_conf_kernel" "$KERNEL_VERSION"; then
if [[ $grub_etc_ck == "$removing_ck_conf" ]] && [[ $grub_etc_ck != "$latest_ck_conf" ]]; then
update_grub_defaults "$latest_ck_conf"
fi
- fi
- ;;
+esac diff --git a/kexec-tools.spec b/kexec-tools.spec index 8fed959..ec327da 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -40,6 +40,7 @@ Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd +Source33: 92-crashkernel.install
####################################### # These are sources for mkdumpramfs @@ -66,6 +67,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool +Requires: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext @@ -210,6 +212,7 @@ install -m 644 %{SOURCE15} $RPM_BUILD_ROOT%{_mandir}/man5/kdump.conf.5 install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install +install -m 755 -D %{SOURCE32} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install
%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile @@ -360,6 +363,7 @@ done %{_unitdir}/kdump.service %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install +%{_prefix}/lib/kernel/install.d/92-crashkernel.install %doc News %license COPYING %doc TODO -- 2.31.1
Signed-off-by: Kairui Song kasong@redhat.com --- crashkernel-howto.conf | 113 +++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 3 ++ 2 files changed, 116 insertions(+) create mode 100644 crashkernel-howto.conf
diff --git a/crashkernel-howto.conf b/crashkernel-howto.conf new file mode 100644 index 0000000..13e6602 --- /dev/null +++ b/crashkernel-howto.conf @@ -0,0 +1,113 @@ +Introduction +------------ + +This document describes utils kexec-tools package provides for setting and +estimating the crashkernel value. + +Kdump lives in a pre-reserved chunk of memory, and the size of the reserved +memory is specified by the `crashkernel=` kernel parameter. It's hard to +estimate an accurate `crashkernel=` value, so it's always recommended to +test kdump after you updated the `crashkernel=` value or changed the dump +target. + + +crashkernel=auto +---------------- + +Legacy RHEL kernels support a `crashkernel=auto` parameter. When +it's specified, the kernel simply uses a pre-defined default `crashkernel=` +(eg. crashekrnel=1G-4G:192M,4G-64G:256M,64G-:512M) as the cmdline. + +Latest kernel pacakge have dropped this parameter, and a default +`crashkernel.default` file is included and installed in kernel +modules folder, available as: + + /usr/lib/modules/<kernel>/crashkernel.default + +You can use the content of this file as the default value for +`crashkernel=`, or take this file as a reference for setting the +crashkernel value. + +To make it easier to reset the `crashkernel=` kernel cmdline to this +default value properly, `kdumpctl` also provides a sub-command: + + `kdumpctl reset-crashkernel [<kernel release>]` + +This command will read from the `crashkernel.default` file and reset +bootloader's kernel cmdline to the default value. It will also update +bootloader config if the bootloader have a standalone config file. + + +New installed system +-------------------- + +If you enabled kdump in Anaconda and chosen automatic memory reserve, +Anaconda will execute similar logic with `kdumpctl reset-crashkernel`. +Kernel's `crashkernel=` value will be set to the default value from +`crashkernel.default`. + + +Installing a new kernel +----------------------- + +When a new kernel package is installed, by default, it will inherit current +boot kernel's cmdline. But kexec-tools will install extra kernel hooks +to update `crashkernel=` value when needed. + +If current kernel have a `crashkernel.default` file, and it's using this +default value, kexec-tools will keep the new installed kernel's +`crashkernel=` synchronized with new installed `crashkernel.default` file. + +If new kernel doesn't have a `crashkernel.default` file (eg. installing a +self-compiled kernel), kexec-tools won't do anything, old `crashkernel=` +value will be inherited. + +If the current boot kernel don't have a `crashkernel.default` file, +kexec-tools will iterate through installed kernels, look for a valid +`crashkernel.default` and find out if current boot kernel just inherited +the default value from a previously installed kernel. If that's the case, +it will also perform the `crashkernel=` value synchronization. + +If kexec-tools package is absent, new installed kernel's `crashkernel=` +value will not get updated. And later even if kexec-tools is installed +back it might not be able to update the `crashkernel=` value since the +current `crashkernel=` value may out of sync with the latest default value. +So it's recommended to run `kdumpctl reset-crashkernel` if you have +uninstalled kexec-tools and installed it back later. + + +Estimate crashkernel +-------------------- + +The best way to estimate a usable crashkernel value is by testing kdump +manually. And you can set crashkernel to a large value, then adjust the +crashkernel value to an acceptable value gradually. + +`kdumpctl` also provides a sub-command for doing rough estimating without +triggering kdump: + + `kdumpctl estimate` + + +The output will be like this: + +``` + Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement + + Reserved crashkernel: 256M + Recommended crashkernel: 655M + + Kernel image size: 47M + Kernel modules size: 12M + Initramfs size: 19M + Runtime reservation: 64M + LUKS required size: 512M + Large modules: + xfs: 1892352 + nouveau: 2318336 + WARNING: Current crashkernel size is lower than recommended size 655M. +``` + +It will generate a summary report about the estimated memory consumption +of each component of kdump. The value may not be accurate enough, but +would be a good start for finding a suitable crashkernel value. diff --git a/kexec-tools.spec b/kexec-tools.spec index ec327da..deedcf1 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -41,6 +41,7 @@ Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd Source33: 92-crashkernel.install +Source34: crashkernel-howto.txt
####################################### # These are sources for mkdumpramfs @@ -151,6 +152,7 @@ cp %{SOURCE11} . cp %{SOURCE21} . cp %{SOURCE26} . cp %{SOURCE27} . +cp %{SOURCE34} .
make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 @@ -372,6 +374,7 @@ done %doc fadump-howto.txt %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt +%doc crashkernel-howto.txt %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{_libdir}/eppic_makedumpfile.so /usr/share/makedumpfile/
On 06/30/21 at 02:43pm, Kairui Song wrote:
Signed-off-by: Kairui Song kasong@redhat.com
crashkernel-howto.conf | 113 +++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 3 ++ 2 files changed, 116 insertions(+) create mode 100644 crashkernel-howto.conf
diff --git a/crashkernel-howto.conf b/crashkernel-howto.conf new file mode 100644 index 0000000..13e6602 --- /dev/null +++ b/crashkernel-howto.conf @@ -0,0 +1,113 @@ +Introduction +------------
+This document describes utils kexec-tools package provides for setting and +estimating the crashkernel value.
+Kdump lives in a pre-reserved chunk of memory, and the size of the reserved +memory is specified by the `crashkernel=` kernel parameter. It's hard to +estimate an accurate `crashkernel=` value, so it's always recommended to +test kdump after you updated the `crashkernel=` value or changed the dump +target.
+crashkernel=auto
Not sure if we need mention an never existed kernel cmdline in rhel9 for rhel9. We can change it to "crashkernel default value"?
+----------------
+Legacy RHEL kernels support a `crashkernel=auto` parameter. When +it's specified, the kernel simply uses a pre-defined default `crashkernel=` +(eg. crashekrnel=1G-4G:192M,4G-64G:256M,64G-:512M) as the cmdline.
+Latest kernel pacakge have dropped this parameter, and a default +`crashkernel.default` file is included and installed in kernel +modules folder, available as:
- /usr/lib/modules/<kernel>/crashkernel.default
+You can use the content of this file as the default value for +`crashkernel=`, or take this file as a reference for setting the +crashkernel value.
The content of the file will be taken as the default value of 'crashkernel=', or take this file as a reference for setting crashkernel value manually.
+To make it easier to reset the `crashkernel=` kernel cmdline to this +default value properly, `kdumpctl` also provides a sub-command:
- `kdumpctl reset-crashkernel [<kernel release>]`
+This command will read from the `crashkernel.default` file and reset +bootloader's kernel cmdline to the default value. It will also update +bootloader config if the bootloader have a standalone config file.
+New installed system +--------------------
+If you enabled kdump in Anaconda and chosen automatic memory reserve, +Anaconda will execute similar logic with `kdumpctl reset-crashkernel`. +Kernel's `crashkernel=` value will be set to the default value from +`crashkernel.default`.
Anaconda is the absolute start of kernel, we may need to mention it earlier. Then we say resetting crashkernel, or manually change it. the log will be better.
+Installing a new kernel +-----------------------
+When a new kernel package is installed, by default, it will inherit current +boot kernel's cmdline. But kexec-tools will install extra kernel hooks +to update `crashkernel=` value when needed.
+If current kernel have a `crashkernel.default` file, and it's using this +default value, kexec-tools will keep the new installed kernel's +`crashkernel=` synchronized with new installed `crashkernel.default` file.
Don't get it. the synchronized means whose content is synchronized to whose content.
+If new kernel doesn't have a `crashkernel.default` file (eg. installing a +self-compiled kernel), kexec-tools won't do anything, old `crashkernel=` +value will be inherited.
+If the current boot kernel don't have a `crashkernel.default` file,
~doesn't
+kexec-tools will iterate through installed kernels, look for a valid +`crashkernel.default` and find out if current boot kernel just inherited +the default value from a previously installed kernel. If that's the case, +it will also perform the `crashkernel=` value synchronization.
How to synchronize?
+If kexec-tools package is absent, new installed kernel's `crashkernel=` +value will not get updated. And later even if kexec-tools is installed +back it might not be able to update the `crashkernel=` value since the +current `crashkernel=` value may out of sync with the latest default value. +So it's recommended to run `kdumpctl reset-crashkernel` if you have +uninstalled kexec-tools and installed it back later.
+Estimate crashkernel +--------------------
+The best way to estimate a usable crashkernel value is by testing kdump
~~~~~~ is testing kdump
+manually. And you can set crashkernel to a large value, then adjust the
~~ we can only shrink,
+crashkernel value to an acceptable value gradually.
+`kdumpctl` also provides a sub-command for doing rough estimating without +triggering kdump:
- `kdumpctl estimate`
+The output will be like this:
+```
Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement
Reserved crashkernel: 256M
Recommended crashkernel: 655M
Kernel image size: 47M
Kernel modules size: 12M
Initramfs size: 19M
Runtime reservation: 64M
LUKS required size: 512M
Large modules:
xfs: 1892352
nouveau: 2318336
WARNING: Current crashkernel size is lower than recommended size 655M.
+```
+It will generate a summary report about the estimated memory consumption +of each component of kdump. The value may not be accurate enough, but +would be a good start for finding a suitable crashkernel value. diff --git a/kexec-tools.spec b/kexec-tools.spec index ec327da..deedcf1 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -41,6 +41,7 @@ Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd Source33: 92-crashkernel.install +Source34: crashkernel-howto.txt
####################################### # These are sources for mkdumpramfs @@ -151,6 +152,7 @@ cp %{SOURCE11} . cp %{SOURCE21} . cp %{SOURCE26} . cp %{SOURCE27} . +cp %{SOURCE34} .
make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 @@ -372,6 +374,7 @@ done %doc fadump-howto.txt %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt +%doc crashkernel-howto.txt %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{_libdir}/eppic_makedumpfile.so /usr/share/makedumpfile/ -- 2.31.1