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