How to restore Grub 2 after reinstalling Windows XP/Vista/Win7

This post was written by admin on October 20, 2009
Posted Under: General

After reinstalling Windows in the computer dual boot with both Windows and Ubuntu Linux,you need restore grub because mbr has been rewritten.This tutorial shows how to restore grub 2.

Update:Today I ghost my XP system,but after restore grub,I cannot boot into XP by clicking the old windows option in grub menu.So you’d better to run this command to renew the grub2 boot list after trying following method:

sudo update-grub

1).Using grub4dos
First download grub4dos from here.
1. For XP user,copy the file “grldr”(without quotes) from grub4dos package to C:\.Edit boot.ini (hidden file in C:\) and add this line to the file:

c:\grldr="grub4dos"

For Vista/win7 user,copy the file “grldr”,”grldr.mbr” to C:\.Create boot.ini file in the root directory of C:,copy and paste following into this file.

[boot loader]
timeout=0
default=c:\grldr.mbr
[operating systems]
C:\grldr.mbr="Grub4Dos"

2. Now,create menu.lst in root directory of C:,its content:

timeout 0
default 0
title grub2
find --set-root /boot/grub/core.img
kernel /boot/grub/core.img
boot

Restart computer,and select boot from Grub4Dos.Then select boot up Ubuntu in grub menu.
Once login,use this command to install grub into mbr:

sudo grub-install /dev/sda

2).Using Ubuntu 9.10 livecd or higher
Here assuming the Ubuntu partition is sda7,and /boot partition is sda6 (if you have a separate /boot partition).
Boot up ubuntu from the livecd,open terminal and run:

sudo -i
mount /dev/sda7 /mnt
mount /dev/sda6 /mnt/boot  #skip this one if not have a separate /boot partition
grub-install --root-directory=/mnt/ /dev/sda

If you miss “grub.cfg” file,use following to recreate:

mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
chroot /mnt update-grub
umount /mnt/sys
umount /mnt/dev
umount /mnt/proc
exit

3).Using the cd/usb boot up with grub
Boot up the cd/usb,press c in grub menu.Type:

grub>find /boot/grub/core.img
grub>root (hdx,y)   (previous command will output the x,y)
grub>kernel /boot/grub/core.img
grub>boot

After the boot command,you’ll go into grub2 menu.Select to boot up ubuntu,and run this command to restore grub:

sudo grub-install /dev/sda

Related posts:

  1. How to install Windows 7 from Ubuntu without burnning a disc
  2. 3 Ways Setting XP/Vista/Windows 7 as default bootup OS In Grub 2
  3. Install Ubuntu 9.10(Karmic) from Windows XP dual-boot system
  4. Add Windows into grub menu after install Ubuntu
  5. How to install ubuntu9.04 dual boot with Windows XP

    Tags:

    Reader Comments

    Hey thanks,Number 2 this was the only tutorial that worked. I didnt have to do none of that stupid chroot, that I tried from another site. I thought it would be that simple but alot of other tutorials have the backwards chroot method dont know why?

    [Reply]

    #1 
    Written By Meka on October 29th, 2009 @ 8:41 pm

    Hi,
    I have a simpler method in my blog.
    Restoring the Grub after reinstalling Windows

    [Reply]

    admin Reply:

    @R.Srijith , this is for grub 2.I had tried your method,but it didn’t work.

    [Reply]

    manoj Reply:

    update ur ubuntu man

    [Reply]

    #2 
    Written By R.Srijith on November 3rd, 2009 @ 5:26 am

    My sincere apologies. This DOES WORK!

    I was sooo frustrated with having spent an hour plus on this problem. You would think it would be part and parcel with the 9.10 installation.

    To recover the grub boot shouldn’t be soooooo hard (or at least the installation should auto-link to this site!!!!, or similar, with correct information regarding the grub2 peculiarities — e.g. no menu.lst.).

    But again, my apologies, and sincere thanks for this post.

    Cheers

    [Reply]

    matt Reply:

    you should not have to do this at all, windows should not over write an existing boot loader, it’s just irresponsible of them to continue to allow this to happen.

    It is a deliberate choice by microsoft to overwrite grub and replace it with their own shitty boot loader with no mention of other operating systems.

    Dont blame ubuntu or grub, at least they include windows

    [Reply]

    #3 
    Written By fairdinkum on November 5th, 2009 @ 4:07 pm

    This howto was useful for me twice today.

    I`m brazillian, but I`m lucky cause I can read in English. There`s a lack of good tutorials and howtos in Portuguese.

    Could I translate some of them?
    Mail me so we can talk about it.

    [Reply]

    #4 
    Written By Neto on November 13th, 2009 @ 6:56 am

    This does work… not so well
    I have dual boot machine, xp and ubuntu 9.10
    my xp broken, so i reinstall it
    then I follow step 2
    ubuntu is up and running again
    but I cannot get into xp now
    some error like device not found or what

    any suggestion?

    Thanks
    Regards
    Hendra

    [Reply]

    admin Reply:

    Try manually adding entry for XP in Grub 2.Read this:
    http://ubuntuforums.org/showthread.php?t=1195275

    [Reply]

    Charlie Reply:

    I had the same problem when I installed Ubuntu 10.4 LTS and windows xp crapped out. I put in the Xp cd, then ran recovery console, then executed fixboot fixmbr, I booted to windows, downloaded grub4dos, and bingo! now I can boot ubuntu from grub.

    [Reply]

    #5 
    Written By hendra on November 17th, 2009 @ 9:07 pm

    Hi,

    I am having some roblems in applying this guide (no. 2) after reinstalling windows. I am using a USB to boot using the liveubuntu version and further, when I start typing in the command:
    COMMAND: grub-install –root-directory=/mnt/ /dev/sda
    RESULT: The file /mnt//boot/grub/stage1 not read correctly.
    Stuck here.. need some help to proceed..

    [Reply]

    admin Reply:

    Hi,Sharath!make sure you have mount the right partition.
    use “sudo fdisk -l” to find ubuntu partition “sdx,y”
    And change this command to”grub-install -root-directory=/mnt /dev/sdx,y”

    [Reply]

    #6 
    Written By Sharath on December 3rd, 2009 @ 8:03 pm

    Hi, I changed the command to grub-install -root-directory=/mnt /dev/sda5 but the error is the same.
    grub-install -root-directory=/mnt /dev/sdx,y

    FYI, I am reproducing the fdisk output:
    omitting empty partition (5)

    Disk /dev/sda: 120.0 GB, 120034123776 bytes
    255 heads, 63 sectors/track, 14593 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0×366ed536

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 2603 20908566 7 HPFS/NTFS
    /dev/sda2 2604 14593 96309675 f W95 Ext’d (LBA)
    /dev/sda3 5207 9076 31085743+ 7 HPFS/NTFS
    /dev/sda5 2604 4670 16603114+ 83 Linux
    /dev/sda6 4671 5206 4305388+ 82 Linux swap / Solaris
    /dev/sda7 9077 14593 44315271 7 HPFS/NTFS

    Thanks for your help, I really appreciate it.

    [Reply]

    admin Reply:

    boot up from the ubuntu 9.10 liveusb or livecd
    use:
    sudo -i
    mount /dev/sda5 /mnt
    grub-install –root-directory=/mnt/ /dev/sda

    this should work.I have tried this several times.

    [Reply]

    admin Reply:

    There are two “-” before “root-directory” in last command

    [Reply]

    #7 
    Written By Sharath on December 4th, 2009 @ 7:25 am

    Does this work for Ubuntu 8.10 (especially the second method)? If not what should be changed?

    [Reply]

    admin Reply:

    This should work if you have upgraded to grub2 in ubuntu 8.10,but you need a ubuntu 9.10 livecd/dvd/usb for the second method.

    [Reply]

    #8 
    Written By nocturn on December 6th, 2009 @ 11:25 am

    in the Grub4Dos tutorial for those who got problems booting windows7 after this process, you should run “sudo update-grub” without quotes. and it will fix the problem

    [Reply]

    #9 
    Written By Seif Sallam on December 30th, 2009 @ 12:41 pm

    If you use 1st method (grub4dos) after getting back to your Ubuntu distro and reinstalling grub you need to remove “grldr” “grldr.mbr” “boot.ini” & “menu.lst” from your Windows “C:\” partition. If you don’t remove them, trying to boot into Windows will just throw you back into GRUB.

    Thanks a lot for guide.
    Could you use space after punctuation or use quotes for every file and path (guessing that blog automatically removes spaces) because for example “C:\.Create” fooled me to think that Win7 uses same method to hide files and folders as Linux does -> tried to find “.Create” from “C:\” :)

    [Reply]

    #10 
    Written By Truin on January 5th, 2010 @ 4:04 pm

    ur mad genius lol….it took me like 10 attempts of all other methods and this method of yourz so simple and worked straight away wow….thank u

    [Reply]

    #11 
    Written By Ghost-1-0-1 on January 6th, 2010 @ 5:47 pm

    I went from Windows XP to Windows 7 in a dual bot situation with Ubuntu 9.10. After that, the grub boot menu was gone and my Asus 1000H netbook botred directly to Windows.
    Number three worked for me as an easy solution. I tried number two first, but without luck. Thanks for this great article!

    [Reply]

    #12 
    Written By Marco on January 9th, 2010 @ 1:44 am

    DUDE U ARE THE MAN!!! method 2 worked for me!

    my situation was like this: i first installed xp and then ubuntu 9.10

    so sda1 -> xp
    and sda2 -> ubuntu

    grub2 bootloader was handling everything and it was working fine until last night when i logged into my xp partition and modified boot.ini to remove the recovery console option(i couldnt stand it! :P ). on my next reboot, grub2 bootloader was gone and my pc was only booting to xp on without any other options in between. so i tried your method (2) just the first part and it worked like a charm! grub2 bootloader is back!!! million thanks brov! :)

    this is what i used after booting with the live cd:

    sudo -i
    mount /dev/sda2 /mnt –> my ubuntu partition
    grub-install –root-directory=/mnt/ /dev/sda

    [Reply]

    #13 
    Written By Harry on January 18th, 2010 @ 10:30 am

    thanks dude…. the info given by you really helped me a lot…. i was struggling a lot to restore the grub,and this site came handy for me . thanks once again

    [Reply]

    #14 
    Written By ganapati on January 28th, 2010 @ 12:31 am

    Thanks heaps, I used method 2) live CD and it worked fine after I found the password for root. Live CD kept asking for a password, sudo -i was not working. su works fine.

    [Reply]

    #15 
    Written By Rushy on January 30th, 2010 @ 6:50 pm

    Used both the XP and Win7 methods on separate installs of Ubuntu 9.10.

    XP method was flawless, except I ended up editing the boot.ini file so only 1 option (Win XP) was available so during boot it would pause to ask if I wanted WinXP or Grub4Dos. I also had to use “sudo update-grub” from ubuntu to get WinXP to boot in correctly.

    On the Win7 box I had to “sudo update-grub” and delete “grldr” “grldr.mbr” “boot.ini” & “menu.lst”. After that everything was flawless.

    Also initially had a problem with creating the file “C:\.Create” from windows. Eventually found that one out.

    [Reply]

    #16 
    Written By DavisEngy on February 10th, 2010 @ 3:37 pm

    Hi Method 2 worked for me, no problems, many thanks. Phil

    [Reply]

    #17 
    Written By Phil on March 5th, 2010 @ 8:01 am

    I have a problem with Grub2. Not exactly sure what I did but after a couple of weeks running smooth as class and keeping up with my updates, suddenly when I book, I get the Grub2 list of OSs and if I allow the first option (Lucid Lynx) generic I get dumped to the command line. I try to startX and am told that it is already running but I cannot get to it. If I start in recovery mode it boots fine. I have run update-grub and it completes and creates a new grub.cfg file but it does not fix my problem. Any help appreciated.

    jeff
    jdorwart@gmail.com

    [Reply]

    #18 
    Written By jeff on March 14th, 2010 @ 9:59 pm

    Windows Vista is good but it can hog your CPU and Memory.`.;

    [Reply]

    #19 
    Written By Kevin Mitchell on May 9th, 2010 @ 11:54 am

    Hi, thanks for your post. Very useful (for me) :)

    [Reply]

    #20 
    Written By panoet on July 3rd, 2010 @ 8:40 pm

    Brilliant.

    [Reply]

    #21 
    Written By monkeyman on July 8th, 2010 @ 6:34 pm

    3).Using the cd/usb boot up with grub
    Boot up the cd/usb,press c in grub menu.Type:

    this stage i got “grub>” but i try

    “grub>find /boot/grub/core.img”

    that tell to find command not found what is the reason for this

    [Reply]

    #22 
    Written By duleep on July 24th, 2010 @ 5:13 am

    Will this work also for other Linux distributions? I have CentOs5.3.

    [Reply]

    #23 
    Written By sutapanaki on July 25th, 2010 @ 2:14 pm

    Please consider this method of updating GRUB2:
    Fire up a terminal from the Live CD for Ubuntu 10.04.
    $ sudo fdisk -l (Note the partition number on which Linux resides)
    $ sudo mount /dev/sdaX /mnt (Replace X with the partition number housing Linux)
    $ sudo grub-install –root-directory=/mnt/ /dev/sda
    $ sudo reboot
    $ sudo update-grub

    Credits to
    http://mundogeek.net/archivos/2009/12/08/recuperar-grub-2/ for the enlightening post &
    http://www.webupd8.org/2009/12/how-to-recover-grub2-linux.html for the awesome translation.

    [Reply]

    #24 
    Written By growingneeds on August 4th, 2010 @ 2:44 am

    Dude, this totally works! I installed W7 and it wiped out my grub (ubuntu 10.04). I tried the Grub4Dos (cos my live CD didnt worked) and Voilá!

    It worked. Thanks a lot dude!

    [Reply]

    #25 
    Written By Ajmarquez on August 24th, 2010 @ 12:27 pm

    Strange, it keeps giving me grub2 shell.

    [Reply]

    #26 
    Written By Noob on August 25th, 2010 @ 2:26 am

    Add a Comment

    required, use real name
    required, will not be published
    optional, your blog address