Kairui Song 96a3fc
#!/bin/bash --norc
Kairui Song 96a3fc
# Generate an initramfs image that isolates dump capture capability within
Kairui Song 96a3fc
# the default initramfs using zz-fadumpinit dracut module.
Kairui Song 96a3fc
dcb59c
if [[ -f /etc/sysconfig/kdump ]]; then
Kairui Song 96a3fc
	. /etc/sysconfig/kdump
Kairui Song 96a3fc
fi
Kairui Song 96a3fc
Kairui Song 96a3fc
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
Kairui Song 96a3fc
. $dracutbasedir/dracut-functions.sh
Kairui Song 96a3fc
. /lib/kdump/kdump-lib.sh
Kairui Song 96a3fc
. /lib/kdump/kdump-logger.sh
Kairui Song 96a3fc
Kairui Song 96a3fc
#initiate the kdump logger
Kairui Song 96a3fc
if ! dlog_init; then
Kairui Song 96a3fc
	echo "mkfadumprd: failed to initiate the kdump logger."
Kairui Song 96a3fc
	exit 1
Kairui Song 96a3fc
fi
Kairui Song 96a3fc
633084
MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
Kairui Song 96a3fc
[ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed."
Kairui Song 96a3fc
trap '
Kairui Song 96a3fc
    ret=$?;
Kairui Song 96a3fc
    [[ -d $MKFADUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKFADUMPRD_TMPDIR";
Kairui Song 96a3fc
    exit $ret;
Kairui Song 96a3fc
    ' EXIT
Kairui Song 96a3fc
Kairui Song 96a3fc
# clean up after ourselves no matter how we die.
Kairui Song 96a3fc
trap 'exit 1;' SIGINT
Kairui Song 96a3fc
Kairui Song 96a3fc
MKDUMPRD="/sbin/mkdumprd -f"
Kairui Song 96a3fc
# Default boot initramfs to be rebuilt
Kairui Song 96a3fc
REBUILD_INITRD="$1" && shift
Kairui Song 96a3fc
TARGET_INITRD="$1" && shift
Kairui Song 96a3fc
FADUMP_INITRD="$MKFADUMPRD_TMPDIR/fadump.img"
Kairui Song 96a3fc
Kairui Song 96a3fc
### First build an initramfs with dump capture capability
Kairui Song 96a3fc
# this file tells the initrd is fadump enabled
Kairui Song 96a3fc
touch "$MKFADUMPRD_TMPDIR/fadump.initramfs"
Kairui Song 96a3fc
ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER"
Kairui Song 96a3fc
if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs; then
Kairui Song 96a3fc
	perror_exit "mkfadumprd: failed to build image with dump capture support"
Kairui Song 96a3fc
fi
Kairui Song 96a3fc
Kairui Song 96a3fc
### Unpack the initramfs having dump capture capability
Kairui Song 96a3fc
mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot"
b494b7
if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" &&
Kairui Song 96a3fc
	popd > /dev/null); then
Kairui Song 96a3fc
	derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'"
Kairui Song 96a3fc
	exit 1
Kairui Song 96a3fc
fi
Kairui Song 96a3fc
Kairui Song 96a3fc
### Pack it into the normal boot initramfs with zz-fadumpinit module
b494b7
_dracut_isolate_args=(
b494b7
	--rebuild "$REBUILD_INITRD" --add zz-fadumpinit
caa240
	-i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot
caa240
	-i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt"
caa240
	/usr/lib/dracut/fadump-kernel-modules.txt
caa240
)
Kairui Song 8e51eb
Kairui Song 96a3fc
if is_squash_available; then
b494b7
	_dracut_isolate_args+=(--add squash)
Kairui Song 96a3fc
fi
caa240
a501dc
# Same as setting zstd in mkdumprd
96dc81
if ! have_compression_in_dracut_args; then
b5a9e5
	if is_squash_available && dracut_have_option "--squash-compressor"; then
b5a9e5
		_dracut_isolate_args+=(--squash-compressor zstd)
b5a9e5
	elif is_zstd_command_available; then
a501dc
		_dracut_isolate_args+=(--compress zstd)
a501dc
	fi
96dc81
fi
96dc81
caa240
if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then
Kairui Song 96a3fc
	perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability"
Kairui Song 96a3fc
fi