Here’s how to clean your boot partition on Ubuntu or similar Debian based systems
Reboot the machine
It is important that the latest kernel is in use while cleaning up the old kernels. A simple reboot will ensure that the latest kernel is in use.
Check the current kernel version
The current kernel version can be checked using the following command:
uname -r
Show a list of installed kernels
Next, we need to fetch a list of all the installed kernels. This can be obtained using the following command:
dpkg --list 'linux-image*' | grep ^ii
Alternatively, an easier form would be:
sudo dpkg --list 'linux-image*' | awk '{ if ($1=="ii") print $2}' | grep -v `uname -r`
Remove the old kernels
We now need to remove the unused kernels from the step above. The following command needs to be executed for every unused version:
sudo apt purge linux-image-VERSION
Remove dependencies
With the old kernels removed, we now need to remove the dependencies by using:
sudo apt --purge autoremove
Update grub
Finally, we need to update grub to use the latest kernel.
sudo update-grub
And that should be it!
Disclaimer: The steps above have been tested with Ubuntu 18.xx and above. Replace apt
with apt-get
for older versions.
References: The steps above have been referenced from: