[SOLVED] Delete old linux kernel

General support questions
cccc
Posts: 99
Joined: 2008/11/22 19:24:37

[SOLVED] Delete old linux kernel

Post by cccc » 2012/04/06 14:44:18

hi

What's the best whay to delete old linux kernel on CentOS 6?

[code]
$ rpm -q kernel
kernel-2.6.32-220.2.1.el6.i686
kernel-2.6.32-220.4.1.el6.i686
kernel-2.6.32-220.4.2.el6.i686
kernel-2.6.32-220.7.1.el6.i686[/code]

Should I use 'rpm -e' command to remove?

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

[SOLVED] Delete old linux kernel

Post by pschaff » 2012/04/06 15:15:21

That should work. So should "yum remove ...". To keep fewer kernels automatically edit [b]/etc/yum.conf[/b] and change [b]installonly_limit=5[/b] to a smaller number. It is advisable to keep at least a couple of old kernels to fall back to if there is a problem with an update.

cccc
Posts: 99
Joined: 2008/11/22 19:24:37

Re: Delete old linux kernel

Post by cccc » 2012/04/07 19:41:46

Thx Phil

I've removed using yum and now I have the following:[code]
# rpm -qa | grep kernel
dracut-kernel-004-256.el6_2.1.noarch
kernel-firmware-2.6.32-220.7.1.el6.noarch
kernel-2.6.32-220.7.1.el6.i686
kernel-headers-2.6.32-220.7.1.el6.i686
libreport-plugin-kerneloops-2.0.5-20.el6.i686
[/code]

BTW I've changed in /etc/yum.conf to:[code]installonly_limit=2[/code]

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: [SOLVED] Delete old linux kernel

Post by pschaff » 2012/04/07 23:48:31

You are welcome. Looks good, as long as the current kernel is working for you, as you left nothing to fall back on.

Thanks for reporting back. Marking this thread [SOLVED] for posterity.

sten
Posts: 1
Joined: 2012/07/12 08:06:01

Re: [SOLVED] Delete old linux kernel

Post by sten » 2012/07/12 08:39:46

I realize this is solved and closed, but for those interested there is an easier solution -

yum install yum-utils
package-cleanup --oldkernels --count=2

Greg_E
Posts: 143
Joined: 2014/04/04 18:53:45

Re: [SOLVED] Delete old linux kernel

Post by Greg_E » 2014/07/12 17:38:33

Reviving this... Will that command remove all older packages? I'm working with a live CD version of 6.5 with an overlay of roughly 4gb, after update I only have 2.7 GB left and haven't begun installing any of the other packages I'll need for this system. I don't care about a fallback kernel on this, everything I need to do works properly on the latest updates.

And yes I will try the above utilities and see for myself, but thought it was worth asking. I assume that if I don't specify how many to save, only the current kernel and packages will be present.

User avatar
bluegroper
Posts: 264
Joined: 2005/09/07 23:04:21
Location: .au

Re: [SOLVED] Delete old linux kernel

Post by bluegroper » 2016/05/07 07:40:50

Just edit your /etc/yum.conf

Code: Select all

installonly_limit=3
Then your next yum update will do all your housekeeping.
No need for any complicated remove commands.
Too easy.
HTH
I'm not a complete idiot. There's still a few pieces missing.

Urhixidur
Posts: 6
Joined: 2016/05/03 19:40:54

Re: [SOLVED] Delete old linux kernel

Post by Urhixidur » 2016/12/14 14:26:38

bluegroper 's change of /etc/yum.conf installonly_limit followed by 'yum update' does not work.

sten's 'package-cleanup --oldkernels --count=2' works perfectly.

w3k4
Posts: 1
Joined: 2017/01/02 17:04:58

Re: [SOLVED] Delete old linux kernel

Post by w3k4 » 2017/01/02 17:34:00

I found that my new kernel was crashing .. I was unable to delete this kernel, apparently because it was the latest kernel I had ..

Code: Select all

 $ uname -a
Linux reliant.wek 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
 $ rpm -q kernel
kernel-3.10.0-327.el7.x86_64
kernel-3.10.0-327.36.3.el7.x86_64
kernel-3.10.0-514.2.2.el7.x86_64
 $ rpm -e kernel-3.10.0-514.2.2.el7.x86_64
error: Failed dependencies:
        kernel >= 3.10.0-384.el7 is needed by (installed) hypervkvpd-0-0.29.20160216git.el7.x86_64
        kernel >= 3.10.0-384.el7 is needed by (installed) hypervvssd-0-0.29.20160216git.el7.x86_64
        kernel >= 3.10.0-384.el7 is needed by (installed) hypervfcopyd-0-0.29.20160216git.el7.x86_64
I did attempt a yum command as well, with similar results. I finally succeeded, sorta, with the following ..

Code: Select all

 $ find . -name "*514*" -ls
( to ensure I had a good pattern )
 $ tar cfz /root/boot-20170102.tgz /boot
 $ tar tvfz /root/boot-20170102.tgz
( I am good, but not perfect )

Code: Select all

 $ cd /boot && find . -name "*-514.*" -exec rm {} \;
 $ find . -type f -exec grep -c -F "514" {} /dev/null \;
 $ vi ./grub2/grub.cfg
( on line 87 or so, I found a reference to my offending kernel, prefixed with "^menuentry". I deleted that line and all lines through and including it's matching, closing brace ")" )

my boot process now requires human input, so apparently I have some cleanup to do.

User avatar
TrevorH
Forum Moderator
Posts: 31067
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: [SOLVED] Delete old linux kernel

Post by TrevorH » 2017/01/03 16:54:56

That's not the way to do it.

To remove a kernel that you do not want, first you need to make sure you are not running it as yum will refuse to remove the running kernel. So reboot and select a different kernel from the grub menu and then use yum remove kernel-3.10.0-514.2.2.el7.x86_64

Done.
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

Post Reply

Return to “CentOS 6 - General Support”