Utilities such as apt-get generally install kernel updates by adding the new kernel to the Linux boot list and set it as the default. This means that the next time the system boots, the new kernel will be loaded. The problem is that the old kernel is still there (just incase the new one doesn’t work, you’ve got a fall back!), and the kernel before that, and the kernel before that…
The current 3.x kernel for Ubuntu is around 20MB so it doesn’t take long for the kernel updates to fill a tiny 200-or-so-Mb boot partition where they are stored.
The good news is that it’s easy to clear out the old updates, but it’s important to not remove the latest one that you’re using.
Which Kernel am I Running?
It’s quick and easy to see which kernel version you are running. Use the uname command with the -a switch and pay attention to the version numbers reported.
uname -a
3.19.0-47-generic
This shows that you’re using version 3.19.0-47.
List Currently Installed Kernels
Next you’ll need to list the kernel packages that are currently installed so that you can remove any outdated ones to free up the space on the /boot partition.
Run the below dpkg command to list the installed kernel packages and their versions.
dpkg --list 'linux-image*'
The above output shows several versions of kernel that are all taking up space on the /boot partition however we only really need the current running version given by the above uname -a command. It’s a good idea to keep the last 2 kernels just incase you notice an issue down the line, but the above list is quite excessive.
Remove Unused Kernel Packages to Free Space on /boot
Once you’ve identified your current kernel and the kernel packages you have installed it’s time to remove the ones you don’t need.
Using apt-get enter the package names of the kernel packages to remove.
apt-get remove linux-image-3.19.0-25-generic
If you get an error running this command then see the next section.
note: the above screenshot of the installed packages cropped the full version name – it’s missing the generic part. You can use tab completion with the apt-get command, or use an asterisk after the version number to remove the required package.
Errors Removing Packages
If you get an error warning about dependencies similar to the below then you may need to manually remove a few kernel packages to free up some space.
[root@server:~] $apt-get remove linux-image-extra-3.19.0-25-generic
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-image-generic-lts-vivid : Depends: linux-image-3.19.0-49-generic but it is not going to be installed
Depends: linux-image-extra-3.19.0-49-generic but it is not going to be installed
Recommends: thermald but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
The problem here is that the original update failed to install the latest version of the kernel (version 3.19.0-49-generic in this case) and apt-get doesn’t like doing anything else until that problem has been resolved.
First we need to free up some space. Carefully delete 2 of the older kernel packages with a command similar to the below, but with old version numbers from your system returned by the above section List Currently Installed Kernels.
rm /boot/*-3.19.0-25*
rm /boot/*-3.19.0-33*
Check and double check this command because there’s no going back once it’s ran! It’s perfectly safe to do as long as you are using old version numbers that you’re no longer using.
You can now run apt-get to complete the original upgrade now that it has the space. This will remove the error when trying to remove the unused kernel packages in the above section.
apt-get install -f
Now go back to the above section and remove the old kernel packages that you no longer need.