From abfe792fa1dc4a0f1bbbd14ba1d73cbe69519c00 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 01:56:32 +0900 Subject: [PATCH 1/9] kdump.sh: Execute executables for kdump_emergency and emergency.d during error handling Update kdump.sh to execute binary and script files located under /etc/kdump/emergency.d and the file specified by kdump_emergency option when the error handler is invoked in emergency mode. Running these files during error handling ensures that emergency-specific actions and configuration are applied even when kdump encounters failures prior to dump process. This allows administrators to define custom recovery or logging behavior in error scenarios. Signed-off-by: Mamoru Nishibe --- dracut/99kdumpbase/kdump.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dracut/99kdumpbase/kdump.sh b/dracut/99kdumpbase/kdump.sh index 5155453c..3e6baf74 100755 --- a/dracut/99kdumpbase/kdump.sh +++ b/dracut/99kdumpbase/kdump.sh @@ -33,6 +33,7 @@ DD_BLKSIZE=512 FINAL_ACTION="systemctl reboot -f" KDUMP_PRE="" KDUMP_POST="" +KDUMP_EMERGENCY="" NEWROOT="/sysroot" OPALCORE="/sys/firmware/opal/mpipl/core" KDUMP_CONF_PARSED="/tmp/kdump.conf.$$" @@ -66,6 +67,9 @@ get_kdump_confs() { kdump_post) KDUMP_POST="$config_val" ;; + kdump_emergency) + KDUMP_EMERGENCY="$config_val" + ;; fence_kdump_args) FENCE_KDUMP_ARGS="$config_val" ;; @@ -374,6 +378,25 @@ do_kdump_post() { fi } +do_kdump_emergency() { + if [ -d /etc/kdump/emergency.d ]; then + for file in /etc/kdump/emergency.d/*; do + "$file" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$file exited with $_ret status" + fi + done + fi + + if [ -n "$KDUMP_EMERGENCY" ]; then + "$KDUMP_EMERGENCY" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$KDUMP_EMERGENCY exited with $_ret status" + fi + fi +} # $1: block target, eg. /dev/sda dump_raw() { [ -b "$1" ] || return 1 @@ -641,6 +664,7 @@ kdump_test_init() { if [ "$1" = "--error-handler" ]; then get_kdump_confs + do_kdump_emergency do_failure_action save_log do_final_action From 88c7b769b56a3e69adada458b90f541edb3e84c4 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 01:57:22 +0900 Subject: [PATCH 2/9] module-setup.sh: Include files for kdump_emergency and emergency.d into kdump initramfs Includes files installed under /etc/kdump/emergency.d directory and the file specified by kdump_emergency option into kdump initramfs. Signed-off-by: Mamoru Nishibe --- dracut/99kdumpbase/module-setup.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dracut/99kdumpbase/module-setup.sh b/dracut/99kdumpbase/module-setup.sh index 5a580ce0..f0526219 100755 --- a/dracut/99kdumpbase/module-setup.sh +++ b/dracut/99kdumpbase/module-setup.sh @@ -660,7 +660,7 @@ kdump_install_net() { fi } -# install etc/kdump/pre.d and /etc/kdump/post.d +# install etc/kdump/pre.d and /etc/kdump/post.d /etc/kdump/emergency.d kdump_install_pre_post_conf() { if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do @@ -681,6 +681,16 @@ kdump_install_pre_post_conf() { fi done fi + + if [[ -d /etc/kdump/emergency.d ]]; then + for file in /etc/kdump/emergency.d/*; do + if [[ -x $file ]]; then + dracut_install "$file" + elif [[ $file != "/etc/kdump/emergency.d/*" ]]; then + echo "$file is not executable" + fi + done + fi } default_dump_target_install_conf() { @@ -743,7 +753,7 @@ kdump_install_conf() { kdump_collect_netif_usage "$(get_dracut_args_target "$_val")" fi ;; - kdump_pre | kdump_post | extra_bins) + kdump_pre | kdump_post | kdump_emergency | extra_bins) # shellcheck disable=SC2086 dracut_install $_val ;; From f0add698ad035a5083e591b176c7d2ab98526210 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:29:28 +0900 Subject: [PATCH 3/9] kdumpctl: Add support for kdump_emergency option to kdump.conf parser Add support for kdump_emergency option to kdump.conf parser. This allows the parser to recognize the option as valid. Signed-off-by: Mamoru Nishibe --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index dd617f60..5f524b9b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -368,7 +368,7 @@ parse_config() dwarn "Please update $KDUMP_CONFIG_FILE to use option 'failure_action' instead." _set_config failure_action "$config_val" || return 1 ;; - path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; + path | core_collector | kdump_post | kdump_pre | kdump_emergency | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." From 633cb23f287c69cccabdd5ccdfc6e9e053c5b47a Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:35:52 +0900 Subject: [PATCH 4/9] kdumpctl: Clean up handling of EXTRA_BINS, CHECK_FILES and HOOKS Consolidate EXTRA_BINS assignments into a single location and remove the CHECK_FILES variable. And also remove the directories from the HOOKS. No functional change. Signed-off-by: Mamoru Nishibe --- kdumpctl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kdumpctl b/kdumpctl index 5f524b9b..b7f16e73 100755 --- a/kdumpctl +++ b/kdumpctl @@ -461,9 +461,6 @@ check_files_modified() #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files "$image_time") - EXTRA_BINS=${OPT[kdump_post]} - CHECK_FILES=${OPT[kdump_pre]} - HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do if [[ -x $file ]]; then @@ -478,13 +475,11 @@ check_files_modified() fi done fi - HOOKS="$HOOKS $POST_FILES $PRE_FILES" + HOOKS="$POST_FILES $PRE_FILES" CORE_COLLECTOR=$(echo "${OPT[core_collector]}" | awk '{print $1}') CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR") # POST_FILES and PRE_FILES are already checked against executable, need not to check again. - EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" - CHECK_FILES=${OPT[extra_bins]} - EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" + EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[extra_bins]}" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" [[ -e /etc/fstab ]] && files="$files /etc/fstab" From 777dc9587fd33ee10ffe9891136bf7a57cf78636 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:43:39 +0900 Subject: [PATCH 5/9] kdumpctl: Add update checks for kdump_emergency and emergency.d Add update checks for binary and script files located under /etc/kdump/emergency.d directory, and for the file specified by kdump_emergency option. Signed-off-by: Mamoru Nishibe --- kdumpctl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index b7f16e73..bbe3db54 100755 --- a/kdumpctl +++ b/kdumpctl @@ -475,11 +475,18 @@ check_files_modified() fi done fi - HOOKS="$POST_FILES $PRE_FILES" + if [[ -d /etc/kdump/emergency.d ]]; then + for file in /etc/kdump/emergency.d/*; do + if [[ -x $file ]]; then + EMERGENCY_FILES="$EMERGENCY_FILES $file" + fi + done + fi + HOOKS="$POST_FILES $PRE_FILES $EMERGENCY_FILES" CORE_COLLECTOR=$(echo "${OPT[core_collector]}" | awk '{print $1}') CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR") # POST_FILES and PRE_FILES are already checked against executable, need not to check again. - EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[extra_bins]}" + EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[kdump_emergency]} ${OPT[extra_bins]}" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" [[ -e /etc/fstab ]] && files="$files /etc/fstab" From 5989c82f571e5700f148a279b51512e3928fd500 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:46:17 +0900 Subject: [PATCH 6/9] doc/kdump.conf: Add descriptions of the kdump_emergency option This patch adds descriptions of the kdump_emergency option to the documentation. Signed-off-by: Mamoru Nishibe --- gen-kdump-conf.sh | 8 ++++++++ kdump.conf.5 | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gen-kdump-conf.sh b/gen-kdump-conf.sh index 6581eb55..94159cc0 100755 --- a/gen-kdump-conf.sh +++ b/gen-kdump-conf.sh @@ -90,6 +90,14 @@ generate() # For core_collector format details, you can refer to # kexec-kdump-howto.txt or kdump.conf manpage. # +# kdump_emergency +# - This directive allows you to run a specified executable +# in emergency mode within the kdump capture kernel, +# prior to the dump process. +# All files under /etc/kdump/emergency.d are collectively sorted +# and executed in lexical order, before binary or script +# specified kdump_emergency parameter is executed. +# # kdump_post # - This directive allows you to run a executable binary # or script after the vmcore dump process terminates. diff --git a/kdump.conf.5 b/kdump.conf.5 index 6b4e1815..8cf734a7 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -130,6 +130,23 @@ than the system's RAM. .RE +.B kdump_emergency +.RS +This directive allows you to run a specified executable +in emergency mode within the kdump capture kernel, +prior to the dump process. +.PP +All files under /etc/kdump/emergency.d are collectively sorted +and executed in lexical order, before binary or script +specified kdump_emergency parameter is executed. +.PP +Note that scripts written for use with this directive must use the /bin/bash +interpreter. And since these scripts run in kdump enviroment, the reference to +the storage or network device in the scripts should adhere to the section +'Supported dump target types and requirements' in kexec-kdump-howto.txt. + +.RE + .B kdump_post .RS This directive allows you to run a specified executable From 7032bc3413877964da96207f772224d78d8915d2 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:47:14 +0900 Subject: [PATCH 7/9] kexec-kdump-howto.txt: Fix typo in Kdump Post-Capture Executable Replace "All" with "all" to correct grammar. Signed-off-by: Mamoru Nishibe --- kexec-kdump-howto.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 5d205a5c..2f21d9c3 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -625,7 +625,7 @@ It is possible to specify a custom script or binary you wish to run following an attempt to capture a vmcore. The executable is passed an exit code from the capture process, which can be used to trigger different actions from within your post-capture executable. -If /etc/kdump/post.d directory exist, All files in the directory are +If /etc/kdump/post.d directory exist, all files in the directory are collectively sorted and executed in lexical order, before binary or script specified kdump_post parameter is executed. From c1d601bbae0344215e02add5e65a950497a6b1b5 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:47:45 +0900 Subject: [PATCH 8/9] kexec-kdump-howto.txt: Add description of Kdump Emergency Executable Add a description of the Kdump Emergency Executable to kexec-kdump-howto.txt. This documentation explains the purpose of the Kdump Emergency Executable. Signed-off-by: Mamoru Nishibe --- kexec-kdump-howto.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 2f21d9c3..628b7c94 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -618,6 +618,20 @@ level in the above KDUMP_COMMANDLINE_APPEND. Logging levels: no logging(0), error(1), warn(2), info(3), debug(4) +Kdump Emergency Executable +-------------------------- + +It is possible to specify a custom script or binary you wish to run in +emergency mode prior to the dump process. From the error handler launched +in emergency mode within the kdump capture kernel, you can trigger different +actions from within your specified executables. +If /etc/kdump/emergency.d directory exist, all files in the directory are +collectively sorted and executed in lexical order, before binary or script +specified using kdump_emergency option is executed. + +In these scripts, the reference to the storage or network device should adhere +to the section 'Supported dump target types and requirements' + Kdump Post-Capture Executable ----------------------------- From e71635ff471aee1f7491a77c3bfa39d9a211ba25 Mon Sep 17 00:00:00 2001 From: Mamoru Nishibe Date: Fri, 23 Jan 2026 02:49:05 +0900 Subject: [PATCH 9/9] spec: Add setup logic for emergency.d Add setup logic to ensure that the kdump/emergency.d directory is properly created and prepared. Signed-off-by: Mamoru Nishibe --- Makefile | 1 + kdump-utils.spec | 1 + 2 files changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 56e019c7..dcf3e69b 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ install: dracut-modules kdump-conf kdump-sysconfig manpages mkdir -p $(DESTDIR)$(pkglibdir)/dracut.conf.d mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/pre.d mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/post.d + mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/emergency.d mkdir -p -m755 $(DESTDIR)$(localstatedir)/crash mkdir -p -m755 $(DESTDIR)$(udevrulesdir) mkdir -p -m755 $(DESTDIR)$(sharedstatedir)/kdump diff --git a/kdump-utils.spec b/kdump-utils.spec index 2bfb2171..41a3939d 100644 --- a/kdump-utils.spec +++ b/kdump-utils.spec @@ -102,6 +102,7 @@ fi %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d +%dir %{_sysconfdir}/kdump/emergency.d %dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8* %{_mandir}/man8/mkdumprd.8*