YUM Delete / Remove Old Kernels on Fedora, CentOS, Red Hat (RHEL)

This is quick guide howto delete/remove/clean old kernels on Fedora, CentOS, Red Hat (RHEL). I use here two kernel as example, if you want to keep other more or less, then adjust amount of installed kernels as you wish. Normally reason why you maybe want remove kernels is limited disk space, example on VPS servers and laptop. This is very easy task, you need yum-utils package.

1. Check Installed Kernels

rpm -q kernel
kernel-2.6.32-279.el6.x86_64
kernel-2.6.32-279.2.1.el6.x86_64
kernel-2.6.32-279.5.2.el6.x86_64
kernel-2.6.32-279.9.1.el6.x86_64

2. Delete / Remove Old Kernels

## Install yum utils ##
yum install yum-utils
 
## Package-cleanup set count as how many old kernels you want left ##
package-cleanup --oldkernels --count=2

3. Make Amount of Installed Kernels Permanent

Edit /etc/yum.conf and set installonly_limit:

installonly_limit=2
Follow If Not True Then False Updates!

14 Comments

  1. Thank you for your article. Instead of installing yum-utils, why not just use “yum erase” on the kernel packages?

    • Hi kkaos,

      You could of course use “yum erase” (from “rpm -q” output), but with yum-utils package-cleanup you can just simply setup count, how many kernels you want to left, without knowing how many kernels you even have. :)

      • Execellent answer ;-)

  2. Thanks for you post

  3. If there is a new kernel and update, the older kernel will be deleted automatically after doing this?

    • Hi Martín,

      Yes, if you use installonly_limit=[number of kernels] in /etc/yum.conf.

  4. thank u .

  5. I went to /var/log/yum.log, spotted the installed file, concatenated all in one line, added yum remove before it and pressed enter, job done, the new failed kernel disappeared. In all cases, make sure you have booted from a kernel that’s not the one you intend to erase….

    • Hi rolandc,

      Little bit different thing, this guide is removing old kernels and keep amount what you want.

      But yes sometimes it’s useful to remove latest kernel too. Normally I just keep broken kernel also and just boot some another working kernel and wait next kernel build.

  6. Short and sweet. I love my Centos.

  7. Hi, thanks for the arrticle, I want to know that if I update, I’ll get a new kernel , do I need to install all the softwares or packages I have installed in the old kernel in the new one?

    • Hi srinath,

      Could you tell more specific what you have installed in the old kernel? Some packages are compiled automatically when you update kernel.

  8. Loaded plugins: product-id, security, subscription-manager
    Updating certificate-based repositories.
    Unable to read consumer identity
    Setting up Install Process
    Nothing to do
    what is this mean??????

    • Hi dariush,

      Obviously you are using RHEL, first one question, do you have RHEL subscription?

Leave a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>