|
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 |
|
|
Kairui Song |
96a3fc |
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 |
|
|
Kairui Song |
96a3fc |
readonly 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"
|
|
Kairui Song |
96a3fc |
if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$MKFADUMPRD_TMPDIR/fadump.img" && \
|
|
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
|
|
Kairui Song |
96a3fc |
_dracut_isolate_args="--rebuild $REBUILD_INITRD --add zz-fadumpinit -i $MKFADUMPRD_TMPDIR/fadumproot /fadumproot"
|
|
Kairui Song |
96a3fc |
if is_squash_available; then
|
|
Kairui Song |
96a3fc |
_dracut_isolate_args="$_dracut_isolate_args --add squash"
|
|
Kairui Song |
96a3fc |
fi
|
|
Kairui Song |
96a3fc |
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
|