
  .   �_’I|¥‰ÓMjqØ‚¦ð¬÷a–Ým_J*j"Tâ�jàApM©‹FÿÄ      File not found.
  1   ˆl–äY>”ÊC]Šq@½p!¸ÓjbÑ¿Ç„m¿_ŒuÐb&=LyYÿÀÆ <7    #!/usr/bin/sh
#
# The main kdump routine in capture kernel, bash may not be the
# default shell. Any code added must be POSIX compliant.

. /lib/dracut-lib.sh
. /lib/kdump-logger.sh
. /lib/kdump-lib-initramfs.sh

#initiate the kdump logger
if ! dlog_init; then
	echo "failed to initiate the kdump logger."
	exit 1
fi

KDUMP_PATH="/var/crash"
KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log"
KDUMP_TEST_ID=""
KDUMP_TEST_STATUS=""
CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"
DMESG_COLLECTOR="/sbin/vmcore-dmesg"
FAILURE_ACTION="systemctl reboot -f"
DATEDIR=$(date +%Y-%m-%d-%T)
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"
KDUMP_CONF_PARSED="/tmp/kdump.conf.$$"

# POSIX doesn't have pipefail, only apply when using bash
# shellcheck disable=SC3040
[ -n "$BASH" ] && set -o pipefail

DUMP_RETVAL=0

kdump_read_conf > $KDUMP_CONF_PARSED

get_kdump_confs()
{
	while read -r config_opt config_val; do
		# 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
	done < "$KDUMP_CONF_PARSED"

	case $CORE_COLLECTOR in
	    *makedumpfile*)
	        # Ensure no -F in makedumpfile by default.
	        CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
	        if is_ssh_dump_target || is_raw_dump_target; then
	            CORE_COLLECTOR="$CORE_COLLECTOR -F"
	        fi
	        THREADS=$(nproc)
	        if [ "$THREADS" -gt 1 ]; then
	            case "$CORE_COLLECTOR" in
	                *-F* | *-E*) ;;

	               *)
	                    CORE_COLLECTOR="$CORE_COLLECTOR --num-threads=$THREADS"
	                    ;;
	            esac
	        fi
	        ;;
	esac
}

# 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
}

# $1: dump path, must be a mount point
dump_fs()
{
	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!"
			return 1
		fi
	fi

	if [ -z "$KDUMP_TEST_ID" ]; then
		_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
	else
		_dump_fs_path=$(echo "$1/$KDUMP_PATH/" | tr -s /)
	fi

	dinfo "saving to $_dump_fs_path"

	# Only remount to read-write mode if the dump target is mounted read-only.
	_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

	mkdir -p "$_dump_fs_path" || return 1

	save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"
	save_opalcore_fs "$_dump_fs_path"

	dinfo "saving vmcore"
	$CORE_COLLECTOR /proc/vmcore "$_dump_fs_pat