|
|
db7d74 |
#!/bin/bash --norc
|
|
|
db7d74 |
# Generate an initramfs image that isolates dump capture capability within
|
|
|
db7d74 |
# the default initramfs using zz-fadumpinit dracut module.
|
|
|
db7d74 |
|
|
|
4a6108 |
if [[ -f /etc/sysconfig/kdump ]]; then
|
|
|
db7d74 |
. /etc/sysconfig/kdump
|
|
|
db7d74 |
fi
|
|
|
db7d74 |
|
|
|
db7d74 |
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
|
|
|
db7d74 |
. $dracutbasedir/dracut-functions.sh
|
|
|
db7d74 |
. /lib/kdump/kdump-lib.sh
|
|
|
db7d74 |
. /lib/kdump/kdump-logger.sh
|
|
|
db7d74 |
|
|
|
db7d74 |
#initiate the kdump logger
|
|
|
db7d74 |
if ! dlog_init; then
|
|
|
db7d74 |
echo "mkfadumprd: failed to initiate the kdump logger."
|
|
|
db7d74 |
exit 1
|
|
|
db7d74 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
|
|
|
db7d74 |
[ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed."
|
|
|
db7d74 |
trap '
|
|
|
db7d74 |
ret=$?;
|
|
|
db7d74 |
[[ -d $MKFADUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKFADUMPRD_TMPDIR";
|
|
|
db7d74 |
exit $ret;
|
|
|
db7d74 |
' EXIT
|
|
|
db7d74 |
|
|
|
db7d74 |
# clean up after ourselves no matter how we die.
|
|
|
db7d74 |
trap 'exit 1;' SIGINT
|
|
|
db7d74 |
|
|
|
db7d74 |
MKDUMPRD="/sbin/mkdumprd -f"
|
|
|
db7d74 |
# Default boot initramfs to be rebuilt
|
|
|
db7d74 |
REBUILD_INITRD="$1" && shift
|
|
|
db7d74 |
TARGET_INITRD="$1" && shift
|
|
|
db7d74 |
FADUMP_INITRD="$MKFADUMPRD_TMPDIR/fadump.img"
|
|
|
db7d74 |
|
|
|
db7d74 |
### First build an initramfs with dump capture capability
|
|
|
db7d74 |
# this file tells the initrd is fadump enabled
|
|
|
db7d74 |
touch "$MKFADUMPRD_TMPDIR/fadump.initramfs"
|
|
|
db7d74 |
ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER"
|
|
|
4335b5 |
# Don't use squash for capture image or default image as it negatively impacts
|
|
|
4335b5 |
# compression ratio and increases the size of the initramfs image.
|
|
|
4335b5 |
# Don't compress the capture image as uncompressed image is needed immediately.
|
|
|
4335b5 |
# Also, early microcode would not be needed here.
|
|
|
4335b5 |
if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs --omit squash --no-compress --no-early-microcode; then
|
|
|
db7d74 |
perror_exit "mkfadumprd: failed to build image with dump capture support"
|
|
|
db7d74 |
fi
|
|
|
db7d74 |
|
|
|
4335b5 |
### Unpack the initramfs having dump capture capability retaining previous file modification time.
|
|
|
4335b5 |
# This helps in saving space by hardlinking identical files.
|
|
|
db7d74 |
mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot"
|
|
|
4335b5 |
if ! cpio -id --preserve-modification-time --quiet -D "$MKFADUMPRD_TMPDIR/fadumproot" < "$FADUMP_INITRD"; then
|
|
|
db7d74 |
derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'"
|
|
|
db7d74 |
exit 1
|
|
|
db7d74 |
fi
|
|
|
db7d74 |
|
|
|
db7d74 |
### Pack it into the normal boot initramfs with zz-fadumpinit module
|
|
|
4a6108 |
_dracut_isolate_args=(
|
|
|
4a6108 |
--rebuild "$REBUILD_INITRD" --add zz-fadumpinit
|
|
|
4a6108 |
-i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot
|
|
|
4a6108 |
-i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt"
|
|
|
4a6108 |
/usr/lib/dracut/fadump-kernel-modules.txt
|
|
|
4a6108 |
)
|
|
|
db7d74 |
|
|
|
4335b5 |
# Use zstd compression method, if available
|
|
|
455616 |
if ! have_compression_in_dracut_args; then
|
|
|
4335b5 |
if is_zstd_command_available; then
|
|
|
455616 |
_dracut_isolate_args+=(--compress zstd)
|
|
|
455616 |
fi
|
|
|
455616 |
fi
|
|
|
455616 |
|
|
|
4a6108 |
if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then
|
|
|
db7d74 |
perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability"
|
|
|
db7d74 |
fi
|