b9e861
#! /bin/sh
b9e861
b9e861
KEXEC=/sbin/kexec
b9e861
standard_kexec_args="-p"
b9e861
b9e861
EARLY_KDUMP_INITRD=""
b9e861
EARLY_KDUMP_KERNEL=""
b9e861
EARLY_KDUMP_CMDLINE=""
b9e861
EARLY_KDUMP_KERNELVER=""
b9e861
EARLY_KEXEC_ARGS=""
b9e861
b9e861
. /etc/sysconfig/kdump
b9e861
. /lib/dracut-lib.sh
b9e861
. /lib/kdump-lib.sh
b9e861
54b5ae
#initiate the kdump logger
54b5ae
dlog_init
54b5ae
if [ $? -ne 0 ]; then
54b5ae
        echo "failed to initiate the kdump logger."
54b5ae
        exit 1
54b5ae
fi
54b5ae
b9e861
prepare_parameters()
b9e861
{
b9e861
    EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
e97a90
    EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump"
e97a90
    EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump"
b9e861
}
b9e861
b9e861
early_kdump_load()
b9e861
{
b9e861
    check_kdump_feasibility
b9e861
    if [ $? -ne 0 ]; then
b9e861
        return 1
b9e861
    fi
b9e861
b9e861
    if is_fadump_capable; then
54b5ae
        dwarn "WARNING: early kdump doesn't support fadump."
b9e861
        return 1
b9e861
    fi
b9e861
b9e861
    check_current_kdump_status
b9e861
    if [ $? == 0 ]; then
b9e861
        return 1
b9e861
    fi
b9e861
b9e861
    prepare_parameters
b9e861
b9e861
    EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}")
b9e861
e7b8b8
    if is_secure_boot_enforced; then
54b5ae
        dinfo "Secure Boot is enabled. Using kexec file based syscall."
b9e861
        EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
b9e861
    fi
b9e861
54b5ae
    # Here, only output the messages, but do not save these messages
54b5ae
    # to a file because the target disk may not be mounted yet, the
54b5ae
    # earlykdump is too early.
54b5ae
    ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
54b5ae
	--command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \
54b5ae
	$EARLY_KDUMP_KERNEL"
54b5ae
b9e861
    $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
b9e861
        --command-line="$EARLY_KDUMP_CMDLINE" \
b9e861
        --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL
b9e861
    if [ $? == 0 ]; then
54b5ae
        dinfo "kexec: loaded early-kdump kernel"
b9e861
        return 0
b9e861
    else
54b5ae
        derror "kexec: failed to load early-kdump kernel"
b9e861
        return 1
b9e861
    fi
b9e861
}
b9e861
b9e861
set_early_kdump()
b9e861
{
b9e861
    if getargbool 0 rd.earlykdump; then
54b5ae
        dinfo "early-kdump is enabled."
b9e861
        early_kdump_load
b9e861
    else
54b5ae
        dinfo "early-kdump is disabled."
b9e861
    fi
b9e861
b9e861
    return 0
b9e861
}
b9e861
b9e861
set_early_kdump