Steps to safely remove Linux kernels (Ubuntu)
Note: Please understand, these instructions can make your system non-bootable. If you’re unsure, do not continue.
If you’re trying to update the kernel and low/empty disk space errors are shown, it’s probably because the /boot/ directory is full.
Use this command to see the available space of /boot/:
sudo df -h
Now check the kernel version you’re using. Make a note so you don’t delete your current kernel files:
sudo uname -r
View all of the available kernels on your system:
dpkg --list | grep linux-image
With this list, make commands to delete each kernel. Remember not to include the kernel you’re using, run each line separately, replacing the version numbers with your kernel versions, e.g. x.x.x-xx to 4.4.0-31:
sudo update-initramfs -d -k x.x.x-xx-generic sudo apt-get purge linux-image-x.x.x-xx-generic sudo apt-get purge linux-image-extra-x.x.x-xx-generic
Now update the grub2 boot loader:
These commands have been tested on Ubuntu 16.04. More information can be found here: https://help.ubuntu.com/community/RemoveOldKernels