PDA

View Full Version : Help with a custom Script



ajamison
25th June 2008, 05:18 AM
Ok so I know that you can boot into a kernel by adding 3 to the end of the kernel line in the boot loader however I like to make a seperate entry for each kernel with this option appended. (call it lazyness) What I am trying to do is make a script that when run will scan the grub.conf file for kernel entrys with out the 3 and copy the entire entry and append the 3 to it for example

If the original configuration file looke like so
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd1,0)
# kernel /vmlinuz-version ro root=/dev/sdb3
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=10
splashimage=(hd1,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.25.6-55.fc9.i686)
root (hd1,0)
kernel /vmlinuz-2.6.25.6-55.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet
initrd /initrd-2.6.25.6-55.fc9.i686.img
title Fedora (2.6.25-14.fc9.i686)
root (hd1,0)
kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet
initrd /initrd-2.6.25-14.fc9.i686.img
title Other
rootnoverify (hd0,0)
chainloader +1

I would in essence like the script to scan this file and change it like so
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd1,0)
# kernel /vmlinuz-version ro root=/dev/sdb3
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=10
splashimage=(hd1,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.25.6-55.fc9.i686)
root (hd1,0)
kernel /vmlinuz-2.6.25.6-55.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet
initrd /initrd-2.6.25.6-55.fc9.i686.img
title Fedora (2.6.25.6-55.fc9.i686)Terminal Mode
root (hd1,0)
kernel /vmlinuz-2.6.25.6-55.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet 3
initrd /initrd-2.6.25.6-55.fc9.i686.img
title Fedora (2.6.25-14.fc9.i686)
root (hd1,0)
kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet
initrd /initrd-2.6.25-14.fc9.i686.img
title Fedora (2.6.25-14.fc9.i686)Terminal Mode
root (hd1,0)
kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=c710a3e6-8a5c-4b27-ad32-1983fc8d57c8 rhgb quiet 3
initrd /initrd-2.6.25-14.fc9.i686.img
title Other
rootnoverify (hd0,0)
chainloader +1

Of course i would want a back of the conf file to be made prior to changes. I know this is silly to some but it is a shortcut i do and I would like to not manually edit the file.