[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Uploaded grub 0.5.96 (source i386) to master



On Mon, Oct 09, 2000 at 07:04:25PM -0500, Joseph Carter wrote:
> I'd like kernel-package to automatically add a stanza to my menu.lst for a
> new kernel such as...
> 
> title Linux 2.4.0-test8
> root (hd0,1)
> kernel /boot/vmlinuz-2.4.0-test8 root=/dev/hda2
> boot
> 
> ...for the kernel I'm using right now.
> 
> If it was smart enough to remove it afterword, that would be even cooler.
> Also, for grub is is much better to put vmlinuz symlinks in /boot which
> kernel-package only does if you force it to at the moment.

attached is the perl script I have installed as /sbin/lilo for creating the
grub menu from a template with a full array of linux kernels installed
following the standard header, so you can selectively pick and choose beyond
the vmlinuz and vmlinuz.old symlinks with ease..  it assumes the symlinks
are in /boot/ which is the way I keep all my systems, whether they use lilo
or grub .. it could be spiffed up into something much more grand if somebody
has the initiative, but it serves my needs with minor editing of the header
template embedded in the script on all of my grub-using boxes, and makes for
hassle-free installs of kernel packages.

note that it assumes the existence of a menu.lst file, so you'll need to at
least touch one if there isn't one already installed, and I use dpkg-divert
to protect it from lilo pkg updates and still keep lilo installed for
root-disk generation and other odd uses where it comes in handy to have on
the system..

anyway, IWFM, YMMV, HTH, HAND.

Marc
#!/usr/bin/perl -w

use strict;

# basic config variables
my $GrubDir="/boot/grub";
my $RootDev="(hd0,0)";
my $KernelFlags="root=/dev/sda1 reboot=warm vga=extended";

# test for -t so we don't kill a backup file with 2 writes of a new menu
if (defined($ARGV[0]) && $ARGV[0] eq "-t") {
  print "test run\n"; 
  exit 0;
 } else {
  print "Backing up old menu file...";
  die "Can't create backup file: $!" unless rename "$GrubDir/menu.lst", "$GrubDir/menu.bak";
  print "done\n";
}

my @CurrentKernel= split /-/, readlink "/boot/vmlinuz";
my @OldKernel= split /-/, readlink "/boot/vmlinuz.old";
# the following regex nastiness was needed when make-kpkg changed the way 
# it created symlinks
my $CurrentKernelPrefix = shift @CurrentKernel;
$CurrentKernelPrefix =~ m!^/boot/! || s!^(.*)!/boot/$1!;
my $OldKernelPrefix = shift @OldKernel;
$OldKernelPrefix =~ m!^/boot/! || s!^(.*)!/boot/$1!;

open(MenuFile, ">$GrubDir/menu.lst");

# change the default array separator to the - we split on above
$"= "-";		# " <- bogus quote to fix syntax highlighting
# send out the header
print MenuFile <<"__EOF__";
timeout= 10
color light-cyan/blue white/blue

title= Current Linux Kernel (@CurrentKernel)
root=$RootDev
kernel=$CurrentKernelPrefix-@CurrentKernel $KernelFlags

title= Backup Linux Kernel (@OldKernel)
root=$RootDev
kernel=$OldKernelPrefix-@OldKernel $KernelFlags

# put any extra definitions you want in here, for booting other os's, etc..

__EOF__

opendir BOOTDIR, "/boot" or die "No /boot to open: $!";
my @KernelFiles= sort grep /^vmlinuz-.*/, readdir BOOTDIR;
closedir BOOTDIR;

while ($_ = pop @KernelFiles) {
print MenuFile <<"__EOF__" if s/vmlinuz-//;
title= Linux $_
root=$RootDev
kernel=/boot/vmlinuz-$_ $KernelFlags

__EOF__
}

Reply to: