Cleaning up /boot with eclean-kernel

# make install
sh /usr/src/linux-drm-next/arch/x86/boot/install.sh 3.2.0-rc2-pomiocik+ arch/x86/boot/bzImage \
		System.map "/boot"
cat: write error: No space left on device
make[1]: *** [install] Error 1
make: *** [install] Error 2

Ever hit an issue like that when trying to install a new kernel? Ever thought how much you hate manually removing old kernels? Ever forgot to remove modules as well? If you do, then you may be interested in a tiny new tool called eclean-kernel.

In simplest words, eclean-kernel could be called an old kernel harvester. Given a few tiny settings, it finds the kernels installed in the system, chooses ones to remove and removes them along with the modules and sources (if not used by any other kernel).

The usual way of using it is to set it to keep a few newest kernels, and remove all older than them. To do this, you just need to pass the number as --num. For example:

eclean-kernel -n 3 --ask

will remove all kernels but the newest three, asking before removing each one. For non-interactive use, omit --ask; you can also use --pretend for eclean-kernel to list the kernel versions which would be removed.

By default, it preserves all kernels referenced by the bootloader. The --destructive option can be used to disable that. If it fails to detect the correct bootloader (or multiple bootloaders are installed), --bootloader option can be used to specify the one to use.

It can also preserve some kinds of kernel files to fit more specific setups. For example, if you’d like to keep old kernel configs, just pass --exclude config.

And finally, you can avoid having to repeatedly provide the same options by putting them in your ~/.config/eclean-kernel.rc. An example file could look like:

-n 3 --ask --exclude config

22 thoughts on “Cleaning up /boot with eclean-kernel”

    1. For grub, not yet. As for LILO, I’m not aware of anything what would add kernel entries there — so we just assume it has some sane default like /boot/vmlinuz & /boot/vmlinuz.old. If I’m wrong, please correct me.

      1. LiLO does not add kernel entries to /boot. If you use “make install” while building your kernel you will get .config System.map vmlinuz copied to /boot — the files you mentioned will be created and maintained if you create the appropriate symlinks.

        There may be other kernels or files if the user manually copies them to /boot.

  1. The tool assumes /boot is mounted otherwise things go awry. Can you please have it mount /boot? and then unmount it, if mounting was required. thanks.

    1. I’ll probably have to do that, though I do not really think that’s the proper way of doing it. System RC should control mountpoints.

  2. Will it also remove kernel modules under /lib/modules ?

    When running with parameters “-n 3 –ask” and grub2 is installed, could it remove all but 3 newest kernels without taking count existing bootmenu and after that run “grub-mkconfig -o /boot/grub/grub.cfg”? This way the boot menu is also updated correctly, and old entries are removed.

  3. It would be nice to clean up /lib/modules (like Bugitus wrote) and /usr/src as unmerging the kernel leaves conifig and compilation leftovers.

    1. There’s a live ebuild in mgorny overlay. But it won’t help you much, I use ‘release often’ policy on eclean-kernel, so the release delay for any commits is 1-2 days max.

    1. Was supposed to be reply to my previous comment. Now sorry again for cluttering comments. This message will not self-destruct after reading, so feel free to remove it by hand.

  4. Polish it and throw it into gentoolkit! =D

    Thank you for that nifty tool.

  5. I get this error with version 0.2.1
    ~ # eclean-kernel
    Traceback (most recent call last):
    File “/usr/bin/eclean-kernel-2.7”, line 26, in
    sys.exit(main(sys.argv))
    File “/usr/lib/python2.7/site-packages/ecleankernel/cli.py”, line 101, in main
    kernels = find_kernels(exclusions = exclusions)
    File “/usr/lib/python2.7/site-packages/ecleankernel/kernel.py”, line 206, in find_kernels
    realkv = get_real_kv(path)
    File “/usr/lib/python2.7/site-packages/ecleankernel/kernel.py”, line 153, in get_real_kv
    raise NotImplementedError(‘Invalid magic for kernel file (!= HdrS)’)
    NotImplementedError: Invalid magic for kernel file (!= HdrS)

    1. Do you have any non-Linux kernels in /boot? Or other files which are named similarly to kernel yet are not kernels?

      The current git head will report the filename as well.

  6. Great tool but needs a prefix or support for initrd files as it happily deleted mine while I wasn’t paying attention ;)

Comments are closed.