YUM/DNF Remove Old Kernels on Fedora/CentOS/RHEL - Comment Page: 2

This is quick guide howto delete/remove/clean old kernels on Fedora 28/27/26, CentOS 7.5/6.10, Red Hat (RHEL) 7.5/6.10. 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. [inttf_post_ad1] 1. Check Installed Kernels and All Kernel Packages rpm -qa kernel\* |sort...

30 comments on “YUM/DNF Remove Old Kernels on Fedora/CentOS/RHEL - Comment Page: 2

1 2
    1. I noticed you have updated this page for those of us running this centuries fedora however you didnt mention that yum-utils has been deprecated – the dnf way of doing this is not very obvious and I gave up on it after reading a half a dozen man pages.

      fortunately deprecated means ‘still works but wont for much longer’ (key words here are ‘still works’) so I used your method which still works :-)

      Another point Id like to make is that nearly all the commands on this page must be run as root

      Reply
    2. Thank You. Very useful.

      Reply
    3. I think we should run below command after doing the above configurations

      package-cleanup –oldkernels –count=2

      Reply
    4. Hey. The package-cleanup command no longer works; yum is deprecated and you have to use dnf instead, but it looks like the package-cleanup command relies on the yum command that no longer does anything. So for any total beginners like me, who are coming here to find out how to delete old Fedora kernels, I have worked out the following workaround:

      su
      rpm -q kernel
      Make a note of which kernels you have and want to remove!
      package-cleanup –oldkernels
      Make a note of all the packages that will be removed! So, the kernels, but also kernel-modules, kernel-modules-extra, etc
      SAY NO TO DELETING THEM!
      Finally, delete each thing manually; press Tab to fill in the names and versions automatically:

      dnf remove kernel-modules-extra-4.17.12[Tab]
      dnf remove kernel-devel-4.17.12[Tab]
      And so on…

      You can now keep removing old kernels, and keep freeing up hard drive space. It’s not as good as the old package-cleanup command, but at least it actually works.

      Reply
      • Hi Pedgero,

        I updated this guide, it’s now also Fedora 28/27/26 compatible, try following command instead:

        dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)

        Set negative value for --latest-limit=-1.

        Reply
    5. This is not working anymore. package cleanup emit a deprecated error, installonly limits don’t remove oldkernel entries in grub, it’s not equivalent to package-cleanup.

      Reply
      • Hi Gregory,

        I updated this guide, it’s now also Fedora 28/27/26 compatible, try following command instead:

        dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)

        Set negative value for --latest-limit=, like:

        ## Keep one kernel ##
        --latest-limit=-1
        
        ## Keep two kernels ##
        --latest-limit=-2
        
        ## Keep three kernels ##
        --latest-limit=-3
        
        ## And so on... ##
        

        And installonly_limit works normally when you use dnf or yum. If you set installonly_limit=2 and then update next kernel version, dnf/yum will remove all kernels except 2 latest, but this parameter change do not work, if you just update file.

        Reply
1 2

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close