2011-07-28 14:50:43 +00:00
|
|
|
#!/bin/sh
|
2021-08-01 16:50:22 +00:00
|
|
|
#
|
|
|
|
# The main kdump routine in capture kernel
|
|
|
|
#
|
2014-07-24 18:39:22 +00:00
|
|
|
|
2011-07-28 14:50:43 +00:00
|
|
|
. /lib/dracut-lib.sh
|
2021-08-04 16:59:29 +00:00
|
|
|
. /lib/kdump-logger.sh
|
2014-05-08 11:37:14 +00:00
|
|
|
. /lib/kdump-lib-initramfs.sh
|
2011-07-28 14:50:43 +00:00
|
|
|
|
2021-08-04 16:59:29 +00:00
|
|
|
#initiate the kdump logger
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! dlog_init; then
|
2021-08-04 16:59:29 +00:00
|
|
|
echo "failed to initiate the kdump logger."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
KDUMP_PATH="/var/crash"
|
|
|
|
KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log"
|
|
|
|
CORE_COLLECTOR=""
|
|
|
|
DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"
|
|
|
|
DMESG_COLLECTOR="/sbin/vmcore-dmesg"
|
|
|
|
FAILURE_ACTION="systemctl reboot -f"
|
2021-08-18 13:06:52 +00:00
|
|
|
DATEDIR=$(date +%Y-%m-%d-%T)
|
2021-08-04 16:59:29 +00:00
|
|
|
HOST_IP='127.0.0.1'
|
|
|
|
DUMP_INSTRUCTION=""
|
|
|
|
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
|
|
|
|
DD_BLKSIZE=512
|
|
|
|
FINAL_ACTION="systemctl reboot -f"
|
|
|
|
KDUMP_PRE=""
|
|
|
|
KDUMP_POST=""
|
|
|
|
NEWROOT="/sysroot"
|
|
|
|
OPALCORE="/sys/firmware/opal/mpipl/core"
|
2021-08-18 13:06:52 +00:00
|
|
|
KDUMP_CONF_PARSED="/tmp/kdump.conf.$$"
|
2021-08-04 16:59:29 +00:00
|
|
|
|
2021-08-11 18:55:32 +00:00
|
|
|
# POSIX doesn't have pipefail, only apply when using bash
|
|
|
|
# shellcheck disable=SC3040
|
|
|
|
[ -n "$BASH" ] && set -o pipefail
|
|
|
|
|
2012-06-12 01:42:39 +00:00
|
|
|
DUMP_RETVAL=0
|
2012-04-28 10:01:18 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
kdump_read_conf > $KDUMP_CONF_PARSED
|
|
|
|
|
2021-08-04 16:59:29 +00:00
|
|
|
get_kdump_confs()
|
|
|
|
{
|
2021-08-18 13:06:52 +00:00
|
|
|
while read -r config_opt config_val; do
|
2021-08-04 16:59:29 +00:00
|
|
|
# remove inline comments after the end of a directive.
|
|
|
|
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"
|
|
|
|
;;
|
|
|
|
failure_action|default)
|
|
|
|
case $config_val in
|
|
|
|
shell)
|
|
|
|
FAILURE_ACTION="kdump_emergency_shell"
|
|
|
|
;;
|
|
|
|
reboot)
|
|
|
|
FAILURE_ACTION="systemctl reboot -f && exit"
|
|
|
|
;;
|
|
|
|
halt)
|
|
|
|
FAILURE_ACTION="halt && exit"
|
|
|
|
;;
|
|
|
|
poweroff)
|
|
|
|
FAILURE_ACTION="systemctl poweroff -f && exit"
|
|
|
|
;;
|
|
|
|
dump_to_rootfs)
|
|
|
|
FAILURE_ACTION="dump_to_rootfs"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
final_action)
|
|
|
|
case $config_val in
|
|
|
|
reboot)
|
|
|
|
FINAL_ACTION="systemctl reboot -f"
|
|
|
|
;;
|
|
|
|
halt)
|
|
|
|
FINAL_ACTION="halt"
|
|
|
|
;;
|
|
|
|
poweroff)
|
|
|
|
FINAL_ACTION="systemctl poweroff -f"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
2021-08-18 13:06:52 +00:00
|
|
|
done < "$KDUMP_CONF_PARSED"
|
2021-08-04 16:59:29 +00:00
|
|
|
|
|
|
|
if [ -z "$CORE_COLLECTOR" ]; then
|
|
|
|
CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
|
|
|
|
if is_ssh_dump_target || is_raw_dump_target; then
|
|
|
|
CORE_COLLECTOR="$CORE_COLLECTOR -F"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# store the kexec kernel log to a file.
|
|
|
|
save_log()
|
|
|
|
{
|
|
|
|
dmesg -T > $KDUMP_LOG_FILE
|
|
|
|
|
|
|
|
if command -v journalctl > /dev/null; then
|
|
|
|
journalctl -ab >> $KDUMP_LOG_FILE
|
|
|
|
fi
|
|
|
|
chmod 600 $KDUMP_LOG_FILE
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: dump path, must be a mount point
|
2021-08-04 16:59:29 +00:00
|
|
|
dump_fs()
|
|
|
|
{
|
2021-08-18 13:06:52 +00:00
|
|
|
ddebug "dump_fs _mp=$1"
|
|
|
|
|
|
|
|
if ! is_mounted "$1"; then
|
|
|
|
dinfo "dump path '$1' is not mounted, trying to mount..."
|
|
|
|
if ! mount --target "$1"; then
|
|
|
|
derror "failed to dump to '$1', it's not a mount point!"
|
2021-08-04 16:59:29 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove -F in makedumpfile case. We don't want a flat format dump here.
|
2021-08-18 13:06:52 +00:00
|
|
|
case $CORE_COLLECTOR in
|
|
|
|
*makedumpfile* )
|
|
|
|
CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
|
|
|
|
;;
|
|
|
|
esac
|
2021-08-04 16:59:29 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
|
|
|
|
dinfo "saving to $_dump_fs_path"
|
2021-08-04 16:59:29 +00:00
|
|
|
|
|
|
|
# Only remount to read-write mode if the dump target is mounted read-only.
|
2021-08-18 13:06:52 +00:00
|
|
|
_dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f)
|
|
|
|
case $_dump_mnt_op in
|
|
|
|
ro* )
|
|
|
|
dinfo "Remounting the dump target in rw mode."
|
|
|
|
mount -o remount,rw "$1" || return 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-08-04 16:59:29 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
mkdir -p "$_dump_fs_path" || return 1
|
2021-08-04 16:59:29 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"
|
|
|
|
save_opalcore_fs "$_dump_fs_path"
|
2021-08-04 16:59:29 +00:00
|
|
|
|
|
|
|
dinfo "saving vmcore"
|
2021-08-18 13:06:52 +00:00
|
|
|
$CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete"
|
|
|
|
_dump_exitcode=$?
|
|
|
|
if [ $_dump_exitcode -eq 0 ]; then
|
|
|
|
mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore"
|
2021-08-04 16:59:29 +00:00
|
|
|
sync
|
|
|
|
dinfo "saving vmcore complete"
|
|
|
|
else
|
2021-08-18 13:06:52 +00:00
|
|
|
derror "saving vmcore failed, exitcode:$_dump_exitcode"
|
2021-08-04 16:59:29 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/"
|
2021-08-04 16:59:29 +00:00
|
|
|
save_log
|
2021-08-18 13:06:52 +00:00
|
|
|
mv "$KDUMP_LOG_FILE" "$_dump_fs_path/"
|
|
|
|
if [ $_dump_exitcode -ne 0 ]; then
|
2021-08-04 16:59:29 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: dmesg collector
|
|
|
|
# $2: dump path
|
2021-08-04 16:59:29 +00:00
|
|
|
save_vmcore_dmesg_fs() {
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving vmcore-dmesg.txt to $2"
|
|
|
|
if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then
|
|
|
|
mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
|
|
|
chmod 600 "$2/vmcore-dmesg.txt"
|
2021-08-04 16:59:29 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
dinfo "saving vmcore-dmesg.txt complete"
|
|
|
|
else
|
2021-08-18 13:06:52 +00:00
|
|
|
if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then
|
|
|
|
chmod 600 "$2/vmcore-dmesg-incomplete.txt"
|
2021-08-04 16:59:29 +00:00
|
|
|
fi
|
|
|
|
derror "saving vmcore-dmesg.txt failed"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: dump path
|
2021-08-04 16:59:29 +00:00
|
|
|
save_opalcore_fs() {
|
|
|
|
if [ ! -f $OPALCORE ]; then
|
|
|
|
# Check if we are on an old kernel that uses a different path
|
|
|
|
if [ -f /sys/firmware/opal/core ]; then
|
|
|
|
OPALCORE="/sys/firmware/opal/core"
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving opalcore:$OPALCORE to $1/opalcore"
|
|
|
|
if ! cp $OPALCORE "$1/opalcore"; then
|
2021-08-04 16:59:29 +00:00
|
|
|
derror "saving opalcore failed"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sync
|
|
|
|
dinfo "saving opalcore complete"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_to_rootfs()
|
|
|
|
{
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then
|
2021-08-04 16:59:29 +00:00
|
|
|
dinfo "Trying to bring up initqueue for rootfs mount"
|
|
|
|
systemctl start dracut-initqueue
|
|
|
|
fi
|
|
|
|
|
|
|
|
dinfo "Clean up dead systemd services"
|
|
|
|
systemctl cancel
|
|
|
|
dinfo "Waiting for rootfs mount, will timeout after 90 seconds"
|
|
|
|
systemctl start --no-block sysroot.mount
|
|
|
|
|
|
|
|
_loop=0
|
|
|
|
while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do
|
|
|
|
sleep 1
|
|
|
|
_loop=$((_loop + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! is_mounted /sysroot; then
|
|
|
|
derror "Failed to mount rootfs"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
ddebug "NEWROOT=$NEWROOT"
|
|
|
|
dump_fs $NEWROOT
|
|
|
|
}
|
|
|
|
|
|
|
|
kdump_emergency_shell()
|
|
|
|
{
|
|
|
|
ddebug "Switching to kdump emergency shell..."
|
|
|
|
|
|
|
|
[ -f /etc/profile ] && . /etc/profile
|
|
|
|
export PS1='kdump:${PWD}# '
|
|
|
|
|
|
|
|
. /lib/dracut-lib.sh
|
|
|
|
if [ -f /dracut-state.sh ]; then
|
|
|
|
. /dracut-state.sh 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
source_conf /etc/conf.d
|
|
|
|
|
|
|
|
type plymouth >/dev/null 2>&1 && plymouth quit
|
|
|
|
|
|
|
|
source_hook "emergency"
|
2021-08-18 13:06:52 +00:00
|
|
|
while read -r _tty rest; do
|
2021-08-04 16:59:29 +00:00
|
|
|
(
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo 'Entering kdump emergency mode.'
|
|
|
|
echo 'Type "journalctl" to view system logs.'
|
|
|
|
echo 'Type "rdsosreport" to generate a sosreport, you can then'
|
|
|
|
echo 'save it elsewhere and attach it to a bug report.'
|
|
|
|
echo
|
|
|
|
echo
|
2021-08-18 13:06:52 +00:00
|
|
|
) > "/dev/$_tty"
|
2021-08-04 16:59:29 +00:00
|
|
|
done < /proc/consoles
|
|
|
|
sh -i -l
|
|
|
|
/bin/rm -f -- /.console_lock
|
|
|
|
}
|
|
|
|
|
|
|
|
do_failure_action()
|
|
|
|
{
|
|
|
|
dinfo "Executing failure action $FAILURE_ACTION"
|
|
|
|
eval $FAILURE_ACTION
|
|
|
|
}
|
|
|
|
|
|
|
|
do_final_action()
|
|
|
|
{
|
|
|
|
dinfo "Executing final action $FINAL_ACTION"
|
|
|
|
eval $FINAL_ACTION
|
|
|
|
}
|
2021-08-18 13:06:52 +00:00
|
|
|
|
2013-08-02 06:22:23 +00:00
|
|
|
do_dump()
|
|
|
|
{
|
|
|
|
eval $DUMP_INSTRUCTION
|
|
|
|
_ret=$?
|
|
|
|
|
|
|
|
if [ $_ret -ne 0 ]; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "saving vmcore failed"
|
2013-08-02 06:22:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return $_ret
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:57:30 +00:00
|
|
|
do_kdump_pre()
|
|
|
|
{
|
|
|
|
if [ -n "$KDUMP_PRE" ]; then
|
|
|
|
"$KDUMP_PRE"
|
2020-06-05 02:25:12 +00:00
|
|
|
_ret=$?
|
|
|
|
if [ $_ret -ne 0 ]; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "$KDUMP_PRE exited with $_ret status"
|
2020-06-05 02:25:12 +00:00
|
|
|
return $_ret
|
|
|
|
fi
|
2012-06-14 01:57:30 +00:00
|
|
|
fi
|
2020-06-05 02:25:12 +00:00
|
|
|
|
2020-07-15 09:28:04 +00:00
|
|
|
# if any script fails, it just raises warning and continues
|
2020-06-05 02:25:12 +00:00
|
|
|
if [ -d /etc/kdump/pre.d ]; then
|
|
|
|
for file in /etc/kdump/pre.d/*; do
|
|
|
|
"$file"
|
|
|
|
_ret=$?
|
|
|
|
if [ $_ret -ne 0 ]; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "$file exited with $_ret status"
|
2020-06-05 02:25:12 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
return 0
|
2012-06-14 01:57:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 07:50:16 +00:00
|
|
|
do_kdump_post()
|
|
|
|
{
|
2020-06-05 02:25:12 +00:00
|
|
|
if [ -d /etc/kdump/post.d ]; then
|
|
|
|
for file in /etc/kdump/post.d/*; do
|
|
|
|
"$file" "$1"
|
|
|
|
_ret=$?
|
|
|
|
if [ $_ret -ne 0 ]; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "$file exited with $_ret status"
|
2020-06-05 02:25:12 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2015-04-08 07:50:16 +00:00
|
|
|
if [ -n "$KDUMP_POST" ]; then
|
|
|
|
"$KDUMP_POST" "$1"
|
2020-06-05 02:25:12 +00:00
|
|
|
_ret=$?
|
|
|
|
if [ $_ret -ne 0 ]; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "$KDUMP_POST exited with $_ret status"
|
2020-06-05 02:25:12 +00:00
|
|
|
fi
|
2015-04-08 07:50:16 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: block target, eg. /dev/sda
|
2011-08-01 12:01:31 +00:00
|
|
|
dump_raw()
|
|
|
|
{
|
2021-08-18 13:06:52 +00:00
|
|
|
[ -b "$1" ] || return 1
|
2013-06-21 03:23:58 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving to raw disk $1"
|
2013-06-21 03:23:56 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then
|
2021-09-13 19:00:48 +00:00
|
|
|
_src_size=$(stat --format %s /proc/vmcore)
|
2021-08-18 13:06:52 +00:00
|
|
|
_src_size_mb=$((_src_size / 1048576))
|
2021-08-01 17:19:44 +00:00
|
|
|
/kdumpscripts/monitor_dd_progress $_src_size_mb &
|
2012-04-28 10:01:18 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-27 09:04:25 +00:00
|
|
|
dinfo "saving vmcore"
|
2021-08-18 13:06:52 +00:00
|
|
|
$CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1
|
2013-06-26 05:15:18 +00:00
|
|
|
sync
|
2013-06-21 03:23:56 +00:00
|
|
|
|
2020-10-27 09:04:25 +00:00
|
|
|
dinfo "saving vmcore complete"
|
2012-12-19 09:27:40 +00:00
|
|
|
return 0
|
2011-08-01 12:01:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: ssh key file
|
|
|
|
# $2: ssh address in <user>@<host> format
|
2011-07-28 14:50:43 +00:00
|
|
|
dump_ssh()
|
|
|
|
{
|
2021-08-18 13:06:52 +00:00
|
|
|
_ret=0
|
|
|
|
_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
|
|
|
_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
|
|
|
|
if is_ipv6_address "$2"; then
|
|
|
|
_scp_address=${2%@*}@"[${2#*@}]"
|
2021-08-03 05:23:26 +00:00
|
|
|
else
|
2021-08-18 13:06:52 +00:00
|
|
|
_scp_address=$2
|
2021-08-03 05:23:26 +00:00
|
|
|
fi
|
2012-06-14 01:56:10 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving to $2:$_ssh_dir"
|
2013-06-21 03:23:56 +00:00
|
|
|
|
2012-11-14 05:58:37 +00:00
|
|
|
cat /var/lib/random-seed > /dev/urandom
|
2021-08-18 13:06:52 +00:00
|
|
|
ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1
|
2012-06-14 01:56:10 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
|
2020-10-27 09:04:25 +00:00
|
|
|
dinfo "saving vmcore"
|
2013-06-21 03:23:56 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
|
2021-01-14 03:42:01 +00:00
|
|
|
|
2013-05-28 09:53:59 +00:00
|
|
|
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
|
2021-08-18 13:06:52 +00:00
|
|
|
scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
|
|
|
|
_ret=$?
|
|
|
|
_vmcore="vmcore"
|
2012-06-14 01:56:10 +00:00
|
|
|
else
|
2021-08-18 13:06:52 +00:00
|
|
|
$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
|
|
|
|
_ret=$?
|
2020-12-14 09:01:42 +00:00
|
|
|
_vmcore="vmcore.flat"
|
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if [ $_ret -eq 0 ]; then
|
|
|
|
ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
|
|
|
|
_ret=$?
|
|
|
|
if [ $_ret -ne 0 ]; then
|
|
|
|
derror "moving vmcore failed, exitcode:$_ret"
|
2020-12-14 09:01:42 +00:00
|
|
|
else
|
|
|
|
dinfo "saving vmcore complete"
|
2020-10-27 09:04:25 +00:00
|
|
|
fi
|
2020-12-14 09:01:42 +00:00
|
|
|
else
|
2021-08-18 13:06:52 +00:00
|
|
|
derror "saving vmcore failed, exitcode:$_ret"
|
2020-12-14 09:01:42 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/"
|
2020-12-14 09:01:42 +00:00
|
|
|
save_log
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then
|
2020-12-14 09:01:42 +00:00
|
|
|
derror "saving log file failed, _exitcode:$_ret"
|
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
return $_ret
|
2012-06-14 01:56:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: dump path
|
|
|
|
# $2: ssh opts
|
|
|
|
# $3: ssh address in <user>@<host> format
|
|
|
|
# $4: scp address, similar with ssh address but IPv6 addresses are quoted
|
2020-01-28 19:34:48 +00:00
|
|
|
save_opalcore_ssh() {
|
|
|
|
if [ ! -f $OPALCORE ]; then
|
|
|
|
# Check if we are on an old kernel that uses a different path
|
|
|
|
if [ -f /sys/firmware/opal/core ]; then
|
|
|
|
OPALCORE="/sys/firmware/opal/core"
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving opalcore:$OPALCORE to $3:$1"
|
2021-01-14 03:42:01 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "saving opalcore failed"
|
2021-08-18 13:06:52 +00:00
|
|
|
return 1
|
2020-01-28 19:34:48 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
|
2020-10-27 09:04:25 +00:00
|
|
|
dinfo "saving opalcore complete"
|
2020-01-28 19:34:48 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
# $1: dmesg collector
|
|
|
|
# $2: dump path
|
|
|
|
# $3: ssh opts
|
|
|
|
# $4: ssh address in <user>@<host> format
|
2013-05-13 03:13:27 +00:00
|
|
|
save_vmcore_dmesg_ssh() {
|
2021-08-18 13:06:52 +00:00
|
|
|
dinfo "saving vmcore-dmesg.txt to $4:$2"
|
|
|
|
if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
|
|
|
|
ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
2020-10-27 09:04:25 +00:00
|
|
|
dinfo "saving vmcore-dmesg.txt complete"
|
2013-05-13 03:13:27 +00:00
|
|
|
else
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "saving vmcore-dmesg.txt failed"
|
2013-05-13 03:13:27 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 10:32:26 +00:00
|
|
|
get_host_ip()
|
|
|
|
{
|
|
|
|
if is_nfs_dump_target || is_ssh_dump_target
|
|
|
|
then
|
|
|
|
kdumpnic=$(getarg kdumpnic=)
|
2021-08-18 13:06:52 +00:00
|
|
|
if [ -z "$kdumpnic" ]; then
|
|
|
|
derror "failed to get kdumpnic!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then
|
|
|
|
derror "wrong kdumpnic: $kdumpnic"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}')
|
|
|
|
kdumphost="${kdumphost%%/*}"
|
|
|
|
if [ -z "$kdumphost" ]; then
|
|
|
|
derror "wrong kdumpnic: $kdumpnic"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
HOST_IP=$kdumphost
|
2020-05-27 10:32:26 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-08-03 11:49:51 +00:00
|
|
|
read_kdump_confs()
|
2020-05-27 10:32:26 +00:00
|
|
|
{
|
2021-08-03 11:49:51 +00:00
|
|
|
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
|
|
|
|
derror "$KDUMP_CONFIG_FILE not found"
|
2020-05-27 10:32:26 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
get_kdump_confs
|
|
|
|
|
|
|
|
# rescan for add code for dump target
|
2021-08-18 13:06:52 +00:00
|
|
|
while read -r config_opt config_val;
|
2020-05-27 10:32:26 +00:00
|
|
|
do
|
|
|
|
# remove inline comments after the end of a directive.
|
|
|
|
case "$config_opt" in
|
|
|
|
dracut_args)
|
|
|
|
config_val=$(get_dracut_args_target "$config_val")
|
2020-06-11 05:59:14 +00:00
|
|
|
if [ -n "$config_val" ]; then
|
|
|
|
config_val=$(get_mntpoint_from_target "$config_val")
|
2021-08-01 17:25:17 +00:00
|
|
|
DUMP_INSTRUCTION="dump_fs $config_val"
|
2020-06-11 05:59:14 +00:00
|
|
|
fi
|
2020-05-27 10:32:26 +00:00
|
|
|
;;
|
|
|
|
ext[234]|xfs|btrfs|minix|nfs)
|
|
|
|
config_val=$(get_mntpoint_from_target "$config_val")
|
2021-08-01 17:25:17 +00:00
|
|
|
DUMP_INSTRUCTION="dump_fs $config_val"
|
2020-05-27 10:32:26 +00:00
|
|
|
;;
|
|
|
|
raw)
|
2021-08-01 17:25:17 +00:00
|
|
|
DUMP_INSTRUCTION="dump_raw $config_val"
|
2020-05-27 10:32:26 +00:00
|
|
|
;;
|
|
|
|
ssh)
|
2021-08-01 17:25:17 +00:00
|
|
|
DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"
|
2020-05-27 10:32:26 +00:00
|
|
|
;;
|
|
|
|
esac
|
2021-08-18 13:06:52 +00:00
|
|
|
done < "$KDUMP_CONF_PARSED"
|
2020-05-27 10:32:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 07:09:48 +00:00
|
|
|
fence_kdump_notify()
|
|
|
|
{
|
2014-04-02 08:33:47 +00:00
|
|
|
if [ -n "$FENCE_KDUMP_NODES" ]; then
|
2021-08-18 13:06:52 +00:00
|
|
|
# shellcheck disable=SC2086
|
2014-04-02 08:33:47 +00:00
|
|
|
$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &
|
2013-12-20 07:09:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:50:22 +00:00
|
|
|
if [ "$1" = "--error-handler" ]; then
|
|
|
|
get_kdump_confs
|
|
|
|
do_failure_action
|
|
|
|
do_final_action
|
|
|
|
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
# continue here only if we have to save dump.
|
|
|
|
if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-08-03 11:49:51 +00:00
|
|
|
read_kdump_confs
|
2014-04-02 08:33:47 +00:00
|
|
|
fence_kdump_notify
|
2011-07-28 14:50:43 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! get_host_ip; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "get_host_ip exited with non-zero status!"
|
2014-05-08 11:37:16 +00:00
|
|
|
exit 1
|
2012-12-13 05:47:56 +00:00
|
|
|
fi
|
|
|
|
|
2012-06-12 01:42:29 +00:00
|
|
|
if [ -z "$DUMP_INSTRUCTION" ]; then
|
2021-08-01 17:25:17 +00:00
|
|
|
DUMP_INSTRUCTION="dump_fs $NEWROOT"
|
2011-07-28 14:50:43 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! do_kdump_pre; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "kdump_pre script exited with non-zero status!"
|
2013-06-21 03:24:00 +00:00
|
|
|
do_final_action
|
2020-07-08 02:05:25 +00:00
|
|
|
# During systemd service to reboot the machine, stop this shell script running
|
|
|
|
exit 1
|
2012-06-14 01:57:30 +00:00
|
|
|
fi
|
2013-11-19 07:37:53 +00:00
|
|
|
make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab'
|
2013-08-02 06:22:23 +00:00
|
|
|
do_dump
|
2012-06-12 01:42:39 +00:00
|
|
|
DUMP_RETVAL=$?
|
2012-06-14 01:57:30 +00:00
|
|
|
|
2021-08-18 13:06:52 +00:00
|
|
|
if ! do_kdump_post $DUMP_RETVAL; then
|
2020-10-27 09:04:25 +00:00
|
|
|
derror "kdump_post script exited with non-zero status!"
|
2012-06-14 01:57:30 +00:00
|
|
|
fi
|
|
|
|
|
2012-06-12 01:42:39 +00:00
|
|
|
if [ $DUMP_RETVAL -ne 0 ]; then
|
2014-05-08 11:37:16 +00:00
|
|
|
exit 1
|
2012-06-12 01:42:39 +00:00
|
|
|
fi
|
|
|
|
|
2013-06-21 03:24:00 +00:00
|
|
|
do_final_action
|