[PATCH] kdumpctl, fadump: check existence of kdump initramfs before inspecting by lsinitrd
by WANG Chao
When there's no kdump initramfs for lsinitrd to inspect with, there will
be an error:
# kdumpctl start
/boot/initramfs-3.16.0-rc7+kdump.img does not exist
Usage: lsinitrd [options] [<initramfs file> [<filename> [<filename> [...] ]]]
Usage: lsinitrd [options] -k <kernel version>
-h, --help print a help message and exit.
-s, --size sort the contents of the initramfs by size.
-m, --mod list modules.
-f, --file <filename> print the contents of <filename>.
-k, --kver <kernel version> inspect the initramfs of <kernel version>.
No kdump initial ramdisk found.
Rebuilding /boot/initramfs-3.16.0-rc7+kdump.img
[..]
If kdump initramfs doesn't exist, we simply mark the inspecting kdump
module failing. It wouldn't matter, because we need to build kdump
initramfs anyway.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
kdumpctl | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kdumpctl b/kdumpctl
index 98de747..4f50dcb 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -364,7 +364,11 @@ check_rebuild()
done
#check if target initrd has fadump support
- initramfs_has_fadump=`lsinitrd -m $TARGET_INITRD | grep ^kdumpbase$ | wc -l`
+ if [ -f $TARGET_INITRD ]; then
+ initramfs_has_fadump=`lsinitrd -m $TARGET_INITRD | grep ^kdumpbase$ | wc -l`
+ else
+ initramfs_has_fadump=0
+ fi
if [ $image_time -eq 0 ]; then
echo -n "No kdump initial ramdisk found."; echo
--
1.9.3
9 years, 8 months
[PATCH v2 1/3] cleanup: extract functions from kdump.sh to kdump-lib-initramfs.sh
by WANG Chao
Extract functions from kdump.sh, and construct kdump-lib-initramfs.sh as
kdump common functions/varaibles library.
kdump-lib-initramfs.sh will include kdump-lib.sh, because it will use
the functions from there. IOW, kdump-lib-initramfs.sh will be a superset
of kdump-lib.sh
So after this cleanup:
- scripts running in 1st kernel only have to include kdump-lib.sh
- scripts running in 2nd kernel only have to include kdump-lib-initramfs.sh
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump.sh | 150 ++----------------------------------------------
dracut-module-setup.sh | 1 +
kdump-lib-initramfs.sh | 151 +++++++++++++++++++++++++++++++++++++++++++++++++
kexec-tools.spec | 2 +
4 files changed, 159 insertions(+), 145 deletions(-)
create mode 100755 kdump-lib-initramfs.sh
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index e6faf9c..a2bfa05 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -7,30 +7,14 @@ fi
exec &> /dev/console
. /lib/dracut-lib.sh
-. /lib/kdump-lib.sh
+. /lib/kdump-lib-initramfs.sh
if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then
rm -f -- $initdir/lib/dracut/no-emergency-shell
fi
set -o pipefail
-KDUMP_PATH="/var/crash"
-CORE_COLLECTOR=""
-DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
-DMESG_COLLECTOR="/sbin/vmcore-dmesg"
-DEFAULT_ACTION="reboot -f"
-DATEDIR=`date +%Y.%m.%d-%T`
-HOST_IP='127.0.0.1'
-DUMP_INSTRUCTION=""
-SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
-KDUMP_SCRIPT_DIR="/kdumpscripts"
-DD_BLKSIZE=512
-FINAL_ACTION="reboot -f"
DUMP_RETVAL=0
-conf_file="/etc/kdump.conf"
-KDUMP_PRE=""
-KDUMP_POST=""
-MOUNTS=""
export PATH=$PATH:$KDUMP_SCRIPT_DIR
@@ -48,27 +32,6 @@ do_dump()
return $_ret
}
-do_umount()
-{
- if [ -n "$MOUNTS" ]; then
- for mount in $MOUNTS; do
- ismounted $mount && umount -R $mount
- done
- fi
-}
-
-do_final_action()
-{
- do_umount
- eval $FINAL_ACTION
-}
-
-do_default_action()
-{
- wait_for_loginit
- eval $DEFAULT_ACTION
-}
-
do_kdump_pre()
{
if [ -n "$KDUMP_PRE" ]; then
@@ -88,39 +51,6 @@ add_dump_code()
DUMP_INSTRUCTION=$1
}
-# dump_fs <mount point| device>
-dump_fs()
-{
- local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
- local _mp=$(findmnt -k -f -n -r -o TARGET $1)
-
- echo "kdump: dump target is $_dev"
-
- if [ -z "$_mp" ]; then
- echo "kdump: error: Dump target $_dev is not mounted."
- return 1
- fi
- MOUNTS="$MOUNTS $_mp"
-
- # Remove -F in makedumpfile case. We don't want a flat format dump here.
- [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
-
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- mount -o remount,rw $_mp || return 1
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
-
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- echo "kdump: saving vmcore"
- $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
- mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
- sync
-
- echo "kdump: saving vmcore complete"
- return 0
-}
-
dump_raw()
{
local _raw=$1
@@ -170,26 +100,6 @@ dump_ssh()
return 0
}
-save_vmcore_dmesg_fs() {
- local _dmesg_collector=$1
- local _path=$2
-
- echo "kdump: saving vmcore-dmesg.txt"
- $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
- _exitcode=$?
- if [ $_exitcode -eq 0 ]; then
- mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
-
- # Make sure file is on disk. There have been instances where later
- # saving vmcore failed and system rebooted without sync and there
- # was no vmcore-dmesg.txt available.
- sync
- echo "kdump: saving vmcore-dmesg.txt complete"
- else
- echo "kdump: saving vmcore-dmesg.txt failed"
- fi
-}
-
save_vmcore_dmesg_ssh() {
local _dmesg_collector=$1
local _path=$2
@@ -208,7 +118,6 @@ save_vmcore_dmesg_ssh() {
fi
}
-
get_host_ip()
{
local _host
@@ -228,61 +137,12 @@ get_host_ip()
read_kdump_conf()
{
- if [ ! -f "$conf_file" ]; then
- echo "kdump: $conf_file not found"
+ if [ ! -f "$KDUMP_CONF" ]; then
+ echo "kdump: $KDUMP_CONF not found"
return
fi
- # first get the necessary variables
- while read config_opt config_val;
- do
- # remove inline comments after the end of a directive.
- config_val=$(strip_comments $config_val)
- case "$config_opt" in
- path)
- KDUMP_PATH="$config_val"
- ;;
- core_collector)
- [ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
- ;;
- sshkey)
- if [ -f "$config_val" ]; then
- SSH_KEY_LOCATION=$config_val
- fi
- ;;
- kdump_pre)
- KDUMP_PRE="$config_val"
- ;;
- kdump_post)
- KDUMP_POST="$config_val"
- ;;
- fence_kdump_args)
- FENCE_KDUMP_ARGS="$config_val"
- ;;
- fence_kdump_nodes)
- FENCE_KDUMP_NODES="$config_val"
- ;;
- default)
- case $config_val in
- shell)
- DEFAULT_ACTION="_emergency_shell kdump"
- ;;
- reboot)
- DEFAULT_ACTION="do_umount; reboot -f"
- ;;
- halt)
- DEFAULT_ACTION="do_umount; halt -f"
- ;;
- poweroff)
- DEFAULT_ACTION="do_umount; poweroff -f"
- ;;
- dump_to_rootfs)
- DEFAULT_ACTION="dump_fs $NEWROOT"
- ;;
- esac
- ;;
- esac
- done < $conf_file
+ get_kdump_confs
# rescan for add code for dump target
while read config_opt config_val;
@@ -300,7 +160,7 @@ read_kdump_conf()
add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val"
;;
esac
- done < $conf_file
+ done < $KDUMP_CONF
}
fence_kdump_notify()
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 5ab2997..758420b 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -580,6 +580,7 @@ install() {
inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg"
inst_hook pre-pivot 9999 "$moddir/kdump.sh"
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
+ inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
# Check for all the devices and if any device is iscsi, bring up iscsi
# target. Ideally all this should be pushed into dracut iscsi module
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
new file mode 100755
index 0000000..d16bcf4
--- /dev/null
+++ b/kdump-lib-initramfs.sh
@@ -0,0 +1,151 @@
+# These variables and functions are useful in 2nd kernel
+
+. /lib/dracut-lib.sh
+. /lib/kdump-lib.sh
+
+KDUMP_PATH="/var/crash"
+CORE_COLLECTOR=""
+DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
+DMESG_COLLECTOR="/sbin/vmcore-dmesg"
+DEFAULT_ACTION="reboot -f"
+DATEDIR=`date +%Y.%m.%d-%T`
+HOST_IP='127.0.0.1'
+DUMP_INSTRUCTION=""
+SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
+KDUMP_SCRIPT_DIR="/kdumpscripts"
+DD_BLKSIZE=512
+FINAL_ACTION="reboot -f"
+KDUMP_CONF="/etc/kdump.conf"
+KDUMP_PRE=""
+KDUMP_POST=""
+NEWROOT="/sysroot"
+MOUNTS=""
+
+get_kdump_confs()
+{
+ local config_opt config_val
+
+ while read config_opt config_val;
+ do
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
+ case "$config_opt" in
+ path)
+ KDUMP_PATH="$config_val"
+ ;;
+ core_collector)
+ [ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
+ ;;
+ sshkey)
+ if [ -f "$config_val" ]; then
+ SSH_KEY_LOCATION=$config_val
+ fi
+ ;;
+ kdump_pre)
+ KDUMP_PRE="$config_val"
+ ;;
+ kdump_post)
+ KDUMP_POST="$config_val"
+ ;;
+ fence_kdump_args)
+ FENCE_KDUMP_ARGS="$config_val"
+ ;;
+ fence_kdump_nodes)
+ FENCE_KDUMP_NODES="$config_val"
+ ;;
+ default)
+ case $config_val in
+ shell)
+ DEFAULT_ACTION="_emergency_shell kdump"
+ ;;
+ reboot)
+ DEFAULT_ACTION="do_umount; reboot -f"
+ ;;
+ halt)
+ DEFAULT_ACTION="do_umount; halt -f"
+ ;;
+ poweroff)
+ DEFAULT_ACTION="do_umount; poweroff -f"
+ ;;
+ dump_to_rootfs)
+ DEFAULT_ACTION="dump_fs $NEWROOT"
+ ;;
+ esac
+ ;;
+ esac
+ done < $KDUMP_CONF
+}
+
+# dump_fs <mount point| device>
+dump_fs()
+{
+
+ local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
+ local _mp=$(findmnt -k -f -n -r -o TARGET $1)
+
+ echo "kdump: dump target is $_dev"
+
+ if [ -z "$_mp" ]; then
+ echo "kdump: error: Dump target $_dev is not mounted."
+ return 1
+ fi
+ MOUNTS="$MOUNTS $_mp"
+
+ # Remove -F in makedumpfile case. We don't want a flat format dump here.
+ [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
+
+ echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ mount -o remount,rw $_mp || return 1
+ mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
+
+ save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ echo "kdump: saving vmcore"
+ $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
+ mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
+ sync
+
+ echo "kdump: saving vmcore complete"
+}
+
+save_vmcore_dmesg_fs() {
+ local _dmesg_collector=$1
+ local _path=$2
+
+ echo "kdump: saving vmcore-dmesg.txt"
+ $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
+ _exitcode=$?
+ if [ $_exitcode -eq 0 ]; then
+ mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
+
+ # Make sure file is on disk. There have been instances where later
+ # saving vmcore failed and system rebooted without sync and there
+ # was no vmcore-dmesg.txt available.
+ sync
+ echo "kdump: saving vmcore-dmesg.txt complete"
+ else
+ echo "kdump: saving vmcore-dmesg.txt failed"
+ fi
+}
+
+do_umount()
+{
+ if [ -n "$MOUNTS" ]; then
+ for mount in $MOUNTS; do
+ ismounted $mount && umount -R $mount
+ done
+ fi
+}
+
+do_default_action()
+{
+ wait_for_loginit
+ eval $DEFAULT_ACTION
+}
+
+do_final_action()
+{
+ do_umount
+ eval $FINAL_ACTION
+}
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 6581277..b55a7f1 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -27,6 +27,7 @@ Source20: kdump-lib.sh
Source21: kdump-in-cluster-environment.txt
Source22: kdump-dep-generator.sh
Source23: kdump-anaconda-addon-001-4-g03898ef.tar.gz
+Source24: kdump-lib-initramfs.sh
#######################################
# These are sources for mkdumpramfs
@@ -178,6 +179,7 @@ install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8
install -m 755 %{SOURCE11} $RPM_BUILD_ROOT%{_datadir}/kdump/firstboot_kdump.py
install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8
install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh
+install -m 755 %{SOURCE24} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh
%ifnarch s390x
# For s390x the ELF header is created in the kdump kernel and therefore kexec
# udev rules are not required
--
1.9.3
9 years, 8 months
[PATCH v7 0/2] Kdump error handling service
by WANG Chao
Hi, All
Now upon failure kdump script might not be called at all and it might
not be able to execute default action. It results in a hang.
Because we disable emergency shell and rely on kdump.sh being invoked
through dracut-pre-pivot hook. But it might happen that we never call
into dracut-pre-pivot hook because certain systemd targets could not
reach due to failure in their dependencies. In those cases error
handling code does not run and system hangs.
To solve this problem, we need to separate the error handling code from
dracut-pre-pivot hook, and every time when a failure shows up, the
separated code can be called by the emergency service.
By default systemd provides an emergency service which will drop us into
shell every time upon a critical failure. It's very convenient for us to
re-use the framework of systemd emergency, because we don't have to
touch the other parts of systemd. We can use our own script instead of
the default one.
This new scheme will overwrite emergency shell and replace with kdump
error handling code. And this code will do the error handling as needed.
Now, we will not rely on dracut-pre-pivot hook running always. Instead
whenever error happens and it is serious enough that emergency shell
needed to run, now kdump error handler will run.
This patchset introduce a new kdump emergency service. It will override the
existing emergency.service. When fatal error occurs, this emergency service
will be triggered and systemd will isolate to emergency path.
This kdump emergency service is a wrapper service and it will isolate to
kdump-error-handler service. kdump-error-handler can will read kdump.conf and
act according to the configired "default action"
(reboot/poweroff/halt/shell/dump_to_rootfs).
Along with this patchset, kdump-capture.service is introduced as a service unit
to run kdump.sh. When kdump-capture.service fails, systemd will isolate to
kdump emergency service. I copied all the dependencies from
dracut-pre-pivot.service to kdump-capture.service so that kdump.sh will be
called at the correct time window.
v2:
Address several comments from Vivek:
- split [patch 1] into 1/6 and 2/6
- remove several unnecessary lines in service unit.
- modify the description of kdump-capture.service
- introduce another kdump lib kdump-lib-2.sh used in 2nd kernel.
V3:
Address several comments from Vivek:
- update description of [PATCH 1/5] and [PATCH 5/5]
- separate the patch of cleanup to kdump-lib-initramfs.sh
V4:
Address several comments from Vivek and Dave:
- meld the original [PATCH 3/5] into [PATCH 1/5]
- add GPL license for kdump-error-handler.service and kdump-capture.service
- separate the "x-initrd.mount" and "mount under /sysroot" patch to another
patchset
V5:
- Rebase on top of the fadump patchset.
- Enable dracut-emergency again, but override it with kdump error handler.
V6:
- reboot if entering error handler in error handling path
- add comments in dracut-kdump-emergency.service
- update changelog
V7:
- add wrapper emergency.service to isolate to kdump-error-handler service
- remove extra code introduced in v6 for avoiding entering error path again
WANG Chao (2):
Introduce kdump error handling service
Introduce kdump capture service
dracut-kdump-capture.service | 30 ++++++++++++++++++++++++++++++
dracut-kdump-emergency.service | 27 +++++++++++++++++++++++++++
dracut-kdump-error-handler.service | 34 ++++++++++++++++++++++++++++++++++
dracut-kdump-error-handler.sh | 10 ++++++++++
dracut-kdump.sh | 9 ++-------
dracut-module-setup.sh | 11 +++++++++--
kdump-lib-initramfs.sh | 34 ++++++++++++++++++++++++++++++----
kexec-tools.spec | 9 ++++++++-
8 files changed, 150 insertions(+), 14 deletions(-)
create mode 100644 dracut-kdump-capture.service
create mode 100644 dracut-kdump-emergency.service
create mode 100644 dracut-kdump-error-handler.service
create mode 100755 dracut-kdump-error-handler.sh
--
1.9.3
9 years, 8 months
[PATCH] kdumpctl: fix error handling in fadump case
by Hari Bathini
In fadump, in case of failure while rebuilding initrd, the error status
is not handled properly. See code snippet below:
$MKDUMPRD $target_initrd_tmp --rebuild $TARGET_INITRD --kver $kdump_kver \
-i /tmp/fadump.initramfs /etc/fadump.initramfs
rm -f /tmp/fadump.initramfs
if [ $? != 0 ]; then
echo "mkdumprd: failed to rebuild initrd with fadump support" >&2
return 1
fi
This patch fixes this issue
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
kdumpctl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kdumpctl b/kdumpctl
index 98de747..2bac6df 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -156,11 +156,12 @@ rebuild_fadump_initrd()
target_initrd_tmp="$TARGET_INITRD.tmp"
$MKDUMPRD $target_initrd_tmp --rebuild $TARGET_INITRD --kver $kdump_kver \
-i /tmp/fadump.initramfs /etc/fadump.initramfs
- rm -f /tmp/fadump.initramfs
if [ $? != 0 ]; then
echo "mkdumprd: failed to rebuild initrd with fadump support" >&2
+ rm -f /tmp/fadump.initramfs
return 1
fi
+ rm -f /tmp/fadump.initramfs
# updating fadump initrd
mv $target_initrd_tmp $TARGET_INITRD
9 years, 8 months