kexec-tools/mkfadumprd

75 lines
2.7 KiB
Plaintext
Raw Normal View History

2021-07-12 08:07:05 +00:00
#!/bin/bash --norc
# Generate an initramfs image that isolates dump capture capability within
# the default initramfs using zz-fadumpinit dracut module.
if [[ -f /etc/sysconfig/kdump ]]; then
2021-07-12 08:07:05 +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
MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
2021-07-12 08:07:05 +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"
# Don't use squash for capture image or default image as it negatively impacts
# compression ratio and increases the size of the initramfs image.
# Don't compress the capture image as uncompressed image is needed immediately.
# Also, early microcode would not be needed here.
if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs --omit squash --no-compress --no-early-microcode; then
2021-07-12 08:07:05 +00:00
perror_exit "mkfadumprd: failed to build image with dump capture support"
fi
### Unpack the initramfs having dump capture capability retaining previous file modification time.
# This helps in saving space by hardlinking identical files.
2021-07-12 08:07:05 +00:00
mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot"
if ! cpio -id --preserve-modification-time --quiet -D "$MKFADUMPRD_TMPDIR/fadumproot" < "$FADUMP_INITRD"; then
2021-07-12 08:07:05 +00:00
derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'"
exit 1
fi
### Pack it into the normal boot initramfs with zz-fadumpinit module
_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
)
# Use zstd compression method, if available
Set zstd as the default compression method for kdump initrd resolves: bz1896698 upstream: fedora conflict: none commit 0311f6e25bec9994de2c6b156b5a568583aa8aae Author: Tao Liu <ltao@redhat.com> Date: Wed Jan 5 17:42:12 2022 +0800 Set zstd as the default compression method for kdump initrd zstd has better compression ratio and time consumption balance. When no customized compression method specified in kdump.conf, we will use zstd as the default compression method. **The test method: I installed kexec-tools with and without the patch, executing the following command for 4 times, and calculate the averange time: $ rm -f /boot/initramfs-*kdump.img && time kdumpctl rebuild && \ ls -ail /boot/initramfs-*kdump.img **The test result: Bare metal x86_64 machine: dracut with squash module zlib lzo xz lz4 zstd real 10.6282 11.0398 11.395 8.6424 10.1676 user 9.8932 11.9072 14.2304 2.8286 8.6468 sys 3.523 3.4626 3.6028 3.5 3.4942 size of kdump.img 30575616 31419392 27102208 36666368 29236224 dracut without squash module zlib lzo xz lz4 zstd real 9.509 19.4876 11.6724 9.0338 10.267 user 10.6028 14.516 17.8662 4.0476 9.0936 sys 2.942 2.9184 3.0662 2.9232 3.0662 size of kdump.img 19247949 19958120 14505056 21112544 17007764 PowerVM hosted ppc64le VM: dracut with squash module | dracut without sqaush module zlib zstd | zlib zstd real 10.6742 10.7572 | 9.7676 10.5722 user 18.754 19.8338 | 20.7932 13.179 sys 1.8358 1.864 | 1.637 1.663 | size of | kdump.img 36917248 35467264 | 21441323 19007108 **discussion zstd has a better compression ratio and time consumption balance. Acked-by: Coiby Xu <coxu@redhat.com> Signed-off-by: Tao Liu <ltao@redhat.com> Signed-off-by: Tao Liu <ltao@redhat.com>
2022-01-06 06:23:41 +00:00
if ! have_compression_in_dracut_args; then
if is_zstd_command_available; then
_dracut_isolate_args+=(--compress zstd)
fi
Set zstd as the default compression method for kdump initrd resolves: bz1896698 upstream: fedora conflict: none commit 0311f6e25bec9994de2c6b156b5a568583aa8aae Author: Tao Liu <ltao@redhat.com> Date: Wed Jan 5 17:42:12 2022 +0800 Set zstd as the default compression method for kdump initrd zstd has better compression ratio and time consumption balance. When no customized compression method specified in kdump.conf, we will use zstd as the default compression method. **The test method: I installed kexec-tools with and without the patch, executing the following command for 4 times, and calculate the averange time: $ rm -f /boot/initramfs-*kdump.img && time kdumpctl rebuild && \ ls -ail /boot/initramfs-*kdump.img **The test result: Bare metal x86_64 machine: dracut with squash module zlib lzo xz lz4 zstd real 10.6282 11.0398 11.395 8.6424 10.1676 user 9.8932 11.9072 14.2304 2.8286 8.6468 sys 3.523 3.4626 3.6028 3.5 3.4942 size of kdump.img 30575616 31419392 27102208 36666368 29236224 dracut without squash module zlib lzo xz lz4 zstd real 9.509 19.4876 11.6724 9.0338 10.267 user 10.6028 14.516 17.8662 4.0476 9.0936 sys 2.942 2.9184 3.0662 2.9232 3.0662 size of kdump.img 19247949 19958120 14505056 21112544 17007764 PowerVM hosted ppc64le VM: dracut with squash module | dracut without sqaush module zlib zstd | zlib zstd real 10.6742 10.7572 | 9.7676 10.5722 user 18.754 19.8338 | 20.7932 13.179 sys 1.8358 1.864 | 1.637 1.663 | size of | kdump.img 36917248 35467264 | 21441323 19007108 **discussion zstd has a better compression ratio and time consumption balance. Acked-by: Coiby Xu <coxu@redhat.com> Signed-off-by: Tao Liu <ltao@redhat.com> Signed-off-by: Tao Liu <ltao@redhat.com>
2022-01-06 06:23:41 +00:00
fi
if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then
2021-07-12 08:07:05 +00:00
perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability"
fi