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