dracut-kdump.sh: reformat with shfmt
upstream: fedora
resolves: bz2003832
conflict: none
commit 7c76611abb
Author: Kairui Song <kasong@redhat.com>
Date: Wed Sep 15 23:10:07 2021 +0800
dracut-kdump.sh: reformat with shfmt
This is done with `shfmt -w -s dracut-kdump.sh`. There is no behaviour
change.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
parent
eb6eafaf18
commit
5e60aafcaf
768
dracut-kdump.sh
768
dracut-kdump.sh
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#initiate the kdump logger
|
#initiate the kdump logger
|
||||||
if ! dlog_init; then
|
if ! dlog_init; then
|
||||||
echo "failed to initiate the kdump logger."
|
echo "failed to initiate the kdump logger."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
KDUMP_PATH="/var/crash"
|
KDUMP_PATH="/var/crash"
|
||||||
@ -41,541 +41,543 @@ kdump_read_conf > $KDUMP_CONF_PARSED
|
|||||||
|
|
||||||
get_kdump_confs()
|
get_kdump_confs()
|
||||||
{
|
{
|
||||||
while read -r config_opt config_val; do
|
while read -r config_opt config_val; do
|
||||||
# remove inline comments after the end of a directive.
|
# remove inline comments after the end of a directive.
|
||||||
case "$config_opt" in
|
case "$config_opt" in
|
||||||
path)
|
path)
|
||||||
KDUMP_PATH="$config_val"
|
KDUMP_PATH="$config_val"
|
||||||
;;
|
;;
|
||||||
core_collector)
|
core_collector)
|
||||||
[ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
|
[ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
|
||||||
;;
|
;;
|
||||||
sshkey)
|
sshkey)
|
||||||
if [ -f "$config_val" ]; then
|
if [ -f "$config_val" ]; then
|
||||||
SSH_KEY_LOCATION=$config_val
|
SSH_KEY_LOCATION=$config_val
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
kdump_pre)
|
kdump_pre)
|
||||||
KDUMP_PRE="$config_val"
|
KDUMP_PRE="$config_val"
|
||||||
;;
|
;;
|
||||||
kdump_post)
|
kdump_post)
|
||||||
KDUMP_POST="$config_val"
|
KDUMP_POST="$config_val"
|
||||||
;;
|
;;
|
||||||
fence_kdump_args)
|
fence_kdump_args)
|
||||||
FENCE_KDUMP_ARGS="$config_val"
|
FENCE_KDUMP_ARGS="$config_val"
|
||||||
;;
|
;;
|
||||||
fence_kdump_nodes)
|
fence_kdump_nodes)
|
||||||
FENCE_KDUMP_NODES="$config_val"
|
FENCE_KDUMP_NODES="$config_val"
|
||||||
;;
|
;;
|
||||||
failure_action|default)
|
failure_action | default)
|
||||||
case $config_val in
|
case $config_val in
|
||||||
shell)
|
shell)
|
||||||
FAILURE_ACTION="kdump_emergency_shell"
|
FAILURE_ACTION="kdump_emergency_shell"
|
||||||
;;
|
;;
|
||||||
reboot)
|
reboot)
|
||||||
FAILURE_ACTION="systemctl reboot -f && exit"
|
FAILURE_ACTION="systemctl reboot -f && exit"
|
||||||
;;
|
;;
|
||||||
halt)
|
halt)
|
||||||
FAILURE_ACTION="halt && exit"
|
FAILURE_ACTION="halt && exit"
|
||||||
;;
|
;;
|
||||||
poweroff)
|
poweroff)
|
||||||
FAILURE_ACTION="systemctl poweroff -f && exit"
|
FAILURE_ACTION="systemctl poweroff -f && exit"
|
||||||
;;
|
;;
|
||||||
dump_to_rootfs)
|
dump_to_rootfs)
|
||||||
FAILURE_ACTION="dump_to_rootfs"
|
FAILURE_ACTION="dump_to_rootfs"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
final_action)
|
final_action)
|
||||||
case $config_val in
|
case $config_val in
|
||||||
reboot)
|
reboot)
|
||||||
FINAL_ACTION="systemctl reboot -f"
|
FINAL_ACTION="systemctl reboot -f"
|
||||||
;;
|
;;
|
||||||
halt)
|
halt)
|
||||||
FINAL_ACTION="halt"
|
FINAL_ACTION="halt"
|
||||||
;;
|
;;
|
||||||
poweroff)
|
poweroff)
|
||||||
FINAL_ACTION="systemctl poweroff -f"
|
FINAL_ACTION="systemctl poweroff -f"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done < "$KDUMP_CONF_PARSED"
|
done < "$KDUMP_CONF_PARSED"
|
||||||
|
|
||||||
if [ -z "$CORE_COLLECTOR" ]; then
|
if [ -z "$CORE_COLLECTOR" ]; then
|
||||||
CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
|
CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
|
||||||
if is_ssh_dump_target || is_raw_dump_target; then
|
if is_ssh_dump_target || is_raw_dump_target; then
|
||||||
CORE_COLLECTOR="$CORE_COLLECTOR -F"
|
CORE_COLLECTOR="$CORE_COLLECTOR -F"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# store the kexec kernel log to a file.
|
# store the kexec kernel log to a file.
|
||||||
save_log()
|
save_log()
|
||||||
{
|
{
|
||||||
dmesg -T > $KDUMP_LOG_FILE
|
dmesg -T > $KDUMP_LOG_FILE
|
||||||
|
|
||||||
if command -v journalctl > /dev/null; then
|
if command -v journalctl > /dev/null; then
|
||||||
journalctl -ab >> $KDUMP_LOG_FILE
|
journalctl -ab >> $KDUMP_LOG_FILE
|
||||||
fi
|
fi
|
||||||
chmod 600 $KDUMP_LOG_FILE
|
chmod 600 $KDUMP_LOG_FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: dump path, must be a mount point
|
# $1: dump path, must be a mount point
|
||||||
dump_fs()
|
dump_fs()
|
||||||
{
|
{
|
||||||
ddebug "dump_fs _mp=$1"
|
ddebug "dump_fs _mp=$1"
|
||||||
|
|
||||||
if ! is_mounted "$1"; then
|
if ! is_mounted "$1"; then
|
||||||
dinfo "dump path '$1' is not mounted, trying to mount..."
|
dinfo "dump path '$1' is not mounted, trying to mount..."
|
||||||
if ! mount --target "$1"; then
|
if ! mount --target "$1"; then
|
||||||
derror "failed to dump to '$1', it's not a mount point!"
|
derror "failed to dump to '$1', it's not a mount point!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove -F in makedumpfile case. We don't want a flat format dump here.
|
# Remove -F in makedumpfile case. We don't want a flat format dump here.
|
||||||
case $CORE_COLLECTOR in
|
case $CORE_COLLECTOR in
|
||||||
*makedumpfile* )
|
*makedumpfile*)
|
||||||
CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
|
CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
|
_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
|
||||||
dinfo "saving to $_dump_fs_path"
|
dinfo "saving to $_dump_fs_path"
|
||||||
|
|
||||||
# Only remount to read-write mode if the dump target is mounted read-only.
|
# Only remount to read-write mode if the dump target is mounted read-only.
|
||||||
_dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f)
|
_dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f)
|
||||||
case $_dump_mnt_op in
|
case $_dump_mnt_op in
|
||||||
ro* )
|
ro*)
|
||||||
dinfo "Remounting the dump target in rw mode."
|
dinfo "Remounting the dump target in rw mode."
|
||||||
mount -o remount,rw "$1" || return 1
|
mount -o remount,rw "$1" || return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
mkdir -p "$_dump_fs_path" || return 1
|
mkdir -p "$_dump_fs_path" || return 1
|
||||||
|
|
||||||
save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"
|
save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"
|
||||||
save_opalcore_fs "$_dump_fs_path"
|
save_opalcore_fs "$_dump_fs_path"
|
||||||
|
|
||||||
dinfo "saving vmcore"
|
dinfo "saving vmcore"
|
||||||
$CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete"
|
$CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete"
|
||||||
_dump_exitcode=$?
|
_dump_exitcode=$?
|
||||||
if [ $_dump_exitcode -eq 0 ]; then
|
if [ $_dump_exitcode -eq 0 ]; then
|
||||||
mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore"
|
mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore"
|
||||||
sync
|
sync
|
||||||
dinfo "saving vmcore complete"
|
dinfo "saving vmcore complete"
|
||||||
else
|
else
|
||||||
derror "saving vmcore failed, exitcode:$_dump_exitcode"
|
derror "saving vmcore failed, exitcode:$_dump_exitcode"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/"
|
dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/"
|
||||||
save_log
|
save_log
|
||||||
mv "$KDUMP_LOG_FILE" "$_dump_fs_path/"
|
mv "$KDUMP_LOG_FILE" "$_dump_fs_path/"
|
||||||
if [ $_dump_exitcode -ne 0 ]; then
|
if [ $_dump_exitcode -ne 0 ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure
|
# improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: dmesg collector
|
# $1: dmesg collector
|
||||||
# $2: dump path
|
# $2: dump path
|
||||||
save_vmcore_dmesg_fs() {
|
save_vmcore_dmesg_fs()
|
||||||
dinfo "saving vmcore-dmesg.txt to $2"
|
{
|
||||||
if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then
|
dinfo "saving vmcore-dmesg.txt to $2"
|
||||||
mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then
|
||||||
chmod 600 "$2/vmcore-dmesg.txt"
|
mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
||||||
|
chmod 600 "$2/vmcore-dmesg.txt"
|
||||||
|
|
||||||
# Make sure file is on disk. There have been instances where later
|
# Make sure file is on disk. There have been instances where later
|
||||||
# saving vmcore failed and system rebooted without sync and there
|
# saving vmcore failed and system rebooted without sync and there
|
||||||
# was no vmcore-dmesg.txt available.
|
# was no vmcore-dmesg.txt available.
|
||||||
sync
|
sync
|
||||||
dinfo "saving vmcore-dmesg.txt complete"
|
dinfo "saving vmcore-dmesg.txt complete"
|
||||||
else
|
else
|
||||||
if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then
|
if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then
|
||||||
chmod 600 "$2/vmcore-dmesg-incomplete.txt"
|
chmod 600 "$2/vmcore-dmesg-incomplete.txt"
|
||||||
fi
|
fi
|
||||||
derror "saving vmcore-dmesg.txt failed"
|
derror "saving vmcore-dmesg.txt failed"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: dump path
|
# $1: dump path
|
||||||
save_opalcore_fs() {
|
save_opalcore_fs()
|
||||||
if [ ! -f $OPALCORE ]; then
|
{
|
||||||
# Check if we are on an old kernel that uses a different path
|
if [ ! -f $OPALCORE ]; then
|
||||||
if [ -f /sys/firmware/opal/core ]; then
|
# Check if we are on an old kernel that uses a different path
|
||||||
OPALCORE="/sys/firmware/opal/core"
|
if [ -f /sys/firmware/opal/core ]; then
|
||||||
else
|
OPALCORE="/sys/firmware/opal/core"
|
||||||
return 0
|
else
|
||||||
fi
|
return 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
dinfo "saving opalcore:$OPALCORE to $1/opalcore"
|
dinfo "saving opalcore:$OPALCORE to $1/opalcore"
|
||||||
if ! cp $OPALCORE "$1/opalcore"; then
|
if ! cp $OPALCORE "$1/opalcore"; then
|
||||||
derror "saving opalcore failed"
|
derror "saving opalcore failed"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sync
|
sync
|
||||||
dinfo "saving opalcore complete"
|
dinfo "saving opalcore complete"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_to_rootfs()
|
dump_to_rootfs()
|
||||||
{
|
{
|
||||||
|
|
||||||
if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then
|
if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then
|
||||||
dinfo "Trying to bring up initqueue for rootfs mount"
|
dinfo "Trying to bring up initqueue for rootfs mount"
|
||||||
systemctl start dracut-initqueue
|
systemctl start dracut-initqueue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dinfo "Clean up dead systemd services"
|
dinfo "Clean up dead systemd services"
|
||||||
systemctl cancel
|
systemctl cancel
|
||||||
dinfo "Waiting for rootfs mount, will timeout after 90 seconds"
|
dinfo "Waiting for rootfs mount, will timeout after 90 seconds"
|
||||||
systemctl start --no-block sysroot.mount
|
systemctl start --no-block sysroot.mount
|
||||||
|
|
||||||
_loop=0
|
_loop=0
|
||||||
while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do
|
while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do
|
||||||
sleep 1
|
sleep 1
|
||||||
_loop=$((_loop + 1))
|
_loop=$((_loop + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! is_mounted /sysroot; then
|
if ! is_mounted /sysroot; then
|
||||||
derror "Failed to mount rootfs"
|
derror "Failed to mount rootfs"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ddebug "NEWROOT=$NEWROOT"
|
ddebug "NEWROOT=$NEWROOT"
|
||||||
dump_fs $NEWROOT
|
dump_fs $NEWROOT
|
||||||
}
|
}
|
||||||
|
|
||||||
kdump_emergency_shell()
|
kdump_emergency_shell()
|
||||||
{
|
{
|
||||||
ddebug "Switching to kdump emergency shell..."
|
ddebug "Switching to kdump emergency shell..."
|
||||||
|
|
||||||
[ -f /etc/profile ] && . /etc/profile
|
[ -f /etc/profile ] && . /etc/profile
|
||||||
export PS1='kdump:${PWD}# '
|
export PS1='kdump:${PWD}# '
|
||||||
|
|
||||||
. /lib/dracut-lib.sh
|
. /lib/dracut-lib.sh
|
||||||
if [ -f /dracut-state.sh ]; then
|
if [ -f /dracut-state.sh ]; then
|
||||||
. /dracut-state.sh 2>/dev/null
|
. /dracut-state.sh 2> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source_conf /etc/conf.d
|
source_conf /etc/conf.d
|
||||||
|
|
||||||
type plymouth >/dev/null 2>&1 && plymouth quit
|
type plymouth > /dev/null 2>&1 && plymouth quit
|
||||||
|
|
||||||
source_hook "emergency"
|
source_hook "emergency"
|
||||||
while read -r _tty rest; do
|
while read -r _tty rest; do
|
||||||
(
|
(
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo 'Entering kdump emergency mode.'
|
echo 'Entering kdump emergency mode.'
|
||||||
echo 'Type "journalctl" to view system logs.'
|
echo 'Type "journalctl" to view system logs.'
|
||||||
echo 'Type "rdsosreport" to generate a sosreport, you can then'
|
echo 'Type "rdsosreport" to generate a sosreport, you can then'
|
||||||
echo 'save it elsewhere and attach it to a bug report.'
|
echo 'save it elsewhere and attach it to a bug report.'
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
) > "/dev/$_tty"
|
) > "/dev/$_tty"
|
||||||
done < /proc/consoles
|
done < /proc/consoles
|
||||||
sh -i -l
|
sh -i -l
|
||||||
/bin/rm -f -- /.console_lock
|
/bin/rm -f -- /.console_lock
|
||||||
}
|
}
|
||||||
|
|
||||||
do_failure_action()
|
do_failure_action()
|
||||||
{
|
{
|
||||||
dinfo "Executing failure action $FAILURE_ACTION"
|
dinfo "Executing failure action $FAILURE_ACTION"
|
||||||
eval $FAILURE_ACTION
|
eval $FAILURE_ACTION
|
||||||
}
|
}
|
||||||
|
|
||||||
do_final_action()
|
do_final_action()
|
||||||
{
|
{
|
||||||
dinfo "Executing final action $FINAL_ACTION"
|
dinfo "Executing final action $FINAL_ACTION"
|
||||||
eval $FINAL_ACTION
|
eval $FINAL_ACTION
|
||||||
}
|
}
|
||||||
|
|
||||||
do_dump()
|
do_dump()
|
||||||
{
|
{
|
||||||
eval $DUMP_INSTRUCTION
|
eval $DUMP_INSTRUCTION
|
||||||
_ret=$?
|
_ret=$?
|
||||||
|
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "saving vmcore failed"
|
derror "saving vmcore failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $_ret
|
return $_ret
|
||||||
}
|
}
|
||||||
|
|
||||||
do_kdump_pre()
|
do_kdump_pre()
|
||||||
{
|
{
|
||||||
if [ -n "$KDUMP_PRE" ]; then
|
if [ -n "$KDUMP_PRE" ]; then
|
||||||
"$KDUMP_PRE"
|
"$KDUMP_PRE"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "$KDUMP_PRE exited with $_ret status"
|
derror "$KDUMP_PRE exited with $_ret status"
|
||||||
return $_ret
|
return $_ret
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if any script fails, it just raises warning and continues
|
# if any script fails, it just raises warning and continues
|
||||||
if [ -d /etc/kdump/pre.d ]; then
|
if [ -d /etc/kdump/pre.d ]; then
|
||||||
for file in /etc/kdump/pre.d/*; do
|
for file in /etc/kdump/pre.d/*; do
|
||||||
"$file"
|
"$file"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "$file exited with $_ret status"
|
derror "$file exited with $_ret status"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
do_kdump_post()
|
do_kdump_post()
|
||||||
{
|
{
|
||||||
if [ -d /etc/kdump/post.d ]; then
|
if [ -d /etc/kdump/post.d ]; then
|
||||||
for file in /etc/kdump/post.d/*; do
|
for file in /etc/kdump/post.d/*; do
|
||||||
"$file" "$1"
|
"$file" "$1"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "$file exited with $_ret status"
|
derror "$file exited with $_ret status"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$KDUMP_POST" ]; then
|
if [ -n "$KDUMP_POST" ]; then
|
||||||
"$KDUMP_POST" "$1"
|
"$KDUMP_POST" "$1"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "$KDUMP_POST exited with $_ret status"
|
derror "$KDUMP_POST exited with $_ret status"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: block target, eg. /dev/sda
|
# $1: block target, eg. /dev/sda
|
||||||
dump_raw()
|
dump_raw()
|
||||||
{
|
{
|
||||||
[ -b "$1" ] || return 1
|
[ -b "$1" ] || return 1
|
||||||
|
|
||||||
dinfo "saving to raw disk $1"
|
dinfo "saving to raw disk $1"
|
||||||
|
|
||||||
if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then
|
if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then
|
||||||
_src_size=$(stat --format %s /proc/vmcore)
|
_src_size=$(stat --format %s /proc/vmcore)
|
||||||
_src_size_mb=$((_src_size / 1048576))
|
_src_size_mb=$((_src_size / 1048576))
|
||||||
/kdumpscripts/monitor_dd_progress $_src_size_mb &
|
/kdumpscripts/monitor_dd_progress $_src_size_mb &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dinfo "saving vmcore"
|
dinfo "saving vmcore"
|
||||||
$CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1
|
$CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1
|
||||||
sync
|
sync
|
||||||
|
|
||||||
dinfo "saving vmcore complete"
|
dinfo "saving vmcore complete"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: ssh key file
|
# $1: ssh key file
|
||||||
# $2: ssh address in <user>@<host> format
|
# $2: ssh address in <user>@<host> format
|
||||||
dump_ssh()
|
dump_ssh()
|
||||||
{
|
{
|
||||||
_ret=0
|
_ret=0
|
||||||
_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
||||||
_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
|
_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
|
||||||
if is_ipv6_address "$2"; then
|
if is_ipv6_address "$2"; then
|
||||||
_scp_address=${2%@*}@"[${2#*@}]"
|
_scp_address=${2%@*}@"[${2#*@}]"
|
||||||
else
|
else
|
||||||
_scp_address=$2
|
_scp_address=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dinfo "saving to $2:$_ssh_dir"
|
dinfo "saving to $2:$_ssh_dir"
|
||||||
|
|
||||||
cat /var/lib/random-seed > /dev/urandom
|
cat /var/lib/random-seed > /dev/urandom
|
||||||
ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1
|
ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1
|
||||||
|
|
||||||
save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
|
save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
|
||||||
dinfo "saving vmcore"
|
dinfo "saving vmcore"
|
||||||
|
|
||||||
save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
|
save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
|
||||||
|
|
||||||
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
|
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
|
||||||
scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
|
scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
_vmcore="vmcore"
|
_vmcore="vmcore"
|
||||||
else
|
else
|
||||||
$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
|
$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
_vmcore="vmcore.flat"
|
_vmcore="vmcore.flat"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $_ret -eq 0 ]; then
|
if [ $_ret -eq 0 ]; then
|
||||||
ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
|
ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
|
||||||
_ret=$?
|
_ret=$?
|
||||||
if [ $_ret -ne 0 ]; then
|
if [ $_ret -ne 0 ]; then
|
||||||
derror "moving vmcore failed, exitcode:$_ret"
|
derror "moving vmcore failed, exitcode:$_ret"
|
||||||
else
|
else
|
||||||
dinfo "saving vmcore complete"
|
dinfo "saving vmcore complete"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
derror "saving vmcore failed, exitcode:$_ret"
|
derror "saving vmcore failed, exitcode:$_ret"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/"
|
dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/"
|
||||||
save_log
|
save_log
|
||||||
if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then
|
if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then
|
||||||
derror "saving log file failed, _exitcode:$_ret"
|
derror "saving log file failed, _exitcode:$_ret"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $_ret
|
return $_ret
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: dump path
|
# $1: dump path
|
||||||
# $2: ssh opts
|
# $2: ssh opts
|
||||||
# $3: ssh address in <user>@<host> format
|
# $3: ssh address in <user>@<host> format
|
||||||
# $4: scp address, similar with ssh address but IPv6 addresses are quoted
|
# $4: scp address, similar with ssh address but IPv6 addresses are quoted
|
||||||
save_opalcore_ssh() {
|
save_opalcore_ssh()
|
||||||
if [ ! -f $OPALCORE ]; then
|
{
|
||||||
# Check if we are on an old kernel that uses a different path
|
if [ ! -f $OPALCORE ]; then
|
||||||
if [ -f /sys/firmware/opal/core ]; then
|
# Check if we are on an old kernel that uses a different path
|
||||||
OPALCORE="/sys/firmware/opal/core"
|
if [ -f /sys/firmware/opal/core ]; then
|
||||||
else
|
OPALCORE="/sys/firmware/opal/core"
|
||||||
return 0
|
else
|
||||||
fi
|
return 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
dinfo "saving opalcore:$OPALCORE to $3:$1"
|
dinfo "saving opalcore:$OPALCORE to $3:$1"
|
||||||
|
|
||||||
if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
|
if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
|
||||||
derror "saving opalcore failed"
|
derror "saving opalcore failed"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
|
ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
|
||||||
dinfo "saving opalcore complete"
|
dinfo "saving opalcore complete"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: dmesg collector
|
# $1: dmesg collector
|
||||||
# $2: dump path
|
# $2: dump path
|
||||||
# $3: ssh opts
|
# $3: ssh opts
|
||||||
# $4: ssh address in <user>@<host> format
|
# $4: ssh address in <user>@<host> format
|
||||||
save_vmcore_dmesg_ssh() {
|
save_vmcore_dmesg_ssh()
|
||||||
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
|
dinfo "saving vmcore-dmesg.txt to $4:$2"
|
||||||
ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
|
||||||
dinfo "saving vmcore-dmesg.txt complete"
|
ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
|
||||||
else
|
dinfo "saving vmcore-dmesg.txt complete"
|
||||||
derror "saving vmcore-dmesg.txt failed"
|
else
|
||||||
fi
|
derror "saving vmcore-dmesg.txt failed"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_host_ip()
|
get_host_ip()
|
||||||
{
|
{
|
||||||
if is_nfs_dump_target || is_ssh_dump_target
|
if is_nfs_dump_target || is_ssh_dump_target; then
|
||||||
then
|
kdumpnic=$(getarg kdumpnic=)
|
||||||
kdumpnic=$(getarg kdumpnic=)
|
if [ -z "$kdumpnic" ]; then
|
||||||
if [ -z "$kdumpnic" ]; then
|
derror "failed to get kdumpnic!"
|
||||||
derror "failed to get kdumpnic!"
|
return 1
|
||||||
return 1
|
fi
|
||||||
fi
|
if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then
|
||||||
if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then
|
derror "wrong kdumpnic: $kdumpnic"
|
||||||
derror "wrong kdumpnic: $kdumpnic"
|
return 1
|
||||||
return 1
|
fi
|
||||||
fi
|
kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}')
|
||||||
kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}')
|
kdumphost="${kdumphost%%/*}"
|
||||||
kdumphost="${kdumphost%%/*}"
|
if [ -z "$kdumphost" ]; then
|
||||||
if [ -z "$kdumphost" ]; then
|
derror "wrong kdumpnic: $kdumpnic"
|
||||||
derror "wrong kdumpnic: $kdumpnic"
|
return 1
|
||||||
return 1
|
fi
|
||||||
fi
|
HOST_IP=$kdumphost
|
||||||
HOST_IP=$kdumphost
|
fi
|
||||||
fi
|
return 0
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
read_kdump_confs()
|
read_kdump_confs()
|
||||||
{
|
{
|
||||||
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
|
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
|
||||||
derror "$KDUMP_CONFIG_FILE not found"
|
derror "$KDUMP_CONFIG_FILE not found"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
get_kdump_confs
|
get_kdump_confs
|
||||||
|
|
||||||
# rescan for add code for dump target
|
# rescan for add code for dump target
|
||||||
while read -r config_opt config_val;
|
while read -r config_opt config_val; do
|
||||||
do
|
# remove inline comments after the end of a directive.
|
||||||
# remove inline comments after the end of a directive.
|
case "$config_opt" in
|
||||||
case "$config_opt" in
|
dracut_args)
|
||||||
dracut_args)
|
config_val=$(get_dracut_args_target "$config_val")
|
||||||
config_val=$(get_dracut_args_target "$config_val")
|
if [ -n "$config_val" ]; then
|
||||||
if [ -n "$config_val" ]; then
|
config_val=$(get_mntpoint_from_target "$config_val")
|
||||||
config_val=$(get_mntpoint_from_target "$config_val")
|
DUMP_INSTRUCTION="dump_fs $config_val"
|
||||||
DUMP_INSTRUCTION="dump_fs $config_val"
|
fi
|
||||||
fi
|
;;
|
||||||
;;
|
ext[234] | xfs | btrfs | minix | nfs)
|
||||||
ext[234]|xfs|btrfs|minix|nfs)
|
config_val=$(get_mntpoint_from_target "$config_val")
|
||||||
config_val=$(get_mntpoint_from_target "$config_val")
|
DUMP_INSTRUCTION="dump_fs $config_val"
|
||||||
DUMP_INSTRUCTION="dump_fs $config_val"
|
;;
|
||||||
;;
|
raw)
|
||||||
raw)
|
DUMP_INSTRUCTION="dump_raw $config_val"
|
||||||
DUMP_INSTRUCTION="dump_raw $config_val"
|
;;
|
||||||
;;
|
ssh)
|
||||||
ssh)
|
DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"
|
||||||
DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"
|
;;
|
||||||
;;
|
esac
|
||||||
esac
|
done < "$KDUMP_CONF_PARSED"
|
||||||
done < "$KDUMP_CONF_PARSED"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fence_kdump_notify()
|
fence_kdump_notify()
|
||||||
{
|
{
|
||||||
if [ -n "$FENCE_KDUMP_NODES" ]; then
|
if [ -n "$FENCE_KDUMP_NODES" ]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &
|
$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" = "--error-handler" ]; then
|
if [ "$1" = "--error-handler" ]; then
|
||||||
get_kdump_confs
|
get_kdump_confs
|
||||||
do_failure_action
|
do_failure_action
|
||||||
do_final_action
|
do_final_action
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# continue here only if we have to save dump.
|
# 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
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read_kdump_confs
|
read_kdump_confs
|
||||||
fence_kdump_notify
|
fence_kdump_notify
|
||||||
|
|
||||||
if ! get_host_ip; then
|
if ! get_host_ip; then
|
||||||
derror "get_host_ip exited with non-zero status!"
|
derror "get_host_ip exited with non-zero status!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DUMP_INSTRUCTION" ]; then
|
if [ -z "$DUMP_INSTRUCTION" ]; then
|
||||||
DUMP_INSTRUCTION="dump_fs $NEWROOT"
|
DUMP_INSTRUCTION="dump_fs $NEWROOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! do_kdump_pre; then
|
if ! do_kdump_pre; then
|
||||||
derror "kdump_pre script exited with non-zero status!"
|
derror "kdump_pre script exited with non-zero status!"
|
||||||
do_final_action
|
do_final_action
|
||||||
# During systemd service to reboot the machine, stop this shell script running
|
# During systemd service to reboot the machine, stop this shell script running
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab'
|
make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab'
|
||||||
do_dump
|
do_dump
|
||||||
DUMP_RETVAL=$?
|
DUMP_RETVAL=$?
|
||||||
|
|
||||||
if ! do_kdump_post $DUMP_RETVAL; then
|
if ! do_kdump_post $DUMP_RETVAL; then
|
||||||
derror "kdump_post script exited with non-zero status!"
|
derror "kdump_post script exited with non-zero status!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $DUMP_RETVAL -ne 0 ]; then
|
if [ $DUMP_RETVAL -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
do_final_action
|
do_final_action
|
||||||
|
Loading…
Reference in New Issue
Block a user