2021-06-23 14:36:48 +00:00
|
|
|
#!/bin/bash --norc
|
|
|
|
# Generate an initramfs image that isolates dump capture capability within
|
|
|
|
# the default initramfs using zz-fadumpinit dracut module.
|
|
|
|
|
2021-09-08 09:20:51 +00:00
|
|
|
if [[ -f /etc/sysconfig/kdump ]]; then
|
2021-06-23 14:36:48 +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
|
|
|
|
|
2021-08-17 18:04:45 +00:00
|
|
|
MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
|
2021-06-23 14:36:48 +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"
|
|
|
|
if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs; then
|
|
|
|
perror_exit "mkfadumprd: failed to build image with dump capture support"
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Unpack the initramfs having dump capture capability
|
|
|
|
mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot"
|
2021-09-13 18:25:40 +00:00
|
|
|
if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" &&
|
2021-06-23 14:36:48 +00:00
|
|
|
popd > /dev/null); then
|
|
|
|
derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Pack it into the normal boot initramfs with zz-fadumpinit module
|
2021-09-13 18:25:40 +00:00
|
|
|
_dracut_isolate_args=(
|
|
|
|
--rebuild "$REBUILD_INITRD" --add zz-fadumpinit
|
2021-08-03 19:06:57 +00:00
|
|
|
-i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot
|
|
|
|
-i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt"
|
|
|
|
/usr/lib/dracut/fadump-kernel-modules.txt
|
|
|
|
)
|
2021-06-25 06:44:45 +00:00
|
|
|
|
2021-06-23 14:36:48 +00:00
|
|
|
if is_squash_available; then
|
2021-09-13 18:25:40 +00:00
|
|
|
_dracut_isolate_args+=(--add squash)
|
2021-06-23 14:36:48 +00:00
|
|
|
fi
|
2021-08-03 19:06:57 +00:00
|
|
|
|
2022-01-10 13:51:16 +00:00
|
|
|
# Same as setting zstd in mkdumprd
|
2022-01-05 09:42:12 +00:00
|
|
|
if ! have_compression_in_dracut_args; then
|
Seperate dracut and dracut-squash compressor for zstd
Previously kexec-tools will pass "--compress zstd" to dracut. It
will make dracut to decide whether: a) call mksquashfs to make a
zstd format squash-root.img, b) call cmd zstd to make a initramfs.
Since dracut(>= 057) has decoupled the compressor for dracut and
dracut-squash, So in this patch, we will pass the compressor seperately.
Note:
The is_squash_available && !dracut_has_option --squash-compressor
&& !is_zsdt_command_available case is left unprocessed on purpose.
Actually, the situation when we want to call zstd compression is:
1) If squash function OK, we want dracut to invoke mksquashfs to make
a zstd format squash-root.img within initramfs.
2) If squash function is not OK, and cmd zstd presents, we want dracut
to invoke cmd zstd to make a zstd format initramfs.
is_zstd_command_available check can handle case 2 completely.
However, for the is_squash_available check, it cannot handle case 1
completely. It only checks if the kernel supports squashfs, it doesn't
check whether the squash module has been added by dracut when making
initramfs. In fact, in kexec-tools we are unable to do the check,
there are multiple ways to forbit dracut to load a module, such as
"dracut -o module" and "omit_dracutmodules in dracut.conf".
When squash dracut module is omitted, is_squash_available check will
still pass, so "--compress zstd" will be appended to dracut cmdline,
and it will call cmd zstd to do the compression. However cmd zstd may
not exist, so it fails.
The previous "--compress zstd" is ambiguous, after the intro of
"--squash-compressor", "--squash-compressor" only effect for
mksquashfs and "--compress" only effect for specific cmd.
So for the is_squash_available && !dracut_has_option
--squash-compressor && !is_zsdt_command_available case, we just leave
it to be handled the default way.
Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
2022-10-08 04:09:08 +00:00
|
|
|
if is_squash_available && dracut_have_option "--squash-compressor"; then
|
|
|
|
_dracut_isolate_args+=(--squash-compressor zstd)
|
|
|
|
elif is_zstd_command_available; then
|
2022-01-10 13:51:16 +00:00
|
|
|
_dracut_isolate_args+=(--compress zstd)
|
|
|
|
fi
|
2022-01-05 09:42:12 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-03 19:06:57 +00:00
|
|
|
if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then
|
2021-06-23 14:36:48 +00:00
|
|
|
perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability"
|
|
|
|
fi
|