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
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).
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.
(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 }
(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 > }
It is in the kernel-install.eclass
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
update-bootloader: already resolved via installkernel cleanup-boot and cleanup-src: resolve-able via portage post_pkg_postrm hook or via 'kernel-install remove $version'. Additionally, the /usr/src directory is already cleaned up completely if it has not been manually touched. I don't think there is anything left to do here.