Wednesday, November 11, 2009

Cannot Boot Linux after Installing Windows! Bootloader (GRUAB) Recovery

You installed Linux. Then after that installing Windows XP/ Vista/ Seven (any Microsoft Operating System) you found that your Linux is simply gone. Your computer directly boots to Windows.



You got surprised as you don’t know how this happened. This is a common problem with installing Windows after Linux. It rewrites the Master Boot Record without any notification. As Linux grub was in Master Boot Record it is over-written and gone. Did Linux actually go? Nope. It’s not actually gone. You list the partitions using diskpart in Windows or in disk management console you will see the partitions for Linux still exist. Can we get Linux back life before?

Answer is yes if you haven’t deleted any Linux partition. We just need to recover the Linux bootloader. I shall tell how to recover grub bootloader here. You can recover your grub either using a Ubuntu live CD or other Linux media (CD/DVD). I’ll describe both. Recovering grub is safe because you will be able load (actually it is called chainload) windows too.

Method 1 (using Ubuntu Live CD)
  • Boot using Ubuntu CD selecting option “Try Ubuntu without making changes to your computer”.


  • Wait until it boots completely.
  • When it’s ready open run dialog box by pressing Alt + F2.



    Type exactly “gnome-terminal” there without quotes
  • A terminal where you can give commands will appear.



    Type “sudo fdisk –l” in the terminal.

    # sudo fdisk -l




    Click the image to enlarge.

    You’ll see an output with listing partitions in your disk. Find out the entry saying Linux partition. Notice the partition number. It will look like this sdax; where x is any one or two digit number. Remember this value of x.

    According to our example as shown in the above image it is sda5. So x = 5
  • Now type “sudo grub”. Wait sometime.

    # sudo grub


    A grub prompt will appear.


  • Now type “root (hd0, y)” where y is 1 less than x and hd0 means first harddisk. If the output says it’s ext2fs then it’s okay. Else try with other Linux partition number with the same command again. In our example it is 5-1 = 4. So the command in our case is root (hd0, 4)

    GRUB> root (hd0,4)
  • After you got ext2fs in your output type “setup (hd0)”

    GRUB> setup (hd0)

  • Now grub is written in your Master Boot Record again and you get back all the options. Type “quit” to exit grub prompt.

    GRUB> quit

  • Type “sudo reboot” in the terminal. Pick the live CD from CDROM drive when it is ejected and then press enter. And you get everything like before.

Method 2 (using Fedora Core DVD/any other Linux CD/DVD)
  • Boot your computer from the CD/DVD




  • If there is a boot option like rescue Linux then you must select it. Else select text mode. If you don’t find text mode see helps pressing F1, F2 etc options. In text-mode type exactly “linux rescue” without quotes.


  • Skip media test if your media is ok.
  • When comes a dialog box asking to enable network interface select no.
  • Wait until it boots. After it is booted successfully a text-based terminal is presented before you.
  • Type “chroot /mnt/sysimage” in the terminal
  • Now type “fdisk –l”.



    Click the image to enlarge.

    You’ll see an output with listing partitions in your disk. Find out the entry saying Linux partition. Notice the partition number. It will look like this sdax; where x is any one or two digit number. Remember this value of x.

    According to our example as shown in the above image it is sda5. So x = 5
  • Now type “grub”. Wait until it loads. It may take longer depending how old your BIOS is. A grub prompt will appear finally.


  • Now type “root (hd0, y)” where y is 1 less than x and hd0 means first harddisk. If the output says it’s ext2fs then it’s okay. Else try with other Linux partition number with the same command again. In our example it is 5-1 = 4. So the command in our case is root (hd0, 4)

    GRUB> root (hd0,4)

  • After you got ext2fs or 0x83 in your output type “setup (hd0)”

    GRUB> setup (hd0)

    Now grub is written in your Master Boot Record again and you get back all the options. Type “quit” to exit grub prompt.
  • Type “reboot” in the terminal. Eject the CD/DVD-ROM during reboot to boot from Harddisk.

If you face any kind of trouble just mention in comments I’ll tell you how to solve.

No comments:

Post a Comment