Removing Linux kernel files manually

In this article I am writing about removing Linux kernel files manually from your system. I am explaining this on Ubuntu distribution.

As we know we should use apt-get autoremove it we want to remove not needed packages e.g. old kernel files. In my situation for some reason this did not work (I was trying to find out why but not much luck). I had to deal with that as my /boot partition was full and new kernel file was available to instal - installation failed as there was not enough space on /boot partition. Below I provide steps I use to remove old kernel files manually.

Please notice that I tested this process but I do not guarantee it won't break your system - make sure to take backup of your system first.

As mentioned above on my system /boot was mounted as separate partition. To check used space enter below command:

df -h

Next thing to check is what current version of kernel system is using (you cannot remove this one). Command to check this is:

uname -a

You should see something like this and this is the current version of kernel files that system is using:

Linux domex-master 3.2.0-57-generic #87-Ubuntu SMP Tue Nov 12 21:35:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

If you list content of the /boot (ls -la /boot) partition you can see that there are files for old version of kernel that system doesn't use any more. They use space of /boot partition and these files should be removed to free up space for newest version of kernel files.

To list installed kernel versions on you system you can use dpkg tool, for example:

sudo dpkg --list 'linux-*'

For each version you should see 3 different files (for system below 12.04 replace "generic" by "server"):

  • linux-headers-<version>
  • linux-headers-<version>-generic
  • linux-image-<version>-generic

Now we have to remove old kernel files using below commands:

sudo apt-get remove linux-image-<version>-generic

sudo apt-get purge linux-image-<version>-generic

sudo apt-get remove linux-headers-<version>-generic

sudo apt-get purge linux-headers-<version>

If you now run sudo dpkg --list 'linux-*' the old files should be marked as "un". If not I found that running bellow command would do that:

sudo aptitude purge linux-image-<version>-generic

In during removing files I had one more problem any of the above commands did not work for me. I had to manually remove old kernel files from /boot partion. I did this by running below command on old files until there was enough space for system to run above commands:

cd /boot

sudo rm initr.img-<version>-generic

Just for your information what I wrote above is based on various pages that address this problem but all this is distributed over different pages. I created this article to put all steps in one place.


Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.