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.
|
|
|
|
|
bash scripts: replace '[ ]' with '[[ ]]' for bash scripts
upstream: fedora
resolves: bz2003832
conflict:
function load_kdump_kernel_key() not presented in rhel9,
so related patch hunk are removed.
commit 70978c00e5a573f0901ac404067eaea2c6536370
Author: Kairui Song <kasong@redhat.com>
Date: Wed Sep 8 17:20:51 2021 +0800
bash scripts: replace '[ ]' with '[[ ]]' for bash scripts
kdumpctl, mkdumprd, *-module-setup.sh only target bash, since they
only run in first kernel and depend on dracut, and dracut depends
on bash. So use '[[ ]]' to replace '[ ]'.
This is a batch update done with following command:
`sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdumpctl, mkdumprd, *-module-setup.sh`
and replaced [ ... -a ... ] with [[ ... ]] && [[ ... ]] manually.
See https://tldp.org/LDP/abs/html/testconstructs.html for more details
on '[[ ]]', it's more versatile, safer, and slightly faster than '[ ]'.
This will also help shfmt to clean up the code in later commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 13:13:59 +00:00
|
|
|
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
|
|
|
|
|
2021-11-03 09:30:56 +00:00
|
|
|
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"
|
2022-12-22 05:28:00 +00:00
|
|
|
# Don't use squash for capture image or default image as it negatively impacts
|
|
|
|
# compression ratio and increases the size of the initramfs image.
|
2022-12-22 05:28:43 +00:00
|
|
|
# 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
|
|
|
|
|
2022-12-22 05:28:43 +00:00
|
|
|
### 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"
|
2022-12-22 05:28:43 +00:00
|
|
|
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
|
2021-11-09 13:42:45 +00:00
|
|
|
_dracut_isolate_args=(
|
|
|
|
--rebuild "$REBUILD_INITRD" --add zz-fadumpinit
|
2021-11-03 07:40:15 +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
|
|
|
|
2022-12-22 05:39:50 +00:00
|
|
|
# Use zstd compression method, if available
|
2022-01-06 06:23:41 +00:00
|
|
|
if ! have_compression_in_dracut_args; then
|
2022-12-22 05:39:50 +00:00
|
|
|
if is_zstd_command_available; then
|
2022-01-07 11:47:06 +00:00
|
|
|
_dracut_isolate_args+=(--compress zstd)
|
|
|
|
fi
|
2022-01-06 06:23:41 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-03 07:40:15 +00:00
|
|
|
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
|