2005-12-03 01:30:20

by Steven Rostedt

[permalink] [raw]
Subject: [ANNOUNCE] clean-boot.pl version 0.1 - Simple utility to clean up /boot and /lib/modules

I'm not sure if this has been done already or not (let me know if it
has), but I've just noticed that after playing with several
developmental kernels I had about 30 to 40 different versions of
vmlinuz, initrd.img, config, and System.maps in my /boot directory, not
to mention all the modules loaded in /lib/modules.

So I wrote this perl script that let me pick and choose what I wanted to
clean up. Be careful, this must be run as root, and although the
default is to do nothing, if you hit a "y" in the wrong place, you can
lose that kernel.

The script is here:

http://www.kihontech.com/code/clean-boot.pl

Here's the usage:

# ./clean-boot.pl -h

usage: clean-boot.pl [-b boot_dir] [-m module_dir]
(version 0.1)
default boot_dir = /boot
default module_dir = /lib/modules

It's run like the following:

---
#./clean-boot.pl
List of versions found:
2.6.12-1-386 2.6.14 2.6.14-2-386
2.6.14-2-k7-smp 2.6.14-kthrt2 2.6.14-rt13
2.6.14-rt13-logdev1 2.6.14-rt15 2.6.14-rt20
2.6.15-rc3
Remove files for version 2.6.12-1-386 [y/N/l/q/?]: ?
y - remove files from boot and modules
n [default] - skip this version
l - list the found versions again
q - quit
? - display this message
Remove files for version 2.6.12-1-386 [y/N/l/q/?]: q
---

If you hit "y" (or yes or ye, case is ignored), it will then remove any
of the vmlinuz, initrd.img, config and System.map files for version
2.6.12-1-386 in /boot and the directory /lib/modules/2.6.12-1-386.

This is under just a public license, no warranty, so just be careful not
to delete too much.

Also remember to update lilo or grub, since this doesn't handle that.

Comments?

-- Steve


2005-12-03 08:57:55

by Willy Tarreau

[permalink] [raw]
Subject: Re: [ANNOUNCE] clean-boot.pl version 0.1 - Simple utility to clean up /boot and /lib/modules

On Fri, Dec 02, 2005 at 08:30:15PM -0500, Steven Rostedt wrote:
> I'm not sure if this has been done already or not (let me know if it
> has), but I've just noticed that after playing with several
> developmental kernels I had about 30 to 40 different versions of
> vmlinuz, initrd.img, config, and System.maps in my /boot directory, not
> to mention all the modules loaded in /lib/modules.

One more reason to put kernels and modules into /boot. On my systems,
/lib/modules is a symlink to /boot, so that I have my modules
physically located in /boot/<kversion> and my kernel, config, System.map, ...
into the same directory. So I just have to rm -rf /boot/<kversion> to remove
one kernel, and managing them is very easy. One more advantage is that
when you build many kernels, you just 'sudo make modules_install' first,
which creates the /boot/<kversion> entry, then you just have to
'sudo cp arch/i386/boot/bzImage System.map .config /boot/<kversion>/'
which is very convenient.

The default flat /boot directory + /lib/modules is a real mess, proved
by the fact that you had to write a tool just to manage that. Not that
I find your script useless at all, it's the opposite, I think it will
make life easier for people who want to keep this obsolete directory
structure.

> So I wrote this perl script that let me pick and choose what I wanted to
> clean up. Be careful, this must be run as root, and although the
> default is to do nothing, if you hit a "y" in the wrong place, you can
> lose that kernel.
>
> The script is here:
>
> http://www.kihontech.com/code/clean-boot.pl
>
> Here's the usage:
>
> # ./clean-boot.pl -h
>
> usage: clean-boot.pl [-b boot_dir] [-m module_dir]
> (version 0.1)
> default boot_dir = /boot
> default module_dir = /lib/modules
>
> It's run like the following:
>
> ---
> #./clean-boot.pl
> List of versions found:
> 2.6.12-1-386 2.6.14 2.6.14-2-386
> 2.6.14-2-k7-smp 2.6.14-kthrt2 2.6.14-rt13
> 2.6.14-rt13-logdev1 2.6.14-rt15 2.6.14-rt20
> 2.6.15-rc3
> Remove files for version 2.6.12-1-386 [y/N/l/q/?]: ?
> y - remove files from boot and modules
> n [default] - skip this version
> l - list the found versions again
> q - quit
> ? - display this message
> Remove files for version 2.6.12-1-386 [y/N/l/q/?]: q
> ---
>
> If you hit "y" (or yes or ye, case is ignored), it will then remove any
> of the vmlinuz, initrd.img, config and System.map files for version
> 2.6.12-1-386 in /boot and the directory /lib/modules/2.6.12-1-386.
>
> This is under just a public license, no warranty, so just be careful not
> to delete too much.
>
> Also remember to update lilo or grub, since this doesn't handle that.
>
> Comments?
>
> -- Steve

Regards,
Willy

2005-12-04 00:30:35

by Peter Williams

[permalink] [raw]
Subject: Re: [ANNOUNCE] clean-boot.pl version 0.1 - Simple utility to clean up /boot and /lib/modules

Steven Rostedt wrote:
> I'm not sure if this has been done already or not (let me know if it
> has), but I've just noticed that after playing with several
> developmental kernels I had about 30 to 40 different versions of
> vmlinuz, initrd.img, config, and System.maps in my /boot directory, not
> to mention all the modules loaded in /lib/modules.
>
> So I wrote this perl script that let me pick and choose what I wanted to
> clean up. Be careful, this must be run as root, and although the
> default is to do nothing, if you hit a "y" in the wrong place, you can
> lose that kernel.
>
> The script is here:
>
> http://www.kihontech.com/code/clean-boot.pl
>
> Here's the usage:
>
> # ./clean-boot.pl -h
>
> usage: clean-boot.pl [-b boot_dir] [-m module_dir]
> (version 0.1)
> default boot_dir = /boot
> default module_dir = /lib/modules
>
> It's run like the following:
>
> ---
> #./clean-boot.pl
> List of versions found:
> 2.6.12-1-386 2.6.14 2.6.14-2-386
> 2.6.14-2-k7-smp 2.6.14-kthrt2 2.6.14-rt13
> 2.6.14-rt13-logdev1 2.6.14-rt15 2.6.14-rt20
> 2.6.15-rc3
> Remove files for version 2.6.12-1-386 [y/N/l/q/?]: ?
> y - remove files from boot and modules
> n [default] - skip this version
> l - list the found versions again
> q - quit
> ? - display this message
> Remove files for version 2.6.12-1-386 [y/N/l/q/?]: q
> ---
>
> If you hit "y" (or yes or ye, case is ignored), it will then remove any
> of the vmlinuz, initrd.img, config and System.map files for version
> 2.6.12-1-386 in /boot and the directory /lib/modules/2.6.12-1-386.
>
> This is under just a public license, no warranty, so just be careful not
> to delete too much.
>
> Also remember to update lilo or grub, since this doesn't handle that.
>
> Comments?

I also had this problem and created the attached Python script to handle
the problem. Usage is:

Usage: rmkernel.py [-i] [-v] <kernel> ....

where <kernel> can be a glob expression (n.b. lists of expressions
accepted) describing which kernels to delete, the -i option selects
interactive mode where confirmation is requested for each deletion and
-v lists each kernel that has been deleted. This script is slightly
smarter than yours in that it uses grubby to update grub (or lilo etc.)
for the removal of the kernel. Additionally, the script checks to see
if the kernel was installed via rpm and if it was uses rpm to do the
removal.

If it was thought desirable a GUI version of this program would be
fairly easy to write using rmkernel.py as a library module.

Cheers,
Peter
--
Peter Williams [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
-- Ambrose Bierce


Attachments:
rmkernel.py (5.04 kB)

2005-12-06 17:01:39

by Patrick McLean

[permalink] [raw]
Subject: Re: [ANNOUNCE] clean-boot.pl version 0.1 - Simple utility to clean up /boot and /lib/modules

Willy Tarreau wrote:
> One more reason to put kernels and modules into /boot. On my systems,
> /lib/modules is a symlink to /boot

Not the best idea on distros that use a separate /boot partition that is
not mounted at boot by default (this is Gentoo's recommended setup).

2005-12-06 22:12:31

by Willy Tarreau

[permalink] [raw]
Subject: Re: [ANNOUNCE] clean-boot.pl version 0.1 - Simple utility to clean up /boot and /lib/modules

On Tue, Dec 06, 2005 at 12:01:24PM -0500, Patrick McLean wrote:
> Willy Tarreau wrote:
> >One more reason to put kernels and modules into /boot. On my systems,
> >/lib/modules is a symlink to /boot
>
> Not the best idea on distros that use a separate /boot partition that is
> not mounted at boot by default (this is Gentoo's recommended setup).

It's not mounted just because usually there's nothing useful in it. If
you put useful things such as modules, then you'll mount it.

willy