Why doesn't apt-get autoremove remove my old kernels?


I always do the updates with the following three commands:


sudo apt-get update sudo apt-get dist-upgrade sudo apt-get autoremove

Although is supposed to remove old kernels, for some reason it didn't work that way on my system and old kernels kept piling up, all the way back to v3.13.0-24.

As I wanted to have only the latest two kernels present I ran the following two commands.

1) Show all installed packages with a name that starts with "linux-" and contains a number:


dpkg -l linux-* | awk '/^ii/{ print $2 }' | grep -e [0-9]

2) Specify the names of all unwanted packages and purge them:


sudo apt-get -y purge linux-headers-3.13.0-24 linux-headers-3.13.0-24-generic linux-headers-3.13.0-29 linux-headers-3.13.0-29-generic linux-image-3.13.0-24-generic linux-image-3.13.0-29-generic linux-image-extra-3.13.0-24-generic linux-image-extra-3.13.0-29-generic

Here is the...

0 0

LVM installs and encrypted installs use a separate /boot partition. The partition by default is capable of holding only four or five kernels, and can fill to capacity quickly. To prevent your /boot partition from getting full, you need to configure automatic removal of old kernels, or manually remove old kernels regularly.

Changing the kernel providing packages on your system requires commands with root access, so please read RootSudo.

Removing old kernels is easy to do on a system with sufficient free space in your root parition or separate boot partition. You can remove them manually, or configure unattended-upgrades to do it automatically. If you receive or have received an error from a package management tool, manual removal may not work until the problem is fixed. See Problems section.

Manual Maintenance

Using Apt

You can remove old kernels with a simple autoremove command in a terminal:

sudo apt-get autoremove --purge

Note: In...

0 0

For LVM, encrypted, or limited-storage systems, you need to regularly remove old kernels to prevent your computer (/boot partition) from running out of storage space.

Removing old kernels is easy. You can do it manually, or set unattended-upgrades to do it automatically. For details, open terminal from App Launcher or via Ctrl+Alt+T shortcut keys, and follow the steps below:

Remove Automatically Installed Kernels:

1. To remove the kernels that were automatically installed via regular system updates, open terminal and run:

sudo apt autoremove --purge

It will ask you to type in user password and then remove old kernels as well as other automatically installed packages that are no longer needed.

2. To enable automatic removing of old kernels:

Enable Kernel autoremoving may cause problems if your package management is broken, see

this bug


Run command to enable unattended upgrades. For Desktop Ubuntu 16.04, this...
0 0

Every month are new kernel updates, bug fixes and patches security system. If you regularly update your system, then your system gradually accumulates more the number of unused old kernels.

Thus, it is likely that the boot partition /boot on the hard drive will be filled in a certain period of time. If your /boot partition is full, you will not be able to upgrade, or can't even do a kernel upgrade to any latest available version. In this case, it is very important to regularly update the kernel and software. For this you must have enough free space in the /boot partition. To system to function correctly, you must have enough free space on the /boot and /root partitions.

We can easily remove the accumulated system cache, unwanted packages and dependencies using the following commands:

sudo apt-get autoremove sudo apt-get autoclean

But the problem is that this works only if the kernel was installed automatically, or if you installed them using the Update...

0 0

Old Linux kernels can take up a considerable amount of disk space. Apt ("sudo apt-get autoremove") tries to remove uneeded packages, including old Linux kernels, but it may fail to remove all of them.

Apt may fail to remove old Linux kernels when using an Ubuntu version that's under development, if you encounter


bug (which still occurs in Trusty), or if you've installed the kernels manually.

There are various commands out there for mass removing old Linux kernels, but they complicated (and hard to remember), and not all are safe. So what's the safest way of mass purging old Linux kernels in Ubuntu? Well,


to Dustin Kirkland, it's the "purge-old-kernels" command.


purge-old-kernelsman page

mentions that the command will never remove the currently running kernel. Also, by default, it will keep at least the latest 2 kernels, but you can override this using the "--keep" parameter (for instance "--keep 1" to...

0 0

It was my understanding that apt-get will not work because it is stuck at a point where it failed to install new items and finish running setup scripts because there is no room in the boot partition?

When I tried to remove one of the headers with dpkg, I'm met with this:

dpkg: dependency problems prevent removal of linux-headers-3.2.0-68:

linux-headers-3.2.0-68-generic depends on linux-headers-3.2.0-68.

dpkg: error processing linux-headers-3.2.0-68 (--remove):

dependency problems - not removing

Errors were encountered while processing:


When I try sudo apt-get remove linux-headers-3.2.0-68.......

Reading package lists... Done

Building dependency tree

Reading state information... Done

You might want to run 'apt-get -f install' to correct these:

The following packages have unmet dependencies:

linux-headers-3.2.0-68-generic : Depends:...

0 0

After installing a new Linux kernel, old kernels are not automatically deleted. They remain in your disk (/boot partition). You have to delete them manually. Why?

The main reason is to save disk space, which occupied by old kernels. Some systems may become unusable if not enough disk space is available in /boot partition. However, disk space is not a problem in modern systems.

An other reason is to clean up Grub boot menu. In Ubuntu, Grub boot menu is hidden by default. You can display it by pressing "SHIFT" continuously at boot time. More details in this post.

You will never delete your current kernel, of course. It is recommended to keep at least one or two older kernels, so you can boot your system in an emergency situation (hardware or software compatibility issues with the current kernel).

After removing old kernels, new grub boot menu will be available in next reboot.

In a healthy Debian system, each time you install a...

0 0

The Ubuntu Kernel team will release new Kernel updates, bug fixes, and security patches every month. If you are a long-time Ubuntu user, and regularly updating your Ubuntu system, then it might be accumulated with lot of unused and old Kernels. So, there are chances that the /boot partition in your hard disk will run out of disk space over a period of time. If your /boot partition is full, you can’t upgrade the system or you can’t even upgrade your Kernel to any latest available version. This is no good, and it is very important to regularly update your Kernel and softwares. To do so, You should have enough free space in the /boot partition. This is why it is always a good practice to remove unused Kernels, unnecessary packages, dependencies, and system cache periodically. Keep in mind that in order to function Ubuntu system properly, you must have enough free space in /boot and /root partitions.

Of course, We can easily wipe out the system cache, unneeded packages and...

0 0

How can I remove old kernels after upgrading to a new version?

It is annoying me to have these kernel entries in the Grub boot menu.

It is always recommended to leave the 2 latest versions of the kernel, but to remove other kernel versions I used the following commands:

dpkg -l | fgrep linux-image-

Never remove the kernel shown in uname -r or linux-image-generic-lts-utopic.

Finally sudo apt-get purge for the kernels you want to remove (see screenshot for reference).

Then sudo update-grub to update the Bootloader.

You can use this one-liner to automatically clean up all old kernels (make sure to restart the computer before doing this if you have just updated the kernel):

sudo apt purge $( dpkg --list | grep -P -o "linux-(headers|image)-\d\S+" | grep -v $(uname -r | grep -P -o ".+\d") )

What it does is uninstall (apt purge) the installed packages (dpkg --list) whose names match "linux-headers-[number]" or...

0 0

> On Wed, Oct 15, 2014 at 1:44 AM, Tom H

[hidden email]

> wrote:

>> On Mon, Oct 13, 2014 at 8:59 AM, Andrew Langhorn

[hidden email]

> wrote:


>>> Using sed, uname and apt, I am trying to ensure that all kernels older than

>>> the current and one behind are uninstalled from my machines. I keep the

>>> current one, for obvious reasons, and the previous kernel in case I need to

>>> roll back.


>>> To do this, I'm using `dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed

>>> "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' |

>>> xargs sudo apt-get -y purge`, which pipes the output of `uname -r ` to sed,

>>> ignores any lines beginning with `ii` to ensure installed kernels aren't

>>> removed, and applies that to the ouput of `dpkg -l 'linux-*`.


>>> This ensures that all previous kernels present are removed.


>>> Can I...

0 0

In our last article, we’ve explained how to delete old unused kernels in CentOS/RHEL/Fedora. In this article, we will explain how to delete old unused kernels in Debian and Ubuntu systems, but before moving further, you may want to install the latest version in order to take advantage of: security fixes, new kernel functions, updated drivers and so much more.

To upgrade your kernel to latest version in Ubuntu and Debian, follow this guide:

How to Upgrade Kernel to Latest Version in Ubuntu

Important: It is advisable to keep at least one or two old kernels to fall back to in case there is a problem with an update.

To find out the current version of Linux kernel running on your system, use the following command.

$ uname -sr Linux 4.12.0-041200-generic

To list all installed kernels on your system, issue this command.

$ dpkg -l | grep linux-image | awk '{print$2}' linux-image-4.12.0-041200-generic linux-image-4.8.0-22-generic...
0 0

I have a challenge to clean the boot drive that is 100% full.

I list previous versions:

dpkg -l linux-image*

And will get list of 12 versions,

rc linux-image-4.4.0-45-generic 4.4.0-45.66 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP rc linux-image-4.4.0-47-generic 4.4.0-47.68 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP

here the tail:


ii linux-image-4.4.0-78-generic 4.4.0-78.99 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP iF linux-image-4.4.0-79-generic 4.4.0-79.100 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP iF linux-image-4.4.0-81-generic 4.4.0-81.104 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP in linux-image-4.4.0-83-generic amd64 (no description available) iU linux-image-virtual amd64 This package will always depend on the latest minimal generic kerne...
0 0

Today, for the first time I encountered a strange behaviour on a machine with Ubuntu 15.10 . The problem itself was quite strange and rendered the machine unusable with default boot settings.

The problem

As I went to power up the machine this was the message when booting with default options. The user operating this machine had told me that he had

performed an update

prior to this problem. So I initially thought it was some kind of


with a newer kernel. So I went and use the precedent kernel, but nothing. And here the strange thing, I went and boot the third kernel in the list and

boom! It booted!

Now I decided to take a side trip to the solution and issued:

Everything went fine, however, I noticed the


was missing for some entries in the list. Then I tried listing files inside the boot partition and verified what I suspected: the initrd image for the last two kernels was nowhere to be found in the boot...

0 0

You can find the description of remove, autoremove, purge, clean and autoclean, as well as the syntax in the manpages for apt-get: man apt-get.

If you are still unsure after reading it though (I was) the best way to clarify it is to try it out.

Below is an example of a full dependency tree for vim:

You can get it with:

apt-rdepends -d vim > vim.dot dotty vim.dot

You can also get a list of the immediate dependencies using apt-cache depends (see Declaring relationships between packages for more info):

$ apt-cache depends vim vim Depends: vim-common Depends: vim-runtime Depends: libacl1 Depends: libc6 Depends: libgpm2 Depends: libselinux1 Depends: libtinfo5 Suggests: exuberant-ctags Suggests: vim-doc Suggests: vim-scripts

So it looks like vim depends on a number of packages, let's attempt to install it with apt-get install and see what happens:

$ sudo apt-get install vim ... The following extra packages will be installed: ...
0 0

Delete old kernels in Ubuntu 16.04. Remove Ubuntu kernels you don’t need. Clean Ubuntu and remove old kernel versions. How to delete old Linux Kernels (purge-old-kernels). Terminal commands for Ubuntu to remove old Kernels automatically.

Purge Old Kernels

You can easily remove the old unused kernels, i.e. purge-old-kernels that have been automatically installed via regular Ubuntu system update. To purge-old-kernels run the following command in terminal:

sudo apt autoremove --purge
sudo purge-old-kernels

Enable Automatic Removal of Old & Unused Kernels

You can easily enable unattended upgrades using System Settings. To do so, open System Settings and navigate to Software & Updates > Updates Tab. Here, check the box for *-security (and/or any other repositories you wish) Automatically check for updates: Set to any frequency (except ‘Never’) When there are security updates: Set to Download and Install...

0 0
0 0

Dustin Kirkland, Ubuntu Product and Strategy at Canonical, has informed the community about a simple method of helping them remove old kernels from Ubuntu Linux, thus freeing up a lot of disk space.

Ubuntu is a great OS and all that, but it has this problem that it kinda of stores many old kernel versions on the partition where it is installed. So after some time when you keep on updating your operating system to newer kernel versions, you'll notice that your disk drive runs out of free space.

If you're a beginner, you start wondering what's going on, asking questions like "Where's my disk space disappearing?" And this does matter when you're running Ubuntu from an SSD, which usually comes in smaller sizes than the traditional hard disk drives (HDD), those of 120GB being the most popular ones.

I am a long-time Ubuntu user, and if you're like me, you know some tricks that you need to do from time to time, via the command-line, to remove those pesky old kernels...

0 0

I have noticed that after installing a kernel update through the standard means of sudo apt-get dist-upgrade that sometimes (very rarely) when I run sudo apt-get autoremove afterwards it says that there is nothing to remove. The more likely is for it to say that there are old versions, and when they are removed running the command again tells you that there is nothing to remove (this happens occasionally).
What happens most of the time though is that I will run the command, it will tell me that there are old versions and allow me to remove them, then when I run the command again (even after doing a restart) I get the same result from it, and when I say that I do want to remove them then the exact same thing happens and gets outputted as before.

I am running Ubuntu GNOME 16.04 with GNOME 3.20, why does this happen? Why does it sometimes not show any old versions, sometimes only make me do it once, but most often make me do it...

0 0

If you update your current Ubuntu or Debian kernel, then the old kernel image will remain installed on your hard drive, despite it is no longer needed or used. Also, if you do a frequent system update, then a heap of kernel files will be taking up much hard disk space without being in use.

In this guide we will help you rid your system of these unused kernel images using a single command from the terminal. The tip is workable for both Ubuntu and Debian-based systems.

Getting Started

1. You can check your current used kernel with this command:

uname -r

2. To find a list of all installed kernels on your system, run this command:

dpkg --list | grep linux-image

3. To remove all unused kernels, run now this command:

sudo aptitude purge ~ilinux-image-\[0-9\]\(\!`uname -r`\)

- If "aptitude" is not installed, then install it with this command:

sudo apt-get install aptitude

4. Update now your Grub2...

0 0

Brief: Running out of space on your Linux system? Here are several ways you can clean up your system to free up space on Ubuntu and other Ubuntu based Linux distributions.

Over time, any operating system can become cluttered as programs are added and removed. If you have like a TB of storage capacity, you might not bother to clean up Ubuntu to make some disk space. But if your hard disk has limited space, like I have a 128 GB SSD laptop, freeing up disk space becomes a necessity.

In this article, I’ll show you some of the easiest tricks to clean up your Ubuntu system and get more space.

How to free up disk space in Ubuntu and Linux Mint

There are several ways you clean up disk space in Ubuntu and other Ubuntu based system. I have discussed several command line tricks here followed by some GUI options.

While I have mentioned several ways here, if you are a beginner, avoid the ones marked as ‘expert’. Not that you cannot use them, but it’s...

0 0

Hmm, I did not write it properly. I rather put here what I read yesterday...


There are at least two possibilities to deinstall software without all the dependency stuff.

The first one is :


dpkg -P --force-depends

This means the Debian Package Manager turns errors, based on dependencies, into warnings, and will deinstall the package. And by the way, with -P option, it will purge (remove) the config-files of the selected package.

The second one I know is:


apt-get remove --force-yes

This order causes apt-get to deinstall the selected package without paing attention to any troubles or dependencies.

But please be careful with this options! The result may be an unstable system!

-> So check the dependencies carefully and do not deinstall software other packages you need depend on.

Hope this...

0 0

As to answer why , refer to the file /etc/apt/apt.conf.d/01autoremove-kernels

As you can see, apt is told to never autoremove the kernels , as told by another (script) file, /etc/kernel/postinst.d/apt-auto-removal. And here it is:

If your script-fu is good enough you could edit it to save only couple kernels, though I can't help you there as my script fu isn't that good


In the /etc/kernel/postinst.d/apt-auto-removal there is this part:

if [ "$latest_version" != "$installed_version" ] \ || [ "$latest_version" != "$running_version" ] \ || [ "$installed_version" != "$running_version" ] then # We have at least two kernels that we have reason to think the # user wants, so don't save the second-newest version. previous_version= fi

So if you compare the output of 01autoremove-kernels file and uname -r you'll realize that the currently running kernel and the most recent before it, are kept to be never removed by that...

0 0
It's also kind of a garbage argument.

People who know they have broken kernels don't keep upgrading them, they stop and fix them.

People who don't know they have broken kernels also don't know they can boot with an older kernel, so they get nothing from the "backup".

We want to leave some time for people to realize their kernel is broken, so keeping three is probably just fine. Honestly, it would probably be adequate to just bump the oldest one off the queue whenever a newer one is requested. If you've got a tiny boot partition, maybe that means only two revisions. If you've got a huge boot partition it could be 20.

But just keeping them all and making people manually uninstall them gains you nothing, it's user-hostile for no reason. ...

0 0

I have been upgrading the kernel of our Ubuntu servers since they released a patch for the Meltdown vulnerability. I noticed that pretty much on all the servers, after I reboot I have to run apt autoremove twice for it to clean up all the old kernels that are still on the system.

If I run it the first time, it removes two old versions of the kernel at first:

% sudo apt autoremove Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: linux-headers-4.4.0-103 linux-headers-4.4.0-103-generic linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic linux-image-4.4.0-103-generic linux-image-4.4.0-104-generic linux-image-extra-4.4.0-103-generic linux-image-extra-4.4.0-104-generic 0 upgraded, 0 newly installed, 8 to remove and 2 not upgraded. After this operation, 596 MB disk space will be freed.

But then, after it is done and I run apt autoremove again, it removes yet an older version:

% sudo...
0 0

If we want to do it through a GUI, then install Synaptic Package Manager. And after getting a list of the kernels search in Synaptic for the kernel. For example, from the list given by the OP, search for linux 3.2.0-26 and that will come up with some of the kernel files related to kernel 3.2.0-26.

we will will see this


Select linux-image and right click and select Mark for Complete Removal. That should also remove any other kernel related files not found by the search criteria. Then click apply.

With Synaptic we can queue up several kernels for removal before clicking apply. Or do it one at a time. Just do not remove all the kernels. Save at least 2. To test if we are keeping a working kernel use Grub boot menu Advanced options for Ubuntu to load into earlier kernels to see if we get to a working desktop.

It is wise...

0 0

I update Ubuntu with a very simple script I call apt-update that looks like this:

$ cat ./apt-update sudo apt-get update; sudo apt-get dist-upgrade; sudo apt-get autoremove

Nothing too crazy there. It updates the apt-get cache, performs the upgrade, and then removes all the residual junk that’s laying around. Well, almost all. If you do this enough, eventually you’ll see the following (assuming you’ve got the default motd Ubuntu script running and you’re logging in from a terminal):

=> /boot is using 86.3% of 227MB

This is because that script I mentioned doesn’t consider old kernel images to be junk. However, unless you’ve got an abnormal /boot partition, it doesn’t take too many old images to fill it up.

A quick Google search found Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules. The solution on the page had exactly what I’m looking for, however, I couldn’t take it at face value. While the article offers an adequate solution,...

0 0

Ubuntu Desktop online tour

The Ubuntu community on Reddit

This subreddit is for news, information and general discussion related to Ubuntu.

Getting started


Homophobia, sexism, racism or any derogatory language will not be tolerated. Please refer to the Ubuntu Code of Conduct. Tech support questions must be links to Ask Ubuntu or the forums (here's why). Posts must relate to Ubuntu (i.e. not just Linux in general). No memes or follow-ups to picture posts ("I see your Ubuntu-CDs and give you these...").

Support resources



Ubuntu Members and employees of Canonical have emblems next to their names, indicating their affliation. Members are distinguished by a small Ubuntu logo next to their names, Canonical employees by a purple "O", a portion of Canonical's logo.

To apply for flair, please see here.

Subreddit CSS

The CSS on /r/Ubuntu is an on going development keeping up to date with...

0 0

A while back I wrote a post on how to remove old kernels from your Ubuntu system. While that process works just fine, it is a four step process. One person who read that post left a comment with a nice command line one-liner that removes all but the currently running kernel. And while that one-liner works quite well, I must admit that I don't understand all the regular expressions used in it, so I decided to try and come up with my own one-liner to remove the old kernels from my system.

I'm going to take you through this step by step so you can see how the individual commands in this one-liner tie together. If you're impatient, you can skip to the end to see the final command.

Step 1) List all packages that start with "linux-"

We'll use the dpkg command with the -l switch to list the packages, whether installed or not, that start with the string linux-.

dpkg -l linux-*

Step 2) Filter that list to show only installed packages

To filter...

0 0

e have four different versions of Linux kernel installed by the yum command under CentOS Linux. Currently, I am using only latest version 2.6.18-53.1.4.el5.

What is proper and suggested method to remove old kernels

from a CemtOS / Debian Linux server?

Most Linux distro keeps old kernel files so that you can revert in case of emergency pop up due to hardware or software incompatibility issues. A kernel is nothing but a set of files on Linux box. Following is the suggested way to remove old kernels safely on Linux based system.

uname -r
Sample outputs:


Step #2: List all installed kernels

Use the rpm command or dpkg command on Linux:
# rpm -q kernel
Sample outputs (from RPM based distro such as CentOS/RHEL):

kernel-2.6.12-1.el5 kernel-2.6.18-17.el5 kernel-2.6.18-53.el5 kernel-2.6.18-53.1.4.el5

Debian / Ubuntu Linux user, enter:
$ dpkg --list 'linux-image*'
Sample outputs:

0 0