I just installed Ubuntu 9.10 ‘Karmic Koala’ in my notebook, which already had Windows XP and Fedora Core 10 installed, and the new GRUB2 boot menu created by Ubuntu only consisted of boot entries for itself and Windows XP — FC10’s entry is missed as expected. So I need to take care of it a little bit to get my FC10 back.
The problem is, GRUB2 doesn’t have our familiar configuration file, /boot/grub/menu.lst, anymore! And it took me more than half an hour to learn configuring GRUB2. Most of the time I got lost in some random webboards with too little details about GRUB2 (my bad, maybe I used the wrong keywords = =”), until I found this very useful web page: https://help.ubuntu.com/community/Grub2 — it contains everything I want! But it’s a bit too detailed so I decided to make some quick reference here:
- /boot/grub/menu.lst has been replaced by /boot/grub/grub.cfg
- /boot/grub/grub.cfg does not meant to be edited by any user (even root), it should be generated from the scripts in /etc/grub.d/
- In each (re)generation of grub.cfg, all scripts in /etc/grub.d/ are executed.
- The default scripts names are lead with a 2-digit number. The lower the number, the sooner it will be executed.
- We can add arbitrarily any scripts of any names as well.
- Some scripts worth mentioning in /etc/grub.d:
- 10_linux: generates entry for the current OS. (Ubuntu 9.04 in this case)
- 30_os-prober: generates entry for the other OSes it detects. (Windows XP in this case)
- 40_custom: free space for us to add our custom entries = the new /boot/grub/menu.lst
So… what to do?
- Copy the entry template from the file /boot/grub/grub.cfg, such as
- menuentry “Ubuntu, Linux 2.6.31-14-generic” {
set root=(hd0,7)
search –no-floppy –fs-uuid –set 3259f467-9dab-45c2-9896-d9963b0629fc
linux /boot/vmlinuz-2.6.31-14-generic root=UUID=3259f467-9dab-45c2-9896-d9963b0629fc ro quiet splash
initrd /boot/initrd.img-2.6.31-14-generic
}
- menuentry “Ubuntu, Linux 2.6.31-14-generic” {
- Paste it in 40_custom and then modify. (The text in green above is what should be edited)
- Some keywords/modifiers are changed
- title -> menuentry
- root -> set root =
- kernel -> linux
- Be careful with the partition numbers, GRUB2 start the count at 1.
- Device numbers still start at 0.
The text in orange -> I think it’s not necessary so I commented it out (using #) and it still works, still haven’t searched what it means yet. (If anyone knows please tell me, thank you ^^)
- Some keywords/modifiers are changed
- If you want to change the order the custom entries appear, then just change the file name (split in to many files too if needed)
- Every custom files should begin with these 2 lines (to make the system write the contents in all lines below to grub.cfg):
- #!/bin/sh
- exec tail -n +3 $0
- Every custom files should begin with these 2 lines (to make the system write the contents in all lines below to grub.cfg):
- run sudo update-grub to cause all the scripts to be executed