I might be encountering odd symptoms resulting from competing kernels in CentOS 7. So how do I safely delete the old kernels? And how do I know which kernel is the newest one?

Below is the terminal output I get at the moment when researching this on the server in question. Note that I tried package-cleanup but it leaves the same 2 kernels:

The instructions in this tutorial say that the output of the following two commands should match, but you can see that they do not match, even after a reboot:

[root@localhost ~]# rpm -qa kernel |sort -V |tail -n 1
[root@localhost ~]# uname -r

The remaining commands confirm that there are two kernels, and illustrate attempts to delete the old one.

[root@localhost ~]# cd /usr/src/kernels
[root@localhost kernels]# ls -al
total 16
drwxr-xr-x.  4 root root 4096 Oct  2 12:55 .
drwxr-xr-x.  4 root root 4096 Oct  2 13:15 ..
drwxr-xr-x. 22 root root 4096 Oct  2 12:55 3.10.0-229.14.1.el7.x86_64
drwxr-xr-x. 22 root root 4096 Oct  2 12:35 3.10.0-229.el7.x86_64
[root@localhost kernels]# rpm -q kernel
[root@localhost kernels]# package-cleanup --oldkernels=1
Loaded plugins: fastestmirror
    package-cleanup: helps find problems in the rpmdb of system and correct them

    usage: package-cleanup --problems or --leaves or --orphans or --oldkernels
Command line error: --oldkernels option does not take a value
[root@localhost kernels]# package-cleanup --oldkernels
Loaded plugins: fastestmirror
No old kernels to remove
[root@localhost kernels]# rpm -q kernel
[root@localhost kernels]# 

I also opened up /etc/yum.conf and set installonly_limit=1, but this resulted in an error from a subsequent yum update command saying that 1 is outside the range of acceptable values for installonly_limit.

I assume that 3.10.0-229.14.1.el7.x86_64 is the newest, but how can I know this? Also, the boot options seem to offer multiple kernels to choose from. And the opportunities for confusion get worse when the system auto-boots from the first kernel on the list of options.

Can someone please explain how this works, and in specific, how to safely delete old kernels so that kernel version can be eliminated as a possible cause of odd symptoms? I want to make sure that the most recent kernel is the only kernel that can ever run, no matter how the system is restarted.

  • Walking out the door so I can't write up a full answer right now. Will try to check back later. yum-utils used to do this (not sure if it still does). if-not-true-then-false.com/2012/… – 0xSheepdog Oct 2 '15 at 22:39
  • @0xSheepdog Yes, I am using those commands from a similar tutorial, but the CentOS 7 server will not allow installonly_limit=1. I am getting funny symptoms that might be resulting from two kernel versions, so I would like to have only one version, if possible, or at least to have a definitive explanation of why it is not possible to have less than 2 versions, if in fact it is not possible. – CodeMed Oct 2 '15 at 22:42
  • 2
    I would suggest changing your "keep" criteria to "booted kernel" as opposed to simply newest -- for various reasons, you may not be booting to the newest kernel. – Jeff Schaller Oct 2 '15 at 23:41

package-cleanup --oldkernels --count=1 delete all kernels except latest.

  • 1
    Thanks Fractal Turtle for brief answer. I also want to you to safely keep at least two latest kernel. package-cleanup --oldkernels --count=2 – rangsiman Jun 1 '17 at 3:58
  • 1
    I run package-cleanup --oldkernels --count=1. After reboot, I still get two kernels: CentOS Linux (4.4.6-1.el7.elrepo.x86_64) 7 (Core) and CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core), do you know how to just keep one? – Ron Sep 18 '17 at 0:44
  • Can someone answer @Ron 's question? – Alireza Mohamadi Apr 12 at 13:26

The command package-cleanup remove older kernel. Use --count=1 to keep just the latest. The program will never remove the kernel currently used ("Not removing kernel 3.10.0-327.el7 because it is the running kernel"), so you may end-up with two kernels in /boot... until you reboot and re-run the command.

So the command is

package-cleanup --oldkernels --count=1 

The manpage document three options:

          Remove old kernel and kernel-devel packages.
--count <COUNT>
          Number of duplicate/kernel packages to keep on the system (default 2)
          Do not remove kernel-devel packages when removing kernels

Use yum upgrade instead of yum update

Then it will only keep three kernels. If you use update then it will fill up your /boot

according to this:

run rpm -q kernel to show installed kernel

then run yum remove kernel <shown kernel from output above> to remove the kernel

reboot ur computer

edit: this actualy work for @Ron's problem, but make sure elrepo kernel is running correctly

  • How do you avoid removing your current kernel? – Jeff Schaller Jun 10 at 14:59
  • IDK specific command for that @JeffSchaller I guess, to make sure u are not removing current kernel, u sud check it first by using uname -r then delete the unused kernel but shown from that command, – Surya Stefanus Jun 11 at 12:04

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.