diff --git a/SOURCES/dracut-early-kdump.sh b/SOURCES/dracut-early-kdump.sh index 69a34eb..6788a6b 100755 --- a/SOURCES/dracut-early-kdump.sh +++ b/SOURCES/dracut-early-kdump.sh @@ -2,6 +2,7 @@ KEXEC=/sbin/kexec standard_kexec_args="-p" +KDUMP_FILE_LOAD="" EARLY_KDUMP_INITRD="" EARLY_KDUMP_KERNEL="" @@ -43,8 +44,8 @@ early_kdump_load() EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") - if is_secure_boot_enforced; then - echo "Secure Boot is enabled. Using kexec file based syscall." + if [ "$KDUMP_FILE_LOAD" == "on" ]; then + echo "Using kexec file based syscall." EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s" fi diff --git a/SOURCES/dracut-kdump.sh b/SOURCES/dracut-kdump.sh index 8752178..b71278d 100755 --- a/SOURCES/dracut-kdump.sh +++ b/SOURCES/dracut-kdump.sh @@ -30,15 +30,49 @@ do_dump() do_kdump_pre() { + local _ret + if [ -n "$KDUMP_PRE" ]; then "$KDUMP_PRE" + _ret=$? + if [ $_ret -ne 0 ]; then + echo "kdump: $KDUMP_PRE exited with $_ret status" + return $_ret + fi fi + + if [ -d /etc/kdump/pre.d ]; then + for file in /etc/kdump/pre.d/*; do + "$file" + _ret=$? + if [ $_ret -ne 0 ]; then + echo "kdump: $file exited with $_ret status" + fi + done + fi + return 0 } do_kdump_post() { + local _ret + + if [ -d /etc/kdump/post.d ]; then + for file in /etc/kdump/post.d/*; do + "$file" "$1" + _ret=$? + if [ $_ret -ne 0 ]; then + echo "kdump: $file exited with $_ret status" + fi + done + fi + if [ -n "$KDUMP_POST" ]; then "$KDUMP_POST" "$1" + _ret=$? + if [ $_ret -ne 0 ]; then + echo "kdump: $KDUMP_POST exited with $_ret status" + fi fi } @@ -174,7 +208,10 @@ read_kdump_conf() case "$config_opt" in dracut_args) config_val=$(get_dracut_args_target "$config_val") - [ -n "$config_val" ] && add_dump_code "dump_fs $config_val" + if [ -n "$config_val" ]; then + config_val=$(get_mntpoint_from_target "$config_val") + add_dump_code "dump_fs $config_val" + fi ;; ext[234]|xfs|btrfs|minix|nfs) config_val=$(get_mntpoint_from_target "$config_val") diff --git a/SOURCES/dracut-module-setup.sh b/SOURCES/dracut-module-setup.sh index 7e1ac0b..596ee57 100755 --- a/SOURCES/dracut-module-setup.sh +++ b/SOURCES/dracut-module-setup.sh @@ -48,20 +48,6 @@ depends() { return 0 } -kdump_get_persistent_dev() { - local dev="${1//\"/}" - - case "$dev" in - UUID=*) - dev=`blkid -U "${dev#UUID=}"` - ;; - LABEL=*) - dev=`blkid -L "${dev#LABEL=}"` - ;; - esac - echo $(get_persistent_dev "$dev") -} - kdump_is_bridge() { [ -d /sys/class/net/"$1"/bridge ] } @@ -388,6 +374,29 @@ kdump_install_net() { fi } +# install etc/kdump/pre.d and /etc/kdump/post.d +kdump_install_pre_post_conf() { + if [ -d /etc/kdump/pre.d ]; then + for file in /etc/kdump/pre.d/*; do + if [ -x "$file" ]; then + dracut_install $file + else + echo "$file is not executable" + fi + done + fi + + if [ -d /etc/kdump/post.d ]; then + for file in /etc/kdump/post.d/*; do + if [ -x "$file" ]; then + dracut_install $file + else + echo "$file is not executable" + fi + done + fi +} + default_dump_target_install_conf() { local _target _fstype @@ -453,6 +462,8 @@ kdump_install_conf() { esac done <<< "$(read_strip_comments /etc/kdump.conf)" + kdump_install_pre_post_conf + default_dump_target_install_conf kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" diff --git a/SOURCES/kdump-lib.sh b/SOURCES/kdump-lib.sh index 83d7779..c88c3f5 100755 --- a/SOURCES/kdump-lib.sh +++ b/SOURCES/kdump-lib.sh @@ -295,6 +295,20 @@ get_option_value() { strip_comments `grep "^$1[[:space:]]\+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` } +kdump_get_persistent_dev() { + local dev="${1//\"/}" + + case "$dev" in + UUID=*) + dev=`blkid -U "${dev#UUID=}"` + ;; + LABEL=*) + dev=`blkid -L "${dev#LABEL=}"` + ;; + esac + echo $(get_persistent_dev "$dev") +} + is_atomic() { grep -q "ostree" /proc/cmdline @@ -583,35 +597,6 @@ need_64bit_headers() print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'` } -# Check if secure boot is being enforced. -# -# Per Peter Jones, we need check efivar SecureBoot-$(the UUID) and -# SetupMode-$(the UUID), they are both 5 bytes binary data. The first four -# bytes are the attributes associated with the variable and can safely be -# ignored, the last bytes are one-byte true-or-false variables. If SecureBoot -# is 1 and SetupMode is 0, then secure boot is being enforced. -# -# Assume efivars is mounted at /sys/firmware/efi/efivars. -is_secure_boot_enforced() -{ - local secure_boot_file setup_mode_file - local secure_boot_byte setup_mode_byte - - secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null) - setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null) - - if [ -f "$secure_boot_file" ] && [ -f "$setup_mode_file" ]; then - secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5) - setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5) - - if [ "$secure_boot_byte" = "1" ] && [ "$setup_mode_byte" = "0" ]; then - return 0 - fi - fi - - return 1 -} - # # prepare_kexec_args # This function prepares kexec argument. diff --git a/SOURCES/kdump.conf b/SOURCES/kdump.conf index 2b2fc89..4f3e30e 100644 --- a/SOURCES/kdump.conf +++ b/SOURCES/kdump.conf @@ -79,13 +79,23 @@ # or script after the vmcore dump process terminates. # The exit status of the current dump process is fed to # the executable binary or script as its first argument. +# If /etc/kdump/post.d directory is exist, All files in +# the directory are collectively sorted and executed in +# lexical order, before binary or script specified +# kdump_post parameter is executed. # # kdump_pre # - Works like the "kdump_post" directive, but instead of running # after the dump process, runs immediately before it. # Exit status of this binary is interpreted as follows: -# 0 - continue with dump process as usual -# non 0 - reboot the system +# 0 - continue with dump process as usual +# non 0 - reboot the system +# If /etc/kdump/pre.d directory exists, all files in +# the directory are collectively sorted and executed in +# lexical order, after binary or script specified +# kdump_pre parameter is executed. +# Even if the binary or script in /etc/kdump/pre.d directory +# returns non 0 exit status, the processing is continued. # # extra_bins # - This directive allows you to specify additional binaries or diff --git a/SOURCES/kdump.conf.5 b/SOURCES/kdump.conf.5 index adfc372..ea3e770 100644 --- a/SOURCES/kdump.conf.5 +++ b/SOURCES/kdump.conf.5 @@ -109,6 +109,11 @@ status of the current dump process is fed to the kdump_post executable as its first argument($1). Executable can modify it to indicate the new exit status of succeeding dump process, .PP +If /etc/kdump/post.d directory exists, All files in +the directory are collectively sorted and executed in +lexical order, before binary or script specified +kdump_post parameter is executed. +.PP Note that scripts written for use with this directive must use the /bin/bash interpreter. .RE @@ -124,6 +129,13 @@ as follows: .PP non 0 - reboot the system .PP +If /etc/kdump/pre.d directory exists, all files in +the directory are collectively sorted and executed in +lexical order, after binary or script specified +kdump_pre parameter is executed. +Even if the binary or script in /etc/kdump/pre.d directory +returns non 0 exit status, the processing is continued. +.PP Note that scripts written for this directive must use the /bin/bash interpreter. .RE diff --git a/SOURCES/kdump.sysconfig.x86_64 b/SOURCES/kdump.sysconfig.x86_64 index 96ac7be..ef1da2d 100644 --- a/SOURCES/kdump.sysconfig.x86_64 +++ b/SOURCES/kdump.sysconfig.x86_64 @@ -38,3 +38,9 @@ KDUMP_IMG="vmlinuz" #What is the images extension. Relocatable kernels don't have one KDUMP_IMG_EXT="" + +# Using kexec file based syscall by default +# +# Here, the "on" is the only valid value to enable the kexec file load and +# anything else is equal to the "off"(disable). +KDUMP_FILE_LOAD="off" diff --git a/SOURCES/kdumpctl b/SOURCES/kdumpctl index a542b54..73f45d3 100755 --- a/SOURCES/kdumpctl +++ b/SOURCES/kdumpctl @@ -4,6 +4,7 @@ KEXEC=/sbin/kexec KDUMP_KERNELVER="" KDUMP_COMMANDLINE="" KEXEC_ARGS="" +KDUMP_FILE_LOAD="" KDUMP_CONFIG_FILE="/etc/kdump.conf" MKDUMPRD="/sbin/mkdumprd -f" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" @@ -335,9 +336,23 @@ check_files_modified() EXTRA_BINS=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2` CHECK_FILES=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\ -f2` + if [ -d /etc/kdump/post.d ]; then + for file in /etc/kdump/post.d/*; do + if [ -x "$file" ]; then + POST_FILES="$POST_FILES $file" + fi + done + fi + if [ -d /etc/kdump/pre.d ]; then + for file in /etc/kdump/pre.d/*; do + if [ -x "$file" ]; then + PRE_FILES="$PRE_FILES $file" + fi + done + fi CORE_COLLECTOR=`grep ^core_collector $KDUMP_CONFIG_FILE | cut -d\ -f2` CORE_COLLECTOR=`type -P $CORE_COLLECTOR` - EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" + EXTRA_BINS="$EXTRA_BINS $CHECK_FILES $POST_FILES $PRE_FILES" CHECK_FILES=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\ -f2-` EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" files="$KDUMP_CONFIG_FILE $kdump_kernel $EXTRA_BINS $CORE_COLLECTOR" @@ -464,7 +479,7 @@ check_dump_fs_modified() if [[ $(expr substr $_new_fstype 1 3) = "nfs" ]];then _new_dev=$_target else - _new_dev=$(get_persistent_dev $_target) + _new_dev=$(kdump_get_persistent_dev $_target) if [ -z "$_new_dev" ]; then echo "Get persistent device name failed" return 2 @@ -668,11 +683,8 @@ load_kdump() KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") KDUMP_COMMANDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") - # For secureboot enabled machines, use new kexec file based syscall. - # Old syscall will always fail as it does not have capability to - # to kernel signature verification. - if is_secure_boot_enforced; then - echo "Secure Boot is enabled. Using kexec file based syscall." + if [ "$KDUMP_FILE_LOAD" == "on" ]; then + echo "Using kexec file based syscall." KEXEC_ARGS="$KEXEC_ARGS -s" fi @@ -684,6 +696,9 @@ load_kdump() return 0 else echo "kexec: failed to load kdump kernel" >&2 + if [ "$KDUMP_FILE_LOAD" == "on" ]; then + echo "kexec_file_load() failed, please try kexec_load()" >&2 + fi return 1 fi } @@ -1139,7 +1154,7 @@ stop_fadump() stop_kdump() { - if is_secure_boot_enforced; then + if [ "$KDUMP_FILE_LOAD" == "on" ]; then $KEXEC -s -p -u else $KEXEC -p -u diff --git a/SOURCES/kexec-kdump-howto.txt b/SOURCES/kexec-kdump-howto.txt index 4b15dd0..449855e 100644 --- a/SOURCES/kexec-kdump-howto.txt +++ b/SOURCES/kexec-kdump-howto.txt @@ -543,6 +543,9 @@ 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 +collectively sorted and executed in lexical order, before binary or script +specified kdump_post parameter is executed. Kdump Pre-Capture Executable ---------------------------- @@ -551,6 +554,11 @@ It is possible to specify a custom script or binary you wish to run before capturing a vmcore. Exit status of this binary is interpreted: 0 - continue with dump process as usual non 0 - reboot the system +If /etc/kdump/pre.d directory exists, all files in the directory are collectively +sorted and executed in lexical order, after binary or script specified +kdump_pre parameter is executed. +Even if the binary or script in /etc/kdump/pre.d directory returns non 0 +exit status, the processing is continued. Extra Binaries -------------- diff --git a/SOURCES/mkdumprd b/SOURCES/mkdumprd index f8edde1..8b09710 100644 --- a/SOURCES/mkdumprd +++ b/SOURCES/mkdumprd @@ -65,7 +65,7 @@ add_dracut_sshkey() { # caller should ensure $1 is valid and mounted in 1st kernel to_mount() { - local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _mntopts _pdev + local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _pdev _new_mntpoint=$(get_kdump_mntpoint_from_target $_target) _fstype="${_fstype:-$(get_fs_type_from_target $_target)}" @@ -73,9 +73,16 @@ to_mount() { _options="${_options:-defaults}" if [[ "$_fstype" == "nfs"* ]]; then + _pdev=$_target _options=$(echo $_options | sed 's/,addr=[^,]*//') _options=$(echo $_options | sed 's/,proto=[^,]*//') _options=$(echo $_options | sed 's/,clientaddr=[^,]*//') + else + # for non-nfs _target converting to use udev persistent name + _pdev="$(kdump_get_persistent_dev $_target)" + if [ -z "$_pdev" ]; then + return 1 + fi fi #mount fs target as rw in 2nd kernel @@ -87,18 +94,7 @@ to_mount() { # mount it before kdump starts, this is an attempt to improve robustness _options="$_options,nofail,x-systemd.before=initrd-fs.target" - _mntopts="$_new_mntpoint $_fstype $_options" - # for non-nfs _target converting to use udev persistent name - if [ -b "$_target" ]; then - _pdev="$(get_persistent_dev $_target)" - if [ -z "$_pdev" ]; then - return 1 - fi - else - _pdev=$_target - fi - - echo "$_pdev $_mntopts" + echo "$_pdev $_new_mntpoint $_fstype $_options" } #Function: get_ssh_size @@ -223,7 +219,7 @@ check_user_configured_target() [ $? -ne 0 ] && perror_exit "Failed to mount $_target on $_mnt for kdump preflight check." _mounted=$_mnt else - perror_exit "$_target is configured in fstab but not mounted, please check its usability." + perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" fi fi else @@ -435,7 +431,7 @@ do dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { perror_exit "Bad raw disk $config_val" } - _praw=$(persistent_policy="by-id" get_persistent_dev $config_val) + _praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val) if [ -z "$_praw" ]; then exit 1 fi @@ -468,7 +464,7 @@ handle_default_dump_target if [ -n "$extra_modules" ] then - add_dracut_arg "--add-drivers" "$extra_modules" + add_dracut_arg "--add-drivers" \"$extra_modules\" fi if ! is_fadump_capable; then diff --git a/SPECS/kexec-tools.spec b/SPECS/kexec-tools.spec index 8df9093..49e1d46 100644 --- a/SPECS/kexec-tools.spec +++ b/SPECS/kexec-tools.spec @@ -1,6 +1,6 @@ Name: kexec-tools Version: 2.0.20 -Release: 24%{?dist} +Release: 29%{?dist} License: GPLv2 Group: Applications/System Summary: The kexec/kdump userspace component @@ -173,7 +173,7 @@ cp %{SOURCE28} . cp %{SOURCE31} . make -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{arm} +%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 make -C eppic/libeppic make -C makedumpfile-1.6.7 LINKTYPE=dynamic USELZO=on USESNAPPY=on make -C makedumpfile-1.6.7 LDFLAGS="$LDFLAGS -I../eppic/libeppic -L../eppic/libeppic" eppic_makedumpfile.so @@ -226,7 +226,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 -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{arm} +%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 install -m 755 makedumpfile-1.6.7/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile install -m 644 makedumpfile-1.6.7/makedumpfile.8.gz $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8.gz install -m 644 makedumpfile-1.6.7/makedumpfile.conf.5.gz $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5.gz @@ -339,7 +339,7 @@ done %{_bindir}/* %{_datadir}/kdump %{_prefix}/lib/kdump -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{arm} +%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{_sysconfdir}/makedumpfile.conf.sample %endif %config(noreplace,missingok) %{_sysconfdir}/sysconfig/kdump @@ -367,12 +367,33 @@ done %doc supported-kdump-targets.txt %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{arm} +%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{_libdir}/eppic_makedumpfile.so /usr/share/makedumpfile/ %endif %changelog +* Wed Jun 24 2020 Pingfan Liu - 2.0.20-29 +- mkdumprd: Improve the error message for umounted dump target + +* Wed Jun 24 2020 Pingfan Liu - 2.0.20-28 +- mkdumprd: Fix nfs detection in to_mount +- Always wrap up call to dracut get_persistent_dev function +- man: improve description about /etc/kdump/{pre.d,post.d}interface + +* Tue Jun 16 2020 Pingfan Liu - 2.0.20-27 +- kdump-lib: switch to the kexec_file_load() syscall on x86_64 by default + +* Mon Jun 15 2020 Pingfan Liu - 2.0.20-26 +- Fix kdump failure when mount target specified by dracut_args +- mkdumprd: Fix dracut error on multiple extra_modules + +* Mon Jun 15 2020 Pingfan Liu - 2.0.20-25 +- kdump.conf: Specify /etc/kdump/{pre.d,post.d}interface +- dracut-kdump.sh: Execute the binary and script filesin /etc/kdump/{pre.d,post.d} +- kdumpctl: Check the update of the binary and script files in /etc/kdump/{pre.d,post.d} +- dracut-module-setup.sh: Install files under /etc/kdump/{pre.d,post.d} into kdump initramfs + * Thu Jun 4 2020 Pingfan Liu - 2.0.20-24 - fadump: update fadump-howto.txt with some more troubleshooting help