Remove an old Kernel (and its symlink) from Gentoo
[Jack Todaro]
I think every Gentoo user would have to admit to having a form of OCD to varying degrees, and I would have to be one of them; I go bonkers when I see a kernel symlink in eselect kernel list to a kernel I don’t even have installed anymore.
If you’re like me and you like to keep your computer clean - that is, every file is organised and categorised into appropriate directories, and there is no such thing as cruft on your Gentoo system - then thankfully there is an easy solution, as always with Gentoo.
Firstly, I assume that you have set up your new kernel, tested it, and all the functionality you expect from it is working. In other words, I expect that you do not require your old kernel to stick around anymore. When you are sure, open a terminal and run:
# ‘emerge -Pav gentoo-sources’
If you run a non-Gentoo kernel, such as the vanilla-sources kernel, you would obviously replace gentoo-sources with vanilla-sources in the above example. Do not confuse -P with -p; it does not mean ‘pretend’: it means ‘Prune’. Essentially, ‘Prune’ removes every version of the package specified except for the latest version installed. It is invaluable when working with kernels.
Once you have double checked that Portage is removing the correct kernel(s), go ahead and run the command.
But there is one, small issue: the old kernel symlinks will remain, but we can get rid of these quite easily:
# cd /usr/src/
# rm -r <kernel-name>
Repeat the second command for each kernel symlink you want to remove. If you now run eselect kernel list, you should only see a symlink to the kernel you have installed.