Are you an Ubuntu user looking to free up some space on your system? One effective way to accomplish this is by removing old kernels. Over time, as you update your Ubuntu operating system, multiple kernel versions may accumulate, taking up valuable disk space.
In this article, we will guide you through the process of removing old kernels in Ubuntu, ensuring a cleaner and more efficient system.
Table of Contents
As you use your Ubuntu system, you may notice that each time a kernel update is installed, a new entry is added to the GRUB boot menu.
While it is useful to have multiple kernel versions available for troubleshooting purposes, keeping too many can lead to disk space wastage.
Why should you remove old kernels?
Removing old kernels offers several advantages.
Firstly, it helps you reclaim valuable disk space, which can be crucial, especially if you have a limited storage capacity.
Secondly, it improves system performance by reducing clutter and streamlining the boot process.
Lastly, it minimizes security risks associated with outdated kernel versions.
Checking your current kernel version
Before removing old kernels, it is essential to identify the current kernel version running on your Ubuntu system. To do this, open a terminal and execute the following command:
uname -r
The output will display the active kernel version.
uname -r
5.13.0-46-generic
Determining which kernels to remove
To determine which kernels can be safely removed, you need to list all installed kernels on your system.
Execute the following command in the terminal:
dpkg --list | grep linux-image
The command will generate a list of installed kernel versions, along with their associated package names as shown below.
ubuntu@ub21:~$ dpkg --list | grep linux-image
rc linux-image-5.13.0-19-generic 5.13.0-19.19 amd64 Signed kernel image generic
rc linux-image-5.13.0-23-generic 5.13.0-23.23 amd64 Signed kernel image generic
ii linux-image-5.13.0-35-generic 5.13.0-35.40 amd64 Signed kernel image generic
ii linux-image-5.13.0-46-generic 5.13.0-46.51 amd64 Signed kernel image generic
ii linux-image-generic-hwe-20.04 5.13.0.46.55 amd64 Generic Linux kernel image
Removing old kernels using the command line
Removing old kernels via the command line is a straightforward process. Once you have identified the kernels you wish to remove, execute the following steps:
1. Open a terminal.
2. Use the sudo apt-get purge <kernel-package-name>
command to remove the kernel package. Replace <kernel-package-name>
with the appropriate package name of the kernel you want to remove.
ubuntu@ub21:~$ sudo apt-get purge linux-image-5.13.0-19-generic
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfwupdplugin1 linux-headers-5.13.0-35 linux-headers-5.13.0-35-generic linux-image-5.13.0-35-generic
linux-modules-5.13.0-35-generic linux-modules-extra-5.13.0-35-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
linux-image-5.13.0-19-generic*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 202435 files and directories currently installed.)
Purging configuration files for linux-image-5.13.0-19-generic (5.13.0-19.19) ...
ubuntu@ub21:~$
3. Repeat the process for each kernel you want to uninstall.
Remember to exercise caution when removing kernels. It is advisable to keep at least one or two previous versions as a backup in case of any issues with the latest kernel.
Removing old kernels using a graphical tool
If you have Ubuntu Desktop and want to use GUI to remove old kernels, then you can use “update manager” to do that.
$ sudo update-manager
Note: We did not find this method to be reliable to remove old Kernels from the Ubuntu machines.
Verifying the removal of old kernels
After removing the old kernels, it’s important to verify that they have been successfully removed. To do this, you can follow these steps:
- Open a terminal.
- Execute the command
dpkg --list | grep linux-image
to list all installed kernel versions. - Compare the output with the previous list you generated before removing the kernels. The old kernel versions should no longer be present.
If the old kernel versions are no longer listed, congratulations! You have successfully removed them from your Ubuntu system.
Conclusion
Removing old kernels in Ubuntu is a practical way to free up disk space, enhance system performance, and reduce security risks. Whether you choose the command line method or utilize graphical tools, the process is straightforward and can be completed with ease.
Remember to exercise caution when removing kernels and always keep a backup of a previous version for troubleshooting purposes.
By following the steps outlined in this article, you can efficiently manage your kernel versions and ensure a cleaner and more efficient Ubuntu system. If you want to learn how to change Ubuntu hostname, check out this article.
FAQs
1. Can I remove all old kernels from my Ubuntu system?
While it is possible to remove all old kernels, it is recommended to keep at least one or two previous versions as a backup in case of compatibility issues or other problems with the latest kernel.
2. Will removing old kernels affect my current Ubuntu installation?
No, removing old kernels will not affect your current Ubuntu installation. However, it is always recommended to have a backup and exercise caution when modifying system files.
3. How much disk space can I expect to reclaim by removing old kernels?
The amount of disk space you can reclaim depends on the number and size of the old kernel versions installed on your system. It can vary but is usually several hundred megabytes or even gigabytes.
4. How often should I remove old kernels from my Ubuntu system?
It is a good practice to periodically check for and remove old kernels, especially after system updates. This helps prevent unnecessary disk space usage and keeps your system running smoothly.