Saturday, July 16, 2011

Hacking and Customizing Linux GRUB (Part I) : Adding more Operating System Entries, Changing OS Names, setting Fedora GRUB as default instead of Ubuntu


This is a nice hack to change your GRUB boot loader preferences. For those who have a dual boot configuration on there systems, be it a Linux with Linux or Linux with Windows, you may have sometimes thought of changing OS label names, or the background image or even using GRUB instead of any other boot loader. This post aims to teach you all this. Also Ubuntu 11.04 uses GRUB 2, which is only more complicated and harder to customize. If you have Fedora and Ubuntu installed in your PC like mine, you would like to use Fedora's GRUB 1.9. Or maybe you have installed Fedora but it doesn't recognize Ubuntu and you cannot boot it. Or suppose instead of Windows boot loader, you would like to use GRUB. This article has all the answers of your problems. 


First of all let me say that the full form of acronym GRUB is GRand Unified Bootloader. It is a open-source software that appears to you just after booting your PC and let you make operating system choices. This tweak cover three parts, first part we will learn how to change GRUB OS label names, or add more operating system choices. Second part we will learn about using Fedora's GRUB instead of any other OS bootloader. And in third part (next post) we will learn how to change the GRUB's boring background image to something else.

Changing GRUB OS label names and adding more OS choices in the GRUB menu

In Fedora, open terminal and go to /boot/grub folder.
$ cd /boot/grub
Now backup the grub.conf file using super user privileges or sudo. This is the main file we will be working on, so its always advisable to save a backup of it.
$ sudo cp grub.conf ~
This will copy the file to your home folder.
Now to edit the file, open it with gedit or vi, using root user privileges. You will see something like this:.


# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=4
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
#hiddenmenu
title Fedora 2.6.38-32.fc15.i686.PAE
root (hd0,0)
kernel /boot/vmlinuz-2.6.38.8-32.fc15.i686.PAE ro root=UUID=cdeda400-b2b8-496b-8752-c656c2de6a7d rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
initrd /boot/initramfs-2.6.38.8-32.fc15.i686.PAE.img
title Fedora 2.6.38.6-26.rc1.fc15.i686.PAE
root (hd0,0)
kernel /boot/vmlinuz-2.6.38.6-26.rc1.fc15.i686.PAE ro root=UUID=cdeda400-b2b8-496b-8752-c656c2de6a7d rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
initrd /boot/initramfs-2.6.38.6-26.rc1.fc15.i686.PAE.img


To change the operating system label names, just change the part after title. For e.g. we have this line
title Fedora 2.6.38-32.fc15.i686.PAE
change it to something like
title Fedora 15 Lovelock
you can also give your name there, in fact any name or words. Note that after every kernel update, an entry of that kernel gets added to this list. Its advisable to have two kernel entries of the same OS in the GRUB, one that comes with during installation, and the other the latest kernel, so that if the latest kernel has got bugs, you can always go back to work with the more stable first one. To delete a OS entry, simple remove the title, kernel and initrd entries of that kernel. Also note that you can change the default OS that can be booted by changing the default (0= 1st entry, 1=2nd) . Also you can change the timeout seconds (time GRUB will wait before booting the default OS) by changing the timeout value.
Now suppose that you have installed Fedora and it doesn't recognize the Ubuntu that you have installed earlier. For that you have to add Ubuntu entries in this file. Go to Ubuntu drive, and open /boot/grub/grub.cfg file. Browse till you find something like this line.

menuentry 'Ubuntu, with Linux 2.6.38-8-generic' --class ubuntu --class gnu-linux --class gnu --class os {

Now go back to your Fedora's boot/grub/grub.conf and append the following entries:
title Ubuntu, with Linux 2.6.38-8-generic
Now we need to provide the root entry. For this type root ( and give the hard disk Ubuntu is installed on. If you have a single hard disk, it should be zero, otherwise specify the number like if it in the second had disk, it will be:
root (hd1,
now we need to specify the partition Ubuntu is installed on. For example, /dev/sda1 is known as 0th partition, /dev/sda2 the 1st partition and so on. My Ubuntu is installed in /dev/sda3 so I write:
root (hd0, 2)
Now we need to find the kernel and initrd image addresses. For that, open the grub.cfg file of Ubuntu, go the the entry of Ubuntu, and simply copy what is written after “linux” entry to kernel entry in Fedora's grub.conf. Also copy the initrd entry grub.conf and leave as it is. So our final Ubuntu entry will look somethinbg like this:

title Ubuntu Natty Narwhal
root (hd0,2)
kernel /boot/vmlinuz-2.6.38-8-generic root=UUID=cd16e49b-fa3d-43db-bd4e-6d79b042f082 ro quiet splash vt.handoff=7
initrd /boot/initrd.img-2.6.38-8-generic

You can add other entries in grub.conf (like failsafe mode of Ubuntu, memtest86+) by the process described above.
Once done, save the file and exit.


Setting Fedora's GRUB as default instaed of any other Operating System (Ubuntu), or using GRUB instead of Windows bootloader.


To install Fedora's grub and to use it as the default GRUB instead of Ubuntu or any other OS , open terminal and type:
sudo grub-install /dev/sda
If all goes well, Fedora's GRUB will be installed as default GRUB for your system.


Next, to change the background (splash) image of the GRUB menu, have a look at this

Resources : http://www.gnu.org/software/grub/

Find great Linux & programming tutorials for beginners and experts, java mobile applications and games, wallpapers, jokes, SMS and other entertainment stuff. Subscribe to our RSS Feeds and Like Us in Facebook. Also you can leave a comment below.

0 comments:

Post a Comment