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