How to configure Grub2 in Ubuntu 9.10
Grub2 is now the default bootloader for most of the distros. It is the next generation of GNU GRUB and aims to be cleaner, safer and more powerful than its previous version Grub legacy. In order to provide such features it was written from scratch and so the way it is configured is quite different from Grub Legacy. Since, we linuxers always want to run our systems our way ;), you might be interested in learning how to configure grub2 so that you may comfortably tweak and play around with it.
Grub2 Configuration Files
Like Grub Legacy grub2 resides in /boot/grub but there is no menu.lst file in Grub2. Its configuration file is /boot/grub/grub.cfg. But be careful, this file is not meant to be manually edited (read the last part of this article if you want to edit it anyway). Don't worry, that doesn't mean that you can't configure grub2. Actually, grub.cfg is generated by individual scripts residing in /etc/grub.d/ when "update-grub" command is executed and only read permissions are given to this file to avoid manual editing.
This file grub.cfg is divided into sections, each section is handled by an individual script file (in /etc/grub.d folder). You may see entries similar to the following in your grub.cfg file.
### BEGIN /etc/grub.d/10_linux ###
set root=(hd0,5)
search --fs-uuid --set b02e1934-12dd-418a-be3a-9ff7d3e7e7ea
menuentry "Ubuntu, linux 2.6.28-13-generic" {
linux /boot/vmlinuz-2.6.28-13-generic root=UUID=b02e1934-12dd-418a ro quiet splash vga800
initrd /boot/initrd.img-2.6.28-13-generic
}
### END /etc/grub.d/10_linux ###
These lines mean that this section is handled by the script file /etc/grub.d/10_linux. There are similar sections for each script file. Their naming scheme is similar too (XX_filename, XX is the 2 digit number e.g 10, 20). These special names decide which script to run first. The file that comes before another in the alphabetical ordering will be executed first (e.g. 10_hurd will be executed before 10_linux which will be execute before 20_memtest86).
There is another important file responsible for the content of grub.cfg, it is /etc/default/grub. This file holds the content previously found in the upper section of menu.lst. These settings are primarily concerned with Grub's menu display. So, if you want to change any setting related to the grub display or interface then change this file. And yes, this file can be manually configured.
Adding Entries in the Grub2 Menu
Since, the grub.cfg file is not meant to be manually edited you will have to add scripts in /etc/grub.d/ in order to add entries to the grub menu. Trust me, it sounds quite difficult but its not. The syntax is really easy and anyone can learn it within no time.
The user added custom scripts should have a name with prefix 40_ (eg 40_custom). Now, if we want to write a script that adds a menu entry to boot an OS residing on another partition or another disk in the Grub. The script should look something like this.
echo "Adding Custom Kernel & SystemRescue" >&2
cat << EOF
menuentry "Ubuntu, linux 2.6.31-11-custom" {
set root=(hd0,9)
linux /boot/vmlinuz-2.6.31-11-custom root=UUID=c6829e27-2350-4e84-bdbb-91b83f018f98 ro
initrd /boot/initrd.img-2.6.28-11-generic
}EOF
The first line will print the message in quotes "Adding custom .." when this script runs just to give a visual feedback that this script is executing. So, this line is not compulsory.
As you can notice the "menuentry" tag is used to define the menu entry we are going to enter followed by the name of that menu entry (the name that appears in the menu). The grub2 commands that should execute when this menu entry is clicked are entered in curly braces '{}'. You might have already noticed that the "kernel" command of the grub legacy which was used to mention the kernel image is replaced by "linux" in grub2. Rest of the syntax is almost same. After creating your own script file make sure to give it executable permissions.
[shredder12]$ sudo chmod +x /etc/grub.d/<filename>
Removing Entries from Grub2
You don't need to write scipts for removing entries. Either remove the executable permissions from the scripts in /etc/grub.d/ or remove those files from that directory and execute "update-grub" to generate new grub.cfg. You can remove the permission using the following command
[shredder12]$ sudo chmod -x /etc/grub.d/<filename>
Consider an example, if you don't want memtest86+ menu entry all you have to do is remove the executable permissions from the script that generates that entry (/etc/grub.d/20_memtest86+).
[shredder12]$ sudo chmod -x /etc/grub.d/20_memtest86+
If you want to remove the "boot in recovery mode" entry then you can do that by uncommenting this line in /etc/default/grub file
GRUB_DISABLE_LINUX_RECOVERY=true
Editing the /etc/default/grub file
As I have already mentioned above this file contains the settings that were used to be in the upper part of the menu.lst file, above the grub2 menu entries. So, if you want to change the timeout, disable/enable some default settings(like the recovery mode setting above) then you should probably look into this file, make the changes you wish and then update grub.
If you want to know the meanings to the term in the /etc/default/grub file then you may refer to this ubuntu wiki page.
Changing grub2 splash images
I have written a separate article for grub2 splash images. You may read it here.
Manually editing grub.cfg file
Warning: Please don't try to manually edit grub.cfg until and unless you really know what you are doing.
When the command "update-grub" is executed grub.cfg is generated and its permissions are set to read only. You can grant write permissions to the file as root using the following command.
[shredder12]$ sudo chmod +w /boot/grub/grub.cfg
and then open the file with your favourite editor ( i will use gedit).
[shredder12]$ sudo gedit /boot/grub/grub.cfg
P.S - The file will return to "read only" mode and your changes will be overwritten anytime "update-grub" is executed.
I hope this article has covered most of the Grub2 basics. If you think that there is something wrong here then please comment, I have already checked it a few times and I hope I haven't missed anything.

































18 Comments
Thankyou Betelgeuse for pointing them out. I have added a link to the ubuntu grub2 documentation for editing the /etc/default/grub2 file and added another link to my article on grub2 splash images.
Hi Paul,
If you are facing this problem after a fresh install of Ubuntu, then you may try running "sudo update-grub" after booting into the system. This should solve the problem but if not then you might want to check the scripts in /etc/grub.d/ that is responsible for recognizing other operating systems, consider reinstalling grub2 as the last option (in case nothing works).
Hi Paul,
It seems Grub2 is unable to probe the boot devices in other hard drives. I am not sure about this problem because I have never dealt with booting OSs from external hard drives but I think its a fair chance that there is nothing wrong with the grub installation you are just doing it the wrong way.
I would suggest you to post it on ubuntuforums, there you might find some users experienced with such kind of installations or who have faced such errors. It would be good if you could post its link here so that other users with similar problems can follow.
Hi ZoltAi,
This method you are using is actually for grub legacy. But you have grub2 in Ubuntu 9.10 and since you don't have /boot/grub/stage1 in grub2 it is giving "file not found" error. So, in order to solve your problem you should boot into Ubuntu 9.10 and run "sudo update-grub" and see if you get an output line saying that "windows XP is detected on some drive". If this doesn't work then you may want to switch to the older kernel ( you can do this from the grub menu when you boot)and again try this command. If its really a kernel issue then your problem should get resolved.
I never really got a chance to work with grub2 custom config files. Would love to see your result.
Post new comment