Bobcares

Remove old kernels ubuntu like an expert

by | Aug 28, 2022

As higher kernel versions of Linux are released, the system may update to a newer kernel. Let’s see how to Remove old kernels ubuntu from our Server Management Services, Bobcares help Customers with all sorts of queries.

 

The old kernels take up space on your HDD. You can have one or two old kernels installed if you want to boot between them. By default, the Linux versions keep the current kernel additionally with one older version.

 

Although in some instances, Linux doesn’t remove old versions of the kernel. Let us now discuss the possible steps to perform the old kernel removal task.

 

Remove old kernels ubuntu

 

Remove Old Kernel Ubuntu Procedures

 

Display List of Kernel Versions Available :

 

To view kernel versions installed on the server, you need to enter the following:

 
sudo dpkg ––list | egrep –i ––color ‘linux-image|linux-headers’
 

This output lists all files that are labeled linux-image or linux-header. An approximate number of old kernels will be shown on the system.

 

Similarly to count the exact number of kernels, you can follow the below command:

 
sudo dpkg ––list | egrep –i ––color ‘linux-image|linux-headers’ | wc –l
 

This will display the total number of both linux-image and linux-headers available.

 

Remove Old Kernels :

 

The “apt ” package manager will automatically remove all old kernels from the list :

 
sudo apt-get ––purge autoremove
 

Initially, the system scans for the unused kernels and presents a summary of the files that need to be deleted, and prompts you to confirm if you wish to detach old kernels by pressing “y” and click on Enter to delete.

 

Step1: Manually Remove Individual Kernels from Command-Line

 

You can manually remove an individual kernel by naming them specifically.

 

1. First, List the installed kernels with status:

 
dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
 

2. Remove a kernel with the installed removal status:

 
sudo dpkg ––purge [kernel_version]
 

Make sure you type the exact name and version of the kernel you want to remove, you can follow the snippet below:

 
sudo dpkg ––purge linux-image-5.3.0-28-generic
 

Step 2: Removing old kernels using GUI software updater tool

 

Ubuntu have associated with the graphical management of software package updates called “update-manager“.

 

First, start the update manager from GUI or open the terminal application, Next type the command “update-manager“.

 

Now select an option called “Unused kernel updates to be removed” >> click on the Install Now button.

 

Step 3:  To Remove an Old Kernel with Ubuntu Cleaner

 

Ubuntu Cleaner allows maintaining your system at optimal levels by removing unwanted browser caches, packages, and software installers. This open-source software needs to be retrieved as a PPA (Personal Package Archives) and then configure.

 

To add the Ubuntu Cleaner PPA follow the below command in the terminal :

 

sudo add-apt-repository ppa:gerardpuig/ppa

 

Second, install Ubuntu Cleaner with the command:

 

sudo apt install ubuntu-cleaner -y

 

Finally, the installation process has successfully completed, now access the Ubuntu Cleaner:

 

sudo ubuntu-cleaner

 

By using the Ubuntu Cleaner graphical interface, remove the old kernels:

 
  • Select the Old Kernel box.
 
  • Choose the kernels that you want to remove.
 
  • Click the Clean button >> click Continue if you agree.
 
  • The erasing process will be in progress and once finished you will get a “System is clean” confirmation message.
 

Step 4: Remove Old Kernels Using Ubuntu Software Center

 

1. Access to the Ubuntu Software Center.

 

2. Enable the search bar option and search for linux-image.

 

3. Now to display the list of Linux kernels, click on the hyperlink “Show xx technical items” In the lower-left corner.

 

4. Select the older versions and click the Remove button.

 

5. log in to the terminal window and Refresh the GRUB (boot) menu by :

 

sudo update-grub

 

Step 5: Delete Unused Kernels from Ubuntu 16.04 and Older

 

The previous Linux versions didn’t include tools to manage old kernels, to remove old Linux kernels. First, you need to install a tool called byobu:

 

sudo apt-get install byobu

 

Then, run the utility command:

 

sudo purge-old-kernels

 

This utility scans your system and removes all except the latest two kernels. You can adjust the default value 2 and keep more than the default by using the ––keep function:

sudo purge-old-kernels ––keep 3 –qy

 

Make sure that you do not remove the current Linux kernel that is in use. Doing so your system might not be able to boot. Use the uname -r command if you need to know your current kernel version.

 

On condition, if every option failed and still can’t remove the Linux kernel

 

Accordingly, you can run a simple script that will run on Ubuntu 16.04/18.04/20.04 and above:

 


$ sudo purge-old-kernels
# keep at least 2 kernels #
$ sudo purge-old-kernels --keep 2

 

Conclusion

To sum up, you have seen several methods to remove old kernels from Ubuntu 19.04 version to the older. Sweeping out of kernels can help to recover unnecessary disk space in Linux. Recommended as a best practice for having a healthy accessible system by clearing old kernels.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.