How To Remove Old Linux Kernel Images (Ubuntu)

August 3, 2017
Don’t delete them using ‘rm’.

Each version of linux kernel is about 200-300MB.

TL;DR

# List linux kernel package
dpkg --list | grep linux-image

# Check current version, don't remove this
uname -r

# Remove Kernel Image
sudo apt-get purge linux-image-x.x.x-x

# Remove Kernel Header
sudo apt-get purge linux-headers-x.x.x-x

List installed kernels

Use dpkg to list all the kernels installed.

# dpkg --list | grep linux-headers
dpkg --list | grep linux-image
# Output
ii  linux-image-3.13.0-100-generic            3.13.0-100.147                             amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-3.13.0-103-generic            3.13.0-103.150                             amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
...
ii  linux-image-extra-3.13.0-100-generic      3.13.0-100.147                             amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-extra-3.13.0-103-generic      3.13.0-103.150                             amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
...

Check you current kernel (usually the one with the highest version number) to make sure you don’t remove them accidentally.

uname -r
# Output: 4.4.0-87-generic

Location of linux kernels

It’s not necessary to find out the location of the kernels as we won’t be deleting them directly using rm, but just in case you are curious.

linux-headers is stored at /usr/src.

cd /usr/src
sudo du -sh *
# Output
95M   linux-headers-3.13.0-100
15M   linux-headers-3.13.0-100-generic
95M   linux-headers-3.13.0-103
15M   linux-headers-3.13.0-103-generic
...
106M  linux-headers-4.4.0-83
15M   linux-headers-4.4.0-83-generic
106M  linux-headers-4.4.0-87
15M   linux-headers-4.4.0-87-generic
...

To find out location of a particular kernel package, use dpkg –listfiles.

dpkg --listfiles linux-image-3.13.0-103-generic
# Output
...
/usr/share/doc/linux-image-3.13.0-103-generic
...
/lib/modules/3.13.0-103-generic
...
/lib/firmware/3.13.0-103-generic
...

Remove kernel

I would recommend to keep at least 3 latest versions of kernels including the current version (uname -r).

apt-get

Use sudo apt-get purge linux-image-x.x.x-x to remove a specific version of the kernel.

sudo apt-get purge linux-image-3.13.0-100
# Output
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'linux-image-3.13.0-100-generic' for regex 'linux-image-3.13.0-100'
Note, selecting 'linux-image-3.13.0-100-lowlatency' for regex 'linux-image-3.13.0-100'
Package 'linux-image-3.13.0-100-lowlatency' is not installed, so not removed
The following packages will be REMOVED:
  linux-image-3.13.0-100-generic* linux-image-extra-3.13.0-100-generic*
0 upgraded, 0 newly installed, 2 to remove and 8 not upgraded.
After this operation, 195 MB disk space will be freed.

You can remove linux-headers as well using sudo apt-get purge linux-headers-x.x.x-x

sudo apt-get purge linux-headers-3.13.0-100
# Output
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-3.13.0-100* linux-headers-3.13.0-100-generic*
0 upgraded, 0 newly installed, 2 to remove and 7 not upgraded.
After this operation, 76.9 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 475653 files and directories currently installed.)
Removing linux-headers-3.13.0-100-generic (3.13.0-100.147) ...
Removing linux-headers-3.13.0-100 (3.13.0-100.147) ...

Though there are commands to remove a range of linux kernels, I would like to play safe to avoid accidental removal.

GUI

If you prefer GUI, you can try sypnatic or Ubuntu Tweak.

Update on [2017-08-03]: Ubuntu Tweak is no longer maintained since 2016-05-02.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.