I´ve got a question regarding removing old kernels.
Normally I go about it like this:
apt-get autoremove --purge
, which also removes old kernels.
The current kernel and the one before won´t be touched.
This has worked well in the past when I was using Lubuntu. But now with Linux Lite 6.2 it seems that the 3 latest kernels are kept when issuing the above command.
I don´t know if it´s a Lite “speciality” or whether ubuntu itself has changed its policies.
Currently my system looks like this:
dpkg -l | grep -E 'linux-image|linux-headers'
ii linux-headers-5.15.0-52 5.15.0-52.58 all Header files related to Linux kernel version 5.15.0
ii linux-headers-5.15.0-52-generic 5.15.0-52.58 amd64 Linux kernel headers for version 5.15.0 on 64 bit x86 SMP
ii linux-headers-5.15.0-78 5.15.0-78.85 all Header files related to Linux kernel version 5.15.0
ii linux-headers-5.15.0-78-generic 5.15.0-78.85 amd64 Linux kernel headers for version 5.15.0 on 64 bit x86 SMP
ii linux-headers-5.15.0-79 5.15.0-79.86 all Header files related to Linux kernel version 5.15.0
ii linux-headers-5.15.0-79-generic 5.15.0-79.86 amd64 Linux kernel headers for version 5.15.0 on 64 bit x86 SMP
ii linux-headers-generic 22.214.171.124.76 amd64 Generic Linux kernel headers
ii linux-image-5.15.0-52-generic 5.15.0-52.58 amd64 Signed kernel image generic
ii linux-image-5.15.0-78-generic 5.15.0-78.85 amd64 Signed kernel image generic
ii linux-image-5.15.0-79-generic 5.15.0-79.86 amd64 Signed kernel image generic
ii linux-image-generic 126.96.36.199.76 amd64 Generic Linux kernel image
Actually I want to keep just 2 of them, the current one of course, and the one before that.
When looking at the oldest of the kernels (the one ending in “52”) I see three entries.
If you want to purge one specific kernel providing package you can do so via the following command in a terminal:
sudo apt-get purge linux-image-4.12.0-12-generic
sudo dpkg --purge linux-headers-4.12.0-12 linux-headers-4.12.0-12-generic
This will also purge the corresponding linux-image-extra package if it is installed e.g. linux-image-extra-4.12.0-12-generic. It will not purge linux-headers-4.12.0-12, if there is another linux-headers-4.12.0-12 flavor installed besides -generic.
be careful, there may be a reason it keeps 3.
I usually have 3 kernels, more in Void
Dont forget to redo update-grub if you remove kernels
I’ve removed old kernels manually on CentOS. For Ubuntu I let it manage those and it automatically removes old kernels, while saving three (be default), with sudo apt autoremove -y.
Saving three is one better than saving two I guess. If you need to revert to an old kernel you would think one would be enough. If there were a couple rapid releases (small patches), maybe a third one would be a good idea. The kernel doesn’t use much disk space anyway.
I remember reading there was a way to control the number of kernels to keep. Had to look it up, but here it is.
“Edit the file ‘/etc/dnf/dnf.conf’, changing the numeric value in installonly_limit=3 to a number of your choosing.”
I just looked and see I have 4 kernels installed. I have 10 GB of free space on my “/” partition, so I do not worry about the number of kernels installed. Yes, maybe once a month, I will check to see how many kernels are installed. I only remember once using Timeshift to back out a kernel install.
It is interesting in Gentoo. You can compile any kernel you wish. They all seem to work. The kernels are compiled separately from all the other packages, so they are not part of the package system at all.
Kernels include driver modules and firmware (those binary blobs that everyone argues about). So kernels are the most hardware dependent part of your OS. They are also the best managed… problems are quite rare. We hardly ever hear of a new kernel release having issues.
I actually compiled a package in the past; it is a very long time ago though.
I the recent past I didn´t need to do any compilation. So I´m vaguely familiar with the process although I´d look up the how-to´s before doing it again.
Well, the way you put it, it makes sense, of course. The kernel is just another package, albeit a pretty big one.
Still: it would never have occurred to me to compile a kernel myself.
That is what configure is supposed to sort out.
If configure fails, you cannot proceed… you have to go find the missing pieces.
Configure is a huge job for a kernel… you have to find all the right drivers and firmware for your hardware. There are programs which do it… the Gentoo one is called genkernel