I wonder why Ubuntu won't remove the old kernels automatically.
Surely nothing is perfect and things can go wrong, so in case a update doesn't work, having a backup kernel maybe great. But it would also suffice to just keep the latest kernel and the one before the latest and delete all the older ones.
Is there a reason why Ubuntu won't do this automatically?.
I can see only 1 reason: it does not work flawlessly; there is no clean way to currently decide what the definition of "old kernels" is. "old" does not mean "unused" nor does it mean "unwanted". And any mistake in this will kill a users' machine.
So up to now the manual method is preferred since this puts the power of removing into the users' hands.
Resources for this conclusion:
There are two things going on here:
New kernels are completely new packages, not updated packages with a newer version number, so installing a new kernel image doesn't replace any older ones. They coexist.
Ubuntu uses a bunch of apt magic to protect the last two kernel versions from 'apt-get autoremove' (the latest one, and the one that was last booted). See /etc/apt/apt.conf.d/01autoremove-kernels for details.
What this all means is that once you've rebooted into the latest kernel, 'apt-get autoremove' should remove all but the current and last booted kernel packages.
Old kernels still accumulate in /boot because autoremove is not enabled in Ubuntu by default - you must either run it manually every so often, or you must enable it.
This may change in 16.04 - a bugfix to the unattended-upgrades package will enable autoremove of old kernels by default.
This script will do the job. It ll remove all kernels that are not in use.
Other then that, not removing kernels must be a fairly new thing. I have one Ubuntu 14 system after the other running into this issue of a full boot partition due to old kernel garbage.
It can make the life of less experienced users extremely complicated. It is actually a noob trap. Canonical should fix this.
The simple-minded way to remove old kernels is to use ubuntu-tweak. You select the Janitor tag and tick the Old Kernel box. That gives you a list of kernels it thinks you don't need any more. You can select them all and click Clean and, after a while, the job's done. Being of a nervous disposition I checked which kernel I was running using uname -a but it didn't figure on the list. This worked on my wife's laptop (which has a rather small boot partition and was showing warnings) and mine (which was working fine). Does everyone agree that this is safe?
Ubuntu only auto-removes items that are no longer needed or are a security risk...So I assume that the reason for this is security purposes. Lets say for some odd reason a new kernel becomes insecure...Then you would be rerouted back to the old kernel temporarily while the new one is being fixed. Also new kernels can come with changes so therefore some kernels are opt-in for example updating 14.04.1 to 14.04.2 you can opt-in for a new kernel, but this April when the new LTS version 15.04 comes out you will automatically have you kernels updates. So I reckon that its for security purposes.
but if you want to remove it try running this command line
This should remove any unneeded software such as your old kernel if not try
I recommand use Ubuntu Tweak to remove old kernels. look here:
How do I remove old kernel versions to clean up the boot menu?
I think the latest release of Ubuntu 15.10 could remove old kernels automatically, if you edit /etc/apt/apt.conf.d/50unattended-upgrades file: Change line
to
I haven't tested this, though.
I had a problem with being unable to install software. Apt-get was unable to install linux-headers, reporting the disk was full.
$ df -i
reported that IUse% was at 100%: The disk had free space but had run out of inodes.$ sudo dpkg --configure -a
failed, & so did$ sudo apt-get -f install
and$ sudo apt-get autoremove
The problem solved when I manually removed several of the older kernel folders from /usr/src - just
$ rm
or shift-delete the folders. This freed up enough inode space to allow$ apt-get -f install
to complete.After that I had only 10 linux kernels. I ran
$ sudo apt-get autoremove
which deleted 1.4 GB of files. Which begs the question: Really?? Really?? But honestly, is the this the right way to run a user friendly system?