From: Kairui Song <kasong(a)tencent.com>
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.
Signed-off-by: Kairui Song <kasong(a)tencent.com>
---
Hi,
I'm trying again to make this package into Fedora:
https://github.com/ryncsn/kdump-initrd-systemd
It's a minimized version of systemd, as kdump heavily depend on
systemd and so using a minimized version of systemd just for kdump can
help a lot for saving memory.
But it need to depend on kexec-tools for the present of this dir:
`$RPM_BUILD_ROOT%{_prefix}/lib/buildroot`
So this patch have to be merged first, then selinux rule need to be
updated, then that kdump-initrd-systemd package can pass rpm checks
and get included in Fedora.
I've sent the patch previously and got acked by Pingfan, but it didn't
get merged that time:
https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.o...
There have been many updated to kexec-tools so I rebased this patch to
latest rawhide.
Next steps are:
1. Discuss and get this patch merged, and make a new kexec-tools release.
2. Open a bug for SELinux rules to let mkdumprd have access to
buildroot path. SELinux team will need the code base from kexec-tools
as reference the SELinux rule update.
3. Introduce that package (and maybe other minimized package) to Fedora.
I've tested this on some cloud instances, which show a great improvement
in memory usage:
With kdump-initrd-systemd
[debug_mem] kdump saving vmcore
MemTotal: 90084 kB
MemFree: 18612 kB
MemAvailable: 49004 kB
Without kdump-initrd-systemd
[debug_mem] kdump saving vmcore
MemTotal: 90084 kB
MemFree: 9492 kB
MemAvailable: 39800 kB
Which is a good start point, as systemd can be minimized even more, and
some libraries are still being depended on by other packaged, which can also
be minimized later. Systemd is a big part of the initramfs that can't be
stirpped easily so the repackaged version will be very helpful.
kexec-tools.spec | 1 +
mkdumprd | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 849d09c..c90a60a 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -173,6 +173,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/buildroot
mkdir -p -m755 $RPM_BUILD_ROOT%{_sharedstatedir}/kdump
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl
diff --git a/mkdumprd b/mkdumprd
index 593ec77..386f55a 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -22,6 +22,7 @@ if ! dlog_init; then
exit 1
fi
+KDUMP_BUILDROOT="/usr/lib/kdump/buildroot"
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
SAVE_PATH=$(get_save_path)
OVERRIDE_RESETTABLE=0
@@ -32,11 +33,13 @@ dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline
--hostonly-i1
MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t
dracut.XXXXXX failed."
MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
+MKDUMPRD_TMPROOT="$MKDUMPRD_TMPDIR/root"
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
@@ -457,7 +460,22 @@ if ! is_fadump_capable; then
add_dracut_arg "--no-hostonly-default-device"
fi
-dracut "${dracut_args[@]}" "$@"
+if [ -e $KDUMP_BUILDROOT/usr ] || [ -e $KDUMP_BUILDROOT/etc ]; 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
+
+ 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
+ dracut "$@"' _ "${dracut_args[@]}" "$@"
+else
+ dracut "${dracut_args[@]}" "$@"
+fi
_rc=$?
sync
--
2.34.1