Ubuntu 18.04 remove all unused old kernels

You can remove all unused old kernels on Ubuntu 18.04 using the following steps:

  1. Check the installed kernels: Run the following command to check the list of installed kernels on your system:
dpkg --list | grep linux-image

This will show a list of all the installed kernels, including the current one you are using.

  1. Remove old kernels: You can remove old kernels using the command below, replace the version number of the kernel you wish to remove with the version number of the kernel you see in the dpkg command above.
sudo apt-get purge linux-image-X.X.X-X-generic
  1. Clean up the boot partition: After you have removed the old kernels, it’s a good idea to clean up the boot partition by running the following command:
sudo apt-get autoremove

This will remove any unneeded packages and dependencies.

  1. Check that the kernels are removed : you can check the list of installed kernels again by running the command :
dpkg --list | grep linux-image
  1. Reboot: Finally, it is recommended to reboot your system after removing the old kernels to ensure that the system is using the correct kernel and to ensure that there are no issues with the system after the kernels have been removed.

It is worth noting that you should only remove kernels that are not currently in use, as removing the current kernel may cause your system to fail to boot.

Leave a Comment