• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SMASHING LAB

GUIDES | LINUX | GEEKY STUFF

  • Nginx
  • Linux
  • Guide
  • Ubuntu
  • WordPress
  • Drones, My Hobby

Safely Remove Old Kernels From Ubuntu

By Imran Yousaf

Do you know that during the installation of a new kernel in Ubuntu, the old one is not deleted, but remains in the system? Over time, the number of old kernels increases and can take up quite a bit of the hard disk space. In some cases, autoremove can help (that is: sudo apt-get autoremove), it is intended to clean the system of unused packages, but it is not always effective with respect to kernel files.

The autoremove command may not work for older kernels if you use the version of Ubuntu that is under development or the kernel you want to uninstall was installed manually. Also, you can find a bug when the kernels are not marked for automatic deletion.

You can, of course, use utilities such as Ubuntu Tweak or special commands of 150 characters (which you will never remember), but even with their use, no one is immune to errors. So is there any safe way to clean up Ubuntu from old kernels? Yes, this is purge-old-kernels script from Dustin Kirkland (one of the developers of the distribution).

According to the man page purge-old-kernels is a program (script) that can safely clean Ubuntu from old kernels. By default, the program removes everything except the two most recent cores. Thus, in the event of any errors with one, you will be able to boot the system with a different kernel, more stable.

In Ubuntu 16.04 purge-old-kernels goes as part of the package byobu so to use the script, you need to install this package:

1
sudo apt-get install byobu

In older versions of Ubuntu, the script is part of the bikeshed package. Installation:

1
sudo apt-get install bikeshed

Now, in order to clean the system of old cores it is enough to enter in the terminal:

1
sudo purge-old-kernels

If you want to keep a different number of cores in the system, you need to use the keep key to do this. For example, if I want 3 kernels to be left after cleaning, the command will look like this:

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

That’s it. This is what I wanted to tell in this article. I hope you this information will help.

Some more articles you might also be interested in …

  • TeamViewer in Ubuntu - How it Works
  • How to add a Service to Startup in Ubuntu or CentOS
  • Guide How to Install Apache in Ubuntu 18.04
  • How to Install Brackets on Debian / Ubuntu
  • Install and Configure Apache on Ubuntu Server
  • How to Install and Use Multiple Versions of PHP on…
  • Complete Guide: How To Install Ubuntu Server 18.04
  • How To Dual Boot Linux/Ubuntu and Windows 10…
  • How to Install LAMP Stack (Linux, Apache, MySQL,…
  • How to Create a Sudo User and Sudo Group in Ubuntu
Tweet
Pin
Share
0 Shares

Filed Under: Guide, Linux

Primary Sidebar

  • Twitter
  • Facebook
  • Google+

Recent Posts

  • How to install Nextcloud on CentOS 8
  • How to install Zabbix on openSUSE Leap 15.1
  • How to Easily Configure Your Domain’s Email Account with Gmail?
  • Tails 4.4 OS Released with Tor Browser 9.0.6
  • How to Convert JPG to PDF in Linux

Subscribe to our Newsletter

Useful articles, tips and videos about creating and promoting websites to your mail



* required field


  • Contact Us
  • Privacy Policy
  • About Us

Copyright © 2021. Smashing Lab