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
8f4abc
. /lib/kdump-logger.sh
8f4abc
8f4abc
#initiate the kdump logger
8f4abc
dlog_init
8f4abc
if [ $? -ne 0 ]; then
8f4abc
        echo "failed to initiate the kdump logger."
8f4abc
        exit 1
8f4abc
fi
893e0b
893e0b
prepare_parameters()
893e0b
{
893e0b
    EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
16c266
    EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump"
16c266
    EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump"
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
8f4abc
        dwarn "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
8f4abc
        dinfo "Secure Boot is enabled. Using kexec file based syscall."
893e0b
        EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
893e0b
    fi
893e0b
8f4abc
    # Here, only output the messages, but do not save these messages
8f4abc
    # to a file because the target disk may not be mounted yet, the
8f4abc
    # earlykdump is too early.
8f4abc
    ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
8f4abc
	--command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \
8f4abc
	$EARLY_KDUMP_KERNEL"
8f4abc
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
8f4abc
        dinfo "kexec: loaded early-kdump kernel"
893e0b
        return 0
893e0b
    else
8f4abc
        derror "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
8f4abc
        dinfo "early-kdump is enabled."
893e0b
        early_kdump_load
893e0b
    else
8f4abc
        dinfo "early-kdump is disabled."
893e0b
    fi
893e0b
893e0b
    return 0
893e0b
}
893e0b
893e0b
set_early_kdump