893e0b
#! /bin/sh
893e0b
893e0b
KEXEC=/sbin/kexec
893e0b
standard_kexec_args="-p"
893e0b
893e0b
EARLY_KDUMP_INITRD=""
893e0b
EARLY_KDUMP_KERNEL=""
893e0b
EARLY_KDUMP_CMDLINE=""
893e0b
EARLY_KDUMP_KERNELVER=""
893e0b
EARLY_KEXEC_ARGS=""
893e0b
893e0b
. /etc/sysconfig/kdump
893e0b
. /lib/dracut-lib.sh
893e0b
. /lib/kdump-lib.sh
893e0b
893e0b
prepare_parameters()
893e0b
{
893e0b
    EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
893e0b
    KDUMP_BOOTDIR=$(check_boot_dir "${KDUMP_BOOTDIR}")
893e0b
603de6
    EARLY_KDUMP_KERNEL="${KDUMP_BOOTDIR}/${KDUMP_IMG}-earlykdump${KDUMP_IMG_EXT}"
603de6
    EARLY_KDUMP_INITRD="${KDUMP_BOOTDIR}/initramfs-earlykdump.img"
893e0b
}
893e0b
893e0b
early_kdump_load()
893e0b
{
893e0b
    check_kdump_feasibility
893e0b
    if [ $? -ne 0 ]; then
893e0b
        return 1
893e0b
    fi
893e0b
893e0b
    if is_fadump_capable; then
893e0b
        echo "WARNING: early kdump doesn't support fadump."
893e0b
        return 1
893e0b
    fi
893e0b
893e0b
    check_current_kdump_status
893e0b
    if [ $? == 0 ]; then
893e0b
        return 1
893e0b
    fi
893e0b
893e0b
    prepare_parameters
893e0b
893e0b
    EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}")
893e0b
893e0b
    if is_secure_boot_enforced; then
893e0b
        echo "Secure Boot is enabled. Using kexec file based syscall."
893e0b
        EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
893e0b
    fi
893e0b
893e0b
    $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
893e0b
        --command-line="$EARLY_KDUMP_CMDLINE" \
893e0b
        --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL
893e0b
    if [ $? == 0 ]; then
893e0b
        echo "kexec: loaded early-kdump kernel"
893e0b
        return 0
893e0b
    else
893e0b
        echo "kexec: failed to load early-kdump kernel"
893e0b
        return 1
893e0b
    fi
893e0b
}
893e0b
893e0b
set_early_kdump()
893e0b
{
893e0b
    if getargbool 0 rd.earlykdump; then
893e0b
        echo "early-kdump is enabled."
893e0b
        early_kdump_load
893e0b
    else
893e0b
        echo "early-kdump is disabled."
893e0b
    fi
893e0b
893e0b
    return 0
893e0b
}
893e0b
893e0b
set_early_kdump