Currently kdump simply uses dracut and pulls all the required binaries
from the host directly. This keep things simple as kdump is using same
binaries and libs from the system of fisrt kernel.
But some binaries, like systemd, is growing too large, which increase
the memory usage by a lot, and most of its features are never used
in kdump. So it's more reasonable to use a rebuilt-minimized version.
So for such binaries, introduce a "build root" overlay here. Before
calling dracut to build initramfs, setup an overlay to let the build
root override current rootfs, so dracut can just work as usual, but the
binaries used are from the "build root".
All binaries/libs that need to be rebuild for smaller size can be put in
the build root.
---
kexec-tools.spec | 1 +
mkdumprd | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 91bc0f3..1a06b62 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -171,6 +171,7 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir}
mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir}
mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir}
mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump
+mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump/buildroot
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl
install -m 755 build/sbin/kexec $RPM_BUILD_ROOT/usr/sbin/kexec
diff --git a/mkdumprd b/mkdumprd
index c34b79c..5f8d2da 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -23,6 +23,7 @@ if [ $? -ne 0 ]; then
exit 1
fi
+KDUMP_BUILDROOT="/usr/lib/kdump/buildroot"
conf_file="/etc/kdump.conf"
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
SAVE_PATH=$(get_save_path)
@@ -33,12 +34,14 @@ dracut_args="--add kdumpbase --quiet --hostonly
--hostonly-cmdline --hostonly-i1
readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t
dracut.XXXXXX failed."
+readonly MKDUMPRD_TMPROOT="$MKDUMPRD_TMPDIR/root"
readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
trap '
ret=$?;
is_mounted $MKDUMPRD_TMPMNT && umount -f $MKDUMPRD_TMPMNT;
[[ -d $MKDUMPRD_TMPDIR ]] && rm --one-file-system -rf --
"$MKDUMPRD_TMPDIR";
+ [[ -d $MKDUMPRD_TMPROOT ]] && rm --one-file-system -rf --
"$MKDUMPRD_TMPROOT";
exit $ret;
' EXIT
@@ -460,7 +463,22 @@ if ! is_fadump_capable; then
add_dracut_arg "--no-hostonly-default-device"
fi
-echo "$dracut_args $@" | xargs dracut
+if [ -n "$(ls -A1 $KDUMP_BUILDROOT | grep -E "etc|usr")" ]; then
+ # Run in a new namespace, so overlay on root is safe
+ # everything is automatically cleaned up upon exit
+ export KDUMP_BUILDROOT
+ export MKDUMPRD_TMPROOT
+ export dracut_args="$dracut_args $@"
+
+ cp -r /usr/lib/kdump/buildroot $MKDUMPRD_TMPROOT
+ unshare --mount bash -c '
+ for _d in etc usr; do
+ [ -d "$MKDUMPRD_TMPROOT/$_d" ] && mount overlay -t overlay -o
ro,lowerdir=$MKDUMPRD_TMPROOT/$_d:/$_d /$_d;
+ done
+ echo "$dracut_args $@" | xargs -t dracut;'
+else
+ echo "$dracut_args $@" | xargs -t dracut
+fi
_rc=$?
sync
--
2.29.2