Monday, August 23, 2010

Playing with Grub 2

After installing Linux, you may find similar Grub boot loader startup screen.

Most user don't like this list. Here we will learn how to make our own list. I am using Zorin OS 3/Ubuntu 10.04. These steps may be applicable for other Linux. I have dual boot with Windows XP. You may have Windows Vista OR Windows 7 etc.

First of all open terminal and open nautilus/folder browser with root/admin rights.

sudo ls
sudo nautilus &

The '&' sign will let terminal to start nautilus in background. So that the terminal with admin rights would be available to execute further commands.

Now open grub.cfg on following path


grub.cfg contains the configuration for current grub menu list. We normally don't edit this file.

Now move control to following path


This contains files starting with different numbers. Lower number files will come first in the Grub menu list. And higher number files will come at the end of Grub menu list.

Now the plan is to make one entry for Zorin OS/Ubuntu and one for Windows XP OR may be other entries according to your requirements. Here, first we create our required entries and if they are working fine, then remove unnecessary entries.

I prefer to create a separate file for each operating system. If you don't prefer that then put all the menu entries into 40_custom file. For details read 'Custom User Entries' section on this link OR visit this link.

Now create a new empty file for Ubuntu/Zorin OS i.e named 41_ubuntu and put following line in it

#!/bin/sh -e
echo "Ubuntu" >&2
cat << EOF

You can type any thing instead of "Ubuntu" in above lines. These line are just for providing conformation to us when updating grub.

Now copy a required menu entry for Ubuntu from grub.cfg. It would be between these lines

### BEGIN /etc/grub.d/10_linux ###
### END /etc/grub.d/10_linux ###

i.e I am copying following data and putting at the end of file 41_ubuntu

menuentry 'Ubuntu, with Linux 2.6.32-16-generic' --class ubuntu --class gnu-linux --class gnu --class os {
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 444539ba-ab9e-4028-94f5-c1a86b5ec7c1
linux /boot/vmlinuz-2.6.32-16-generic root=UUID=444539ba-ab9e-4028-94f5-c1a86b5ec7c1 ro   quiet splash
initrd /boot/initrd.img-2.6.32-16-generic

You can type any thing instead of 'Ubuntu, with Linux 2.6.32-16-generic' in above lines. This line will become the grub menu entry.

Now put following line at the end of file 41_ubuntu


Now save and close file 41_ubuntu

Now right click on file 41_ubuntu and click properties. And then click on permission tab and tick the check box for execution (Allow execution file as program).

Now the process for Ubuntu entry is complete. Do the similar steps for Windows XP, Windows Vista, Windows 7 OR other Linux.

After finishing you required entries, we need to update grub by this command

sudo update-grub

This command will ultimately update grub.cfg file automatically.

Now you need to restart computer to test your entries are working file OR not. If they are working fine then you can proceed further for excluding unnecessary entries from the grub menu.

After testing and restarting computer, get the root/admin rights again by executing command given at the start of this post. Now untick the check box for execution (Allow execution file as program) as describe above for following files


Now you need again to update grub by following command
sudo update-grub

Now you menu system is ready. Restart computer and enjoy short menu.

For other easy configuration (i.e changing default operating system, boot timeout, resolution, color depth etc) install StartUp Manager.