Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 771678 - sys-kernel/gentoo-kernel: RFE: USE=cleanup-boot & USE=cleanup-src & USE=update-bootloader
Summary: sys-kernel/gentoo-kernel: RFE: USE=cleanup-boot & USE=cleanup-src & USE=updat...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement with 1 vote (vote)
Assignee: Distribution Kernel Project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-19 20:05 UTC by Johannes Niess
Modified: 2022-01-08 14:51 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Niess 2021-02-19 20:05:08 UTC
Gentoo Kernels are great to stay current, but the fast update cycle and remains from old versions need a lot of manual cleanup.
USE=cleanup-boot should remove package files from /boot on deinstall
USE=cleanup-src should remove /usr/src/kernel-<version>
USE=update-bootloader should update the bootloader config to boot this kernel, e. g. 'grub-mkconfig'. Until we get a virtual bootloader pkg, we might need to call this 'USE=update-grub' with variants for other arches.

Reproducible: Always
Comment 1 Ionen Wolkens gentoo-dev 2021-02-19 20:19:32 UTC
Those call /sbin/installkernel during pkg_postinst() to install the kernel which in turn (for installkernel-gentoo) run /etc/kernel/postinst.d/* scripts.

You can have a simple script in there to update your bootloader (with whatever method is needed, there's a lot of different setups), and even run eclean-kernel if wanted.

As for the sources, they already gets cleaned up during normal depclean (those are also smaller than normal sources, just enough to build third party modules or update configs).
Comment 2 Johannes Niess 2021-02-19 21:07:40 UTC
Thanks for the tip regarding USE=update-bootloader. That's resolved.

What's missing is the deletion bit.

Eclean-kernel won't work for cleaning /boot on its own, as the kernels to be removed are already referenced in the boot loader via previous /etc/kernel/postinst.d/* scripts. Eclean-kernel has no '--keep-intalled-packages' option. 'Eclean-kernel --num' is a crude workaround and doesn't need to know the version, so it could also be called from /etc/kernel/postinst.d/* 

What about adding a corresponding /etc/kernel/pre-del.d/* called by the kernel ebuilds during removal? In case the scripts see a $version / $package, they easily can nuke /usr/src/kernel-<version> and files in /boot.
Comment 3 Johannes Niess 2021-02-19 21:19:49 UTC
(In reply to Johannes Niess from comment #2)
> Thanks for the tip regarding USE=update-bootloader. That's resolved.
> 
> What's missing is the deletion bit.
> 
> Eclean-kernel won't work for cleaning /boot on its own, as the kernels to be
> removed are already referenced in the boot loader via previous
> /etc/kernel/postinst.d/* scripts. Eclean-kernel has no
> '--keep-intalled-packages' option. 'Eclean-kernel --num' is a crude
> workaround and doesn't need to know the version, so it could also be called
> from /etc/kernel/postinst.d/* 
> 
> What about adding a corresponding /etc/kernel/pre-del.d/* called by the
> kernel ebuilds during removal? In case the scripts see a $version /
> $package, they easily can nuke /usr/src/kernel-<version> and files in /boot.

/usr/portage/eclass/kernel-build.eclass already has a hook to play around with:
# @FUNCTION: kernel-install_pkg_postrm
# @DESCRIPTION:
# No-op at the moment.  Will be used to remove obsolete kernels
# in the future.
kernel-install_pkg_postrm() {
        debug-print-function ${FUNCNAME} "${@}"

        if [[ -z ${ROOT} ]] && use initramfs; then
                local ver="${PV}${KV_LOCALVERSION}"
                local image_path=$(dist-kernel_get_image_path)
                ebegin "Removing initramfs"
                rm -f "${EROOT}/usr/src/linux-${ver}/${image_path%/*}/initrd" &&
                        find "${EROOT}/usr/src/linux-${ver}" -depth -type d -empty -delete
                eend ${?}
        fi
}
Comment 4 Johannes Niess 2021-02-19 21:21:07 UTC
(In reply to Johannes Niess from comment #3)
> (In reply to Johannes Niess from comment #2)
> > Thanks for the tip regarding USE=update-bootloader. That's resolved.
> > 
> > What's missing is the deletion bit.
> > 
> > Eclean-kernel won't work for cleaning /boot on its own, as the kernels to be
> > removed are already referenced in the boot loader via previous
> > /etc/kernel/postinst.d/* scripts. Eclean-kernel has no
> > '--keep-intalled-packages' option. 'Eclean-kernel --num' is a crude
> > workaround and doesn't need to know the version, so it could also be called
> > from /etc/kernel/postinst.d/* 
> > 
> > What about adding a corresponding /etc/kernel/pre-del.d/* called by the
> > kernel ebuilds during removal? In case the scripts see a $version /
> > $package, they easily can nuke /usr/src/kernel-<version> and files in /boot.
> 
> /usr/portage/eclass/kernel-install.eclass already has a hook to play around
> with:
> # @FUNCTION: kernel-install_pkg_postrm
> # @DESCRIPTION:
> # No-op at the moment.  Will be used to remove obsolete kernels
> # in the future.
> kernel-install_pkg_postrm() {
>         debug-print-function ${FUNCNAME} "${@}"
> 
>         if [[ -z ${ROOT} ]] && use initramfs; then
>                 local ver="${PV}${KV_LOCALVERSION}"
>                 local image_path=$(dist-kernel_get_image_path)
>                 ebegin "Removing initramfs"
>                 rm -f
> "${EROOT}/usr/src/linux-${ver}/${image_path%/*}/initrd" &&
>                         find "${EROOT}/usr/src/linux-${ver}" -depth -type d
> -empty -delete
>                 eend ${?}
>         fi
> }
Comment 5 Johannes Niess 2021-02-19 21:22:44 UTC
It is in the kernel-install.eclass
Comment 6 Johannes Niess 2022-01-08 14:51:01 UTC
I use the script below since many months. For now I haven't added it to my /etc/kernel/postinst.d/* scripts:


#! /bin/sh
# Clean up sources
emerge --depclean sys-kernel/gentoo-kernel

# Ensure eclean-kernel sees all candidates for deletion from /boot and modules
grub-mkconfig -o /boot/grub/grub.cfg

# Remove all but latest two kernels using app-admin/eclean-kernel
eclean-kernel -d -n2

# Clean up grub afterwards
grub-mkconfig -o /boot/grub/grub.cfg