How to restore Grub 2 after reinstalling Windows XP/Vista/Win7
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-grub1).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:
- How to install Windows 7 from Ubuntu without burnning a disc
- 3 Ways Setting XP/Vista/Windows 7 as default bootup OS In Grub 2
- Add Windows into grub menu after install Ubuntu
- Grub missed after reinstall Windows,or Grub error17 after delete Ubuntu partition
- Install Ubuntu 9.10(Karmic) from Windows XP dual-boot system

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]
Hi,
I have a simpler method in my blog.
Restoring the Grub after reinstalling Windows
[Reply]
admin Reply:
November 3rd, 2009 at 5:36 pm
@R.Srijith , this is for grub 2.I had tried your method,but it didn’t work.
[Reply]
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]
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]
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:
November 18th, 2009 at 4:09 am
Try manually adding entry for XP in Grub 2.Read this:
http://ubuntuforums.org/showthread.php?t=1195275
[Reply]
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:
December 3rd, 2009 at 10:39 pm
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]
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:
December 4th, 2009 at 10:46 pm
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:
December 4th, 2009 at 10:47 pm
There are two “-” before “root-directory” in last command
[Reply]
Does this work for Ubuntu 8.10 (especially the second method)? If not what should be changed?
[Reply]
admin Reply:
December 6th, 2009 at 6:09 pm
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]
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]
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]
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]
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]
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!
). 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]
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]
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]