[lug] Script to remove old RHEL kernels.

Hugh Brown hugh at math.byu.edu
Tue May 30 18:31:31 MDT 2006

On Tue, 2006-05-30 at 17:02 -0600, Gregg Phillips wrote:
> Good Afternoon,
> Has anyone written a script or know of a way to remove old kernels from
> a RedHat Enterprise Linux WS 4.0 system. After a while they start to
> pile up and it would be nice to be able to remove all but the last two
> installed.
> TIA,
> Gregg.

I've always done it by hand since a script removing kernels gone haywire
would be a bad thing.  I also only tend to accumulate kernels on systems
with server roles rather than workstation systems.

If I had to write one, I'd rpm -q kernel kernel-smp and then run it
through sort until it was doing "the right thing" and then use head/tail
to ditch the two recent versions and then feed that to rpm -e.

One thing to watch for is your /boot/grub/menu.lst, the scripts don't
always get the default target right.


More information about the LUG mailing list