I'm managing a couple of servers for core services (NTP, DNS, etc) and it just occured to me that one of the servers seems to keep the 3 latest kernels, instead of 2 on the others :
nul@quark:~$ sudo apt-get autoremove --purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
nul@quark:~$ dpkg -l |grep linux-image
ii linux-image-3.13.0-51-generic 3.13.0-51.84 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-52-generic 3.13.0-52.85 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.16.0-37-generic 3.16.0-37.49~14.04.1 amd64 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-51-generic 3.13.0-51.84 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-52-generic 3.13.0-52.85 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.16.0-37-generic 3.16.0-37.49~14.04.1 amd64 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii linux-image-generic 3.13.0.52.59 amd64 Generic Linux kernel image
ii linux-image-generic-lts-utopic 3.16.0.37.29 amd64 Generic Linux kernel image
...
nul@dwarf:~$ sudo apt-get autoremove --purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
nul@dwarf:~$ dpkg -l |grep linux-image
ii linux-image-3.13.0-52-generic 3.13.0-52.85 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.16.0-37-generic 3.16.0-37.49~14.04.1 amd64 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-52-generic 3.13.0-52.85 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.16.0-37-generic 3.16.0-37.49~14.04.1 amd64 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii linux-image-generic 3.13.0.52.59 amd64 Generic Linux kernel image
ii linux-image-generic-lts-utopic 3.16.0.37.29 amd64 Generic Linux kernel image
All servers are maintained identically, don't know what I could have done, must be a parameter somewhere but can't find it!
Please feed my curiosity! Thank you
Best Answer
There is a file that is auto-generated that tells
apt-get
what kernels to autoremove and which ones to keep.The file that tells
apt-get
which kernels they are is/etc/apt/apt.conf.d/01autoremove-kernels
which is generated from/etc/kernel/postinst.d/apt-auto-removal
.Usually what happens is that when you are receiving kernel updates, when the kernel version changes, say from
3.13
to3.16
,/etc/apt/apt.conf.d/01autoremove-kernels
is then updated to keep the3.16*
kernels and is then set to remove all of the3.13
kernels unless specified by the generating script to not be removed.From the
apt-auto-removal
script:However, this sometimes will not mark them for auto-removal since some of the coding has changed over versions to prevent this from happening.
If you want mark the previous kernels for
autoremove
except for the required kernels based on the scripts, run the following command from a terminal window:Then, when you run the
apt-get autoremove
command only the ones that are old and no longer needed can be removed. I have put examples below:This first one shows all kernels on the system minus the current running kernel.
This one shows the current running kernel.
NOTE: The above one was too long to list, so I truncated a bit.
So, after running those commands, you can see that I can now auto-remove all the old but the current kernel (4.0.1-040001-generic) and the next newest one (3.16.0-37-generic).
Hopefully this helps.