Each version of linux kernel is about 200-300MB.
TL;DR
# List linux kernel packagedpkg --list | egrep -i 'linux-image|linux-headers' | awk '{ print $2 }'# Check current version, don't remove thisuname -r# Remove Kernel Imagesudo apt-get purge linux-image-x.x.x-x# Remove Kernel Headersudo apt-get purge linux-headers-x.x.x-x
List installed kernels
Use dpkg to list all the kernels installed.
# dpkg --list | grep linux-headersdpkg --list | grep linux-image# Outputii 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 SMPii 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 SMPii 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...
dpkg --list | egrep -i 'linux-image|linux-headers' | awk '{ print $2 }'
linux-headers-5.4.0-62
linux-headers-5.4.0-62-generic
linux-headers-5.4.0-65
linux-headers-5.4.0-65-generic
linux-headers-generic
linux-image-5.4.0-58-generic
linux-image-5.4.0-62-generic
linux-image-5.4.0-65-generic
linux-image-generic
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/srcsudo du -sh *# Output95M linux-headers-3.13.0-10015M linux-headers-3.13.0-100-generic95M linux-headers-3.13.0-10315M linux-headers-3.13.0-103-generic...106M linux-headers-4.4.0-8315M linux-headers-4.4.0-83-generic106M linux-headers-4.4.0-8715M 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# OutputReading package lists... DoneBuilding dependency tree Reading state information... DoneNote, 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 removedThe 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# OutputReading package lists... DoneBuilding dependency tree Reading state information... DoneThe 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.