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 5.15.0.79.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 5.15.0.79.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.
But I´m not sure about the entry linux-headers-5.15.0-52. What is this one for
The source doesn´t mention it. I guess it should be uninstalled as well
What do you think of it?
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
Regards
Neville
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.
So this is similar to the command I´ve been using so far: sudo apt-get autoremove --purge.
And you say it saves three kernels this way. So it seems to be a ubuntu poilicy then.
Good point. I´ve never thought of that aspect.
Thanks to both of you for providing your views on the matter.
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.
The great joy of Linux (and BSD) is that one can , sometimes with a great deal of effort, find a setting like that in an ASCII file that can be viewed and edited.
Dont let anyone ever take that away. It is part of your Unix heritage, part of what ‘free’ means.
However my situation seems to be different.
I looked for the dnf.conf file and it seems there´s no such thing on Linux Lite 6.2, not even in another path.
That made me curious. What about other systems?
So I looked it up on my Debian VM and my Bodhi Linux VM:
Debian doesn´t have it either, neither does Bodhi.
I wonder what distro uses ‘/etc/dnf/dnf.conf’. Do you have any further information about that?
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 know you have abundant experience with Gentoo, so you´re pretty much ahead of me.
Complinig kernels oneself is something I never would´ve thought of.
You can compile any package ( including a kernel) in any Linux distro. You just need to install what are called the build tools… things like gcc, make, linux headers…
I would suggest you try something smaller than a kernel first…a gentoo kernel takes about 2 hours on my core i5 .
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