On Thu, Mar 4, 2021 at 9:56 AM Coiby Xu <coxu(a)redhat.com> wrote:
On Thu, Feb 04, 2021 at 10:01:42AM +0800, Kairui Song wrote:
>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
$KDUMP_BUILDROOT can be re-used here. Btw, I don't know if there is
another good choice for /usr/lib/kdump/buildroot, but the answer is
yes, then we needn't to copy it to $MKDUMPRD_TMPROOT.
Hi, Coiby
That's also what I was thinking about. Currently $KDUMP_BUILDROOT is
under /usr, so doing a overlay mount need to copy it somewhere else
first. This may slow down the building process and consume a lot of
memory. But I didn't have better idea yet.
>+ 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;
"-o ro" is not necessary. lowerdir is already read-only.
>+ done
>+ echo "$dracut_args $@" | xargs -t dracut;'
>+else
>+ echo "$dracut_args $@" | xargs -t dracut
>+fi
>
> _rc=$?
> sync
>--
>2.29.2
>_______________________________________________
>kexec mailing list -- kexec(a)lists.fedoraproject.org
>To unsubscribe send an email to kexec-leave(a)lists.fedoraproject.org
>Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
>List Archives:
https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
--
Best regards,
Coiby
--
Best Regards,
Kairui Song