[WBEL-users] Removing old kernel files
david
david@daku.org
Wed, 18 Aug 2004 16:09:24 -0700
Chrispatch, Erik, Kuervers.SJ, and anyone else whose response arrived after
I sent this:
I thank you for your assistance. Chrispatch gave me the key "rpm"
command. I had been looking in "yum" for an answer.
I understand the script that Eric gave, and offer the following candidate
for your amusement. It is written in "perl", and because I have no
courage, only informs me of the command that I ought to issue.
I'm sorry for the length, but you'll find that about half of it is comments.
Thanks
David
------------------ begin script
#!/bin/perl
# Script to identify and eventually delete un-needed kernels
# This script is intended to be run once a day or once a week or even once
a month
# Survey boot space to identify Kernels
# The method assumes that the file named
# /boot/System.map
# is linked to the currently running Kernel
#
# Present Kernel versions can be identified by looking at all files named
# /boot/System.map-*
# (note the trailing hyphen) and extracting everything after that hyphen, but
# carefully deleting any trailing period and non-digit sequence.
#
# The order of Kernels can be deduced from the alphanumeric order of those
version id's.
#
#---------------
# Extract version string from a /boot/System.map-
#---------------
sub vid {
my $nam = shift;
$nam =~ s/^.*map-//;
$nam =~ s/\.[A-Z]*$//;
return $nam;
}
#-------------
# Set current version
#-------------
$kver = vid(`uname -r`);
chomp $kver;
# print "Current Kernel is $kver\n";
#-------------
# Survey /boot to identify kernels based upon System.map- files
#-------------
opendir THISDIR, "/boot";
@boot_list = grep !/^\.\.?$/, readdir THISDIR;
closedir THISDIR;
#----------------
# Walk the list and identify old unused kernels
# Retain only the newest of those.
# Maybe by deleting the current minus one, we'll get rid of all the earlier
ones too.
# But if that fails, the next run will solve that.
#----------------
$old_name='';
for (@boot_list) {
next unless /^System\.map-/;
next unless vid($_) lt $kver;
$old_name = $_ if vid($old_name) lt vid($_);
}
if($old_name) {
$old_name =~ s/^.*map//;
$command = "rpm -e kernel" . $old_name;
print "Want to issue: $command\n";
}
------------------- end script
At 01:23 PM 8/18/2004, you wrote:
> rpm -e kernel-2.4.21-15.EL
>
>
>-----Original Message-----
>From: david [mailto:david@daku.org]
>Sent: Wednesday, August 18, 2004 15:42
>To: chrispatch@exchange.nt.intrstar.net
>Subject: [WBEL-users] Removing old kernel files
>
>Folks
>
>Since the original "respin-1", a revised and upgraded Kernel has appeared
>and works just fine. All my systems have been rebooted and are using this
>new version. To the best of my knowledge:
>
>Old kernel: 2.4.21-15.EL
>New Kernel: 2.4.21-15.0.4.EL
>
>Ignoring the trailing ".EL", these names sort very nicely as alphanumeric
>strings.
>
>However, I am somewhat cramped for space, and want to reclaim the space used
>by material I no longer use, like the old Kernel stuff.
>
>Is there some syntax in "yum" or "rpm" that will do this for me, safely?
>
>Thanks
>
>David
>
>_______________________________________________
>Whitebox-users mailing list
>Whitebox-users@beau.org
>http://beau.org/mailman/listinfo/whitebox-users