How to delete old kernels that are no longer used on Ubuntu
Q: I have upgraded the kernel several times on my Ubuntu. Now I want to delete these old kernel images to save my disk space. How to delete the kernel of previous versions on Ubuntu in the simplest way?
There are several methods to upgrade the kernel on Ubuntu. On the Ubuntu Desktop, software updates allow you to check and update each day to the latest kernel. On the Ubuntu server, one of the most important security update projects is the unattended-upgrades package which automatically updates the kernel. However, you can also use the apt-get or aptitude command to update the data.
As time passes, continuous Kernel updates will accumulate a large number of unused kernels in the system, wasting your disk space. Each kernel image and its associated modules/header files occupy-MB of disk space. Therefore, the disk space wasted by the unused kernel will increase rapidly.
The GRUB manager maintains a GRUB entry for each old kernel for your use.
As part of Disk Cleanup, if you no longer use these images, you can consider clearing these images.
How to clear old kernel Images
Before deleting the old kernel, remember to keep two recent kernels (the latest and previous versions) to prevent major version errors. Now let's look at how to clean up the old Kernel on Ubuntu.
The Ubuntu kernel image contains the following packages.
- Linux-image-: Kernel image
- Linux-image-extra-: Additional kernel module
- Linux-headers-: kernel header file
First, check the kernel image installed in the system.
$ dpkg --list|grep linux-image
$ dpkg --list|grep linux-headers
You can remove a specific version (for example, 3.19.0-15) from the list of kernel images ).
$ sudoapt-get purge linux-image-3.19.0-15
$ sudoapt-get purge linux-headers-3.19.0-15
The preceding command deletes the kernel modules and header files associated with the kernel image.
Note: If you have not upgraded the kernel, deleting the old kernel will automatically trigger the installation of the new kernel. After the old kernel is deleted, the GRUB configuration will be automatically upgraded to remove the GRUB entry from the GRUB menu.
If you have many useless kernels, you can use shell expressions to delete multiple kernels at a time. Note that this bracket expression is valid only in bash or compatible shell.
$ sudoapt-get purge linux-image-3.19.0-{18,20,21,25}
$ sudoapt-get purge linux-headers-3.19.0-{18,20,21,25}
The preceding command deletes four kernel images: 3.19.0-18, 3.19.0-20, 3.19.0-21, and 3.19.0-25.
If the GRUB configuration is not correctly upgraded after you delete the old kernel for any reason, you can try to manually update the configuration with the update-grub2 command.
$ sudo update-grub2
Restart now to verify that the GRUB menu has been properly cleared.
L
Author: Dan Nanni Translator: geekpi Proofreader: wxy
This article was originally compiled by LCTT and launched with the honor of Linux in China
This article permanently updates the link address: