Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
menu.lst update script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
alecjw
n00b
n00b


Joined: 27 Mar 2010
Posts: 41
Location: Hertfordshire, UK

PostPosted: Tue Jul 13, 2010 8:10 pm    Post subject: menu.lst update script Reply with quote

I just threw together a script quickly to generate menu.lst for grub legacy, here it is if anyone wants it:
Code:
#!/bin/bash
#This pile of bollocks is by Alec Wright <alecjw@member.fsf.org>
#It only has the features I need. That's why its written for grub legacy and it has no support of initrds or splash images. If you need anything more complicated, make it yourself :)
#It hardly seems worth copylefting a simple bash script like this, so consider this public domain material.

#Modify the line below to change the timeout
GRUBTIMEOUT="2"

echo "A menu.lst for GNU GRUB legacy (ie not grub2) will be created."
echo "Where should the config be saved to? (Default: /boot/grub/menu.lst)"
read -e SAVELOCATION
if [ -z $SAVELOCATION ]
   then
   SAVELOCATION="/boot/grub/menu.lst"
fi
if [ -a "$SAVELOCATION" ]
   then
   BACKUPLOCATION="/tmp/menu.lst.$(date +%s)"
   cp $SAVELOCATION $BACKUPLOCATION
   echo "A backup of $SAVELOCATION has been made to $BACKUPLOCATION. This will most likely be deleted upon reboot."
else
   echo "$SAVELOCATION does not yet exist. Will create."
fi
KERNELS=$(cd /boot ; ls -t linux*) #search for /boot/linux*. replace with vmlinuz* or whatever you use.
echo;echo;echo "Should a chainloader entry be added (eg for windows)? If so, give the grub disk (eg \"(hd0,5)\") for the chainload. Else, say n"
read -e CHAINLOAD
KERNELCOUNT=0
echo;echo "The following kernels will be added:"
for KERNEL in $KERNELS
do
   printf "$KERNELCOUNT:\t\t$KERNEL\n"
   KERNELCOUNT=$[$KERNELCOUNT+1]
done
if [ "$CHAINLOAD" != "n" ]
   then
   printf "$KERNELCOUNT:\t\tchainload from $CHAINLOAD\n"
fi
echo "Which do you wish to use as default?"
read -e DEFAULTKERN
echo "What is the grub device for your boot partition? I'm too lazy to write code to autodetect it."
read -e BOOTPART
echo "What should be appended to the kernel command line?"
read -e APPENDLINE
echo "timeout $GRUBTIMEOUT" > $SAVELOCATION
echo "default $DEFAULTKERN" >> $SAVELOCATION
for KERNEL in $KERNELS
do
   echo "title $KERNEL" >> $SAVELOCATION
   echo "kernel $ROOTPART/boot/$KERNEL $APPENDLINE" >> $SAVELOCATION
   echo >>$SAVELOCATION
done
if [ "$CHAINLOAD" != "n" ]
   then
   printf "\n\n" >> $SAVELOCATION
   echo "title Chainloader" >> $SAVELOCATION
   echo "rootnoverify $CHAINLOAD" >> $SAVELOCATION
   echo "makeactive" >> $SAVELOCATION
   echo "chainloader +1" >> $SAVELOCATION
fi
echo "#Autogenerated by some crappy script made by Alec Wright <alecjw@member.fsf.org>" >> $SAVELOCATION
echo;echo "$SAVELOCATION written. Bye!"


It's not a universal solution, because I made it for my own personal use and just thought i might as well offer it out for anyone else to use in case it helps them.
It does:
* Automatically search for kernels in /boot/linux*
* Save a backup to /tmp in case something goes hideously wrong
* Let you append stuff to the kernel command line (root=... and suchlike)
* Let you have one chainload entry, eg for window dual boot

It doesnt:
* Automatically detect grub disks
* Check for kernels on other partitions
* Allow >1 chainload
* Support initrds, unless you have one initrd common to all kernels (the same options are passed to each kernel)

Feel free to improve it, but I'm not modifiying it myself: it works just fine for me :)

Heres a sample menu.lst:
Code:
timeout 2
default 0
title linux-2.6.34-gentoo-r1-libre-b1
kernel /boot/linux-2.6.34-gentoo-r1-libre-b1 root=/dev/sda7

title linux-2.6.33-gentoo-r2-b0
kernel /boot/linux-2.6.33-gentoo-r2-b0 root=/dev/sda7

title linux-2.6.33-gentoo-r2-libre-b2
kernel /boot/linux-2.6.33-gentoo-r2-libre-b2 root=/dev/sda7

title linux-2.6.33-gentoo-r2-libre-b1
kernel /boot/linux-2.6.33-gentoo-r2-libre-b1 root=/dev/sda7

title linux-2.6.32-gentoo-r7-b3
kernel /boot/linux-2.6.32-gentoo-r7-b3 root=/dev/sda7

title linux-2.6.32-gentoo-r7-b2
kernel /boot/linux-2.6.32-gentoo-r7-b2 root=/dev/sda7

title linux-2.6.32-gentoo-r7-b1
kernel /boot/linux-2.6.32-gentoo-r7-b1 root=/dev/sda7

title linux-2.6.32-gentoo-r7-b0
kernel /boot/linux-2.6.32-gentoo-r7-b0 root=/dev/sda7



title Chainloader
rootnoverify (hd0,1)
makeactive
chainloader +1
#Autogenerated by some crappy script made by Alec Wright <alecjw@member.fsf.org>

_________________
ACTA is a war on your digital freedom
Back to top
View user's profile Send private message
tomk
Administrator
Administrator


Joined: 23 Sep 2003
Posts: 7219
Location: Sat in front of my computer

PostPosted: Wed Jul 14, 2010 8:26 am    Post subject: Reply with quote

Moved from Gentoo Chat to Documentation, Tips & Tricks, it fits better here.
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum