Admin Spotting for Fun and Profit

The kernel collection

May 21st, 2008 Posted in Linux

If you maintain a number of older RHEL or CentOS 3 and 4 machines, you’ve probably got a few extra kernels lying around to clutter up your /boot partition. In some instances this can cause update issues, and I ran into one such case today. An admin came to me asking why yum was attempting to install all of his packages to his /boot partition, and when I examined further, I saw this on his screen:

installing package kdegraphics-3.3.1-9.el4_6 needs 3MB on the /boot filesystem

While the error itself does look at first glance as the admin described it, this is not the case. The culprit was a kernel update further up the screen, and a 98% full /boot partition, with around 25 spare kernels. His system was simply informing him that the transaction would not occur because one of the updates was not going to succeed due to limited disk space.

While the InstallOnlyN plugin for yum will handle this quite nicely for the day to day stuff, once it’s happened it can be a little tricky to resolve. The easiest way is with a script called kernel-prune from Seth Vidal’s duke directory.

By piping the output of this script through xargs, you can remove all the tedium of manually removing packages one or two at a time. For RHEL and CentOS 3, where installonlyn isn’t really an option, this is pretty much the easiest way to periodically purge some unwanted fat from your system. Hope this helps at least 1 of you out there.

Feel free to share your own methods or comments below. I’m sure there are other methods out there so let’s hear them!

  1. 4 Responses to “The kernel collection”

  2. By David Hrbáč on May 22, 2008

    Simple way:
    if [ $(rpm -q kernel | wc -l) -gt 1 ]; then rpm -e $(rpm -q kernel | sed ‘$d’); fi
    if [ $(rpm -q kernel-smp | wc -l) -gt 1 ]; then rpm -e $(rpm -q kernel-smp | sed ‘$d’); fi

  3. By Bart Schaefer on May 22, 2008

    There’s also “package-cleanup –oldkernels” from the yum-utils package.

    Jim Perrin reply on May 22nd, 2008 3:45 pm, 22 May 2008:

    For newer centos/RHEL installs, yes and that’s a very good point. I’d forgotten about the yum-utils bits.

    For CentOS 3, yum is too old to support yum-utils enhancements though.

  4. By Claire Connelly on May 24, 2008

    I wrote the following script to clean up extra kernels. It will leave you with the newest kernel and the kernel you’re currently running if they aren’t the same.

    #!/usr/bin/perl -w

    ### zap-kernels - remove old kernels from system
    ###
    ### C.M. Connelly
    ###
    ### Tue Jul 22 15:43:24 PDT 2003

    use strict;

    my $current_kernel = `uname -r`;
    $current_kernel =~ s/smp$//;

    my @packages = grep { m/^kernel/ } ( `rpm -qa` );
    my @kernels;

    foreach my $kind ( “”, “-smp” ) {
    my $numberadded = 0;
    foreach my $package ( sort @packages ) {
    if ( $package =~ m/^kernel$kind-2/ ) {
    unless ( $package =~ m/$current_kernel/ ) {
    chomp $package;
    push @kernels, $package;
    ++$numberadded;
    }
    }
    }
    if ( $numberadded != 0 ) {
    my $newest_kernel = pop @kernels;
    # print “Removing $newest_kernel from the list of $numberadded bad kernels.\n”;
    }
    }

    #print “Bad kernels!\n@kernels\n”;

    `rpm -e –allmatches @kernels`;

Post a Comment