How to delete old kernels that are no longer used on Ubuntu

Source: Internet
Author: User

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.

  1. $ dpkg --list|grep linux-image
  2. $ dpkg --list|grep linux-headers

You can remove a specific version (for example, 3.19.0-15) from the list of kernel images ).

  1. $ sudoapt-get purge linux-image-3.19.0-15
  2. $ 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.

  1. $ sudoapt-get purge linux-image-3.19.0-{18,20,21,25}
  2. $ 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.

  1. $ 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.