How to Edit Grub’s Boot Menu – Adding an OS

I have been rewriting Grub’s boot menu many times. However, I would like to post it here for some of you guys and also for my future reference in case I forget how to do it. There is a lot of things and options in Grub so I will not be able to cover them all. I will only show you how to add an OS to your boot menu.

NOTE: Before trying this out, read my tutorial on how to recover grub just in case something goes wrong.

To edit Grub menu, we must use terminal.

Edit Grub Menu

  1. Open Terminal: Ctrl+Shift+T or Applications -> Accessories -> Terminal
  2. We need to see what OS is on which partition. Use the command below.

    df -h

      The output will be something like this.

  3. Take note which OS is on what partition. You can do that by looking at the size of the partition. For instance, one of my partitions (sda3) has 12G and mount on “/”, I know that is my Ubuntu partition. Likewise, sda1 has 47G and is my Windows partition. Remember these details, you are going to need them later (in step 9).
  4. Navigate to the grub folder

    cd /boot/grub

  5. Open the menu.lst file in Gedit so we can edit the file

    sudo gedit menu.lst

  6. Enter your password. Gedit will open the file with root authority.
  7. Scroll down to the part where it look somewhat like this

    title Ubuntu
    root (hd0,2)
    kernel /boot/vmlinuz-2.....
    initrd /boot/initrd.img.....
    quiet

  8. Now, to add an OS, follow the example below

    title XP
    root (hd0,0)
    makeactive
    chainloader +1

  9. Copy all the options above and paste it into your grub menu.lst, right below the existing options, you only need to modify the title and your root.
    In modifying your root, know that the hd0 means it’s your first hard drive, and the 0 after the comma tells the partition. My XP partition is in sda1, therefore, my root is (hd0,0). IF it was in sda2, my root would be (hd0,1). And so on, sda3 would result in (hd0,2). Adjust your option accordingly.
  10. After you are done modifying, save the file and close the application.

Now you have added a new OS into your booting.

Advertisements

Restoring Grub.

Just a few minutes ago, I got a HFS+ Partition Error while trying to boot into my OS X. So, I decided to mess with it a little bit. Actually, I reinstalled OS X and messed around some more (the whole process took 3 hours). Somehow, my Grub was gone after the reinstallation. There went my beloved boot manager, who had saved me so many times. I went right to the first stage of grief, denial. I put my Ubuntu live CD in, loaded Firefox on and search for the solution. Folks at Ubuntuforum.org had found the solution years ago. So I just summed everything up, it’s all their credits. (If you are not a member of Ubuntuforum.org join now! it’s awesome.)

Restoring Grub with a Ubuntu Live CD.

You are going to need the Ubuntu Live CD.

  1. Insert the Live CD and boot into Graphic Mode.
  2. Open Terminal: Applications -> Accessories -> Terminal
  3. Enter the Grub Shell.

    sudo grub

  4. Look for your grub files location.

    find /boot/grub/stage1

  5. The returned value from the command above is used for the command below. Scan the partition.

    root (hd?,?)

  6. Substitute the returned value into (hd?,?) above. For instance, if my returned value is (hd0,2), I will enter:

    root (hd0,2)

  7. Now, we reinstall Grub.

    setup (hd0)

  8. Quit Grub.

    quit

  9. Close Terminal and Restart. Grub will starts back again.

I took a snap shot of this whole process. Take a look.