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
b9e861
prepare_parameters()
b9e861
{
b9e861
    EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
b9e861
    KDUMP_BOOTDIR=$(check_boot_dir "${KDUMP_BOOTDIR}")
b9e861
b9e861
    EARLY_KDUMP_KERNEL="${KDUMP_BOOTDIR}/${KDUMP_IMG}-earlykdump${KDUMP_IMG_EXT}"
b9e861
    EARLY_KDUMP_INITRD="${KDUMP_BOOTDIR}/initramfs-earlykdump.img"
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
b9e861
        echo "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
e7b8b8
        echo "Secure Boot is enabled. Using kexec file based syscall."
b9e861
        EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
b9e861
    fi
b9e861
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
b9e861
        echo "kexec: loaded early-kdump kernel"
b9e861
        return 0
b9e861
    else
b9e861
        echo "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
b9e861
        echo "early-kdump is enabled."
b9e861
        early_kdump_load
b9e861
    else
b9e861
        echo "early-kdump is disabled."
b9e861
    fi
b9e861
b9e861
    return 0
b9e861
}
b9e861
b9e861
set_early_kdump