You can remove all unused old kernels on Ubuntu 18.04 using the following steps:
- 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.
- 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
- 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.
- Check that the kernels are removed : you can check the list of installed kernels again by running the command :
dpkg --list | grep linux-image
- 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.