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