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
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. Add Windows into grub menu after install Ubuntu
  4. Grub missed after reinstall Windows,or Grub error17 after delete Ubuntu partition
  5. Install Ubuntu 9.10(Karmic) from Windows XP dual-boot system

    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]

    #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]

    #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]

    #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

    Add a Comment

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