Fix Windows 7 MBR after GRUB

During a Linux install to my 2nd hard drive, GRUB was automatically installed to the wrong MBR (master boot record). The files were on the /boot of the Linux drive, but the Windows drive’s MBR was used. This meant without both drives, I could not boot either operating system.

I installed GRUB manually with grub-install /dev/sdb. Now I needed to restore the original Windows 7 MBR so that it didn’t require GRUB to boot it.

The Windows 7 “startup repair” from the installation disc detected the OS but didn’t find any boot problems with it, so I went to the command prompt on the disc.

There are several commands for this. A lot of web pages suggest using “bootsect”. However, this did not fix anything. The fact that it was for use on individual partitions was probably a clue on that. Some web pages even used “bootcfg” which is for older Windows installs such as XP (it affects your boot.ini), but is still included on the Windows 7 disc to add to the confusion.

The command that did work was:

bootrec /fixmbr

Afterwards, for good measure, I also ran:

bootrec /fixboot

Tags: , , , ,

30 Responses to “Fix Windows 7 MBR after GRUB”

  1. Matt says:

    Yaaaay, a new post. :)

    Hope you didn’t spend too long looking for these commands, if you’d asked me I would have told you as I’ve accidentally overwritten my windows MBR with grub in XP, vista AND 7. I’m just too pro, that’s why I don’t learn from my mistakes.

    Anyway, there’s a website I always use, apcmag.com. They have pretty good instructions on dual and tripple booting with any number of combinations of installing whatever one last. Their vista + linux with vista installed first one should have these instructions in it.

    Be warned though, My dell had 3 partitions to start with on one hard drive, dell utility, dell recivery (vista preinstall environment) and vista. I installed windows 7 onto a separate drive, so that installed a “windows 7 system drive” for booting and the actual windows 7 partition. Every time I try to enter the windows 7 repair DVD it tries to change the vista and dell recovery partitions and it also caused problems one time by telling my hard drive to boot from the windows 7 partition and not the “7 system” partition, where the actual windows 7 bootloader is.

  2. jon says:

    So I’m dual booting Windows 7 and Ubuntu. Grub works fine and its working out pretty good now. Only problem is I can’t hibernate windows 7. I was told on the windows seven forums that since somehow my recovery partition got the System MBR. I was told then that I should do a startup repair to fix this. I was wondering if this was something similar to what you did.

    So in other words would a startup repair damage grub?

  3. George Helyar says:

    While this is a startup repair, I don’t think this will solve your problem.

    To be able to hibernate you need to select the correct options in your power settings in Windows’ control panel. For example, if you have hybrid sleep then hibernate is combined with standby. You also need to have a C:\hiberfil.sys with enough room for it to save to and possibly a C:\pagefile.sys too (though I’m not sure if swap is related to hibernation on Windows or not). This may mean that hibernation has been disabled because you don’t have enough free space on your hard drive to dump memory to when it hibernates, for example.

    I highly doubt it has anything whatsoever to do with Ubuntu. I have certainly never heard of this happening and I suspect the people that gave you that advice have never used Linux at all and are using the ignorant “reinstall everything” solution that people use when they don’t know how to identify a problem (here is a thread I made years ago where malware had messed with my DNS settings, and idiots tried to convince me that the only possible solution was to reinstall Windows). I have also used grub successfully with Windows hibernation before.

    Grub is two parts. One part (stage 1) is on your MBR, which is at the start of the drive. The other part is inside the Linux partition. The boot loader in the MBR runs stage 2. If you do this startup repair, it will overwrite grub’s stage 1 with windows’ boot loader and grub will not run at all (so yes it would “damage” grub). You would need to use grub-install to put it back, but that would just get you back to where you started.

  4. jon says:

    wow thanks for the awesome reply. I always wondered how exactly grub worked.

    I definitely feel your pain about ignorant windows users just telling you to reinstall windows.

    As for my hibernation I do have a hiberfil.sys and a pagefile.sys with enough free space on that partition. I also believe hibernation is enabled because I see the option in the shutdown choices.

    This is the thread that I started on seven forums.

    http://www.sevenforums.com/general-discussion/114706-hibernation-issues-ubuntu-dual-boot.html

    I’m guessing I need to find some way to change the boot flag from the recovery partition to the windows 7 partition?

    thanks for your help. I have also used grub with windows hibernate before and would love it back

  5. George Helyar says:

    The recovery and utility partitions should not be needed at all for hibernation in Windows. I always remove recovery partitions and usually remove dell utility partitions as soon as I get the machine, and have never had a problem hibernating. Windows 7 does seem to add a small “system partition” though too.

    You can use gparted in your Ubunutu (or get the gparted livecd, its only a few megabytes) to change the boot flags of partitions if you need to.

    Does it fail when hibernating or when waking up? “whenever I try and hibernate the screen just turns black and the computer goes to sleep.” sounds like it might just be doing hybrid sleep, which is a combination of hibernation and suspending. If it is doing this, wait a while to see if it eventually hibernates fully. This hybrid sleep is a compromise between the two to get the best of both worlds, with the quick sleep/wake times from suspending and the no power use from hibernation, but it does it by pretty much suspending first then hibernating while its suspended.

    Whoever said “Your System MBR is written to the Recovery drive which is not correct” doesn’t know what they are talking about at all. This line doesn’t even make any sense. You only have one drive, “recovery” is a partition only and the MBR is at the start of that drive, not inside any of the partitions.

    If partitions were causing any problems at all, they would only be with waking up.

    Your grub should be chainloading the partition with Windows 7 on it (or maybe the windows 7 “system partition”)

    I did notice that you have too many partitions though. You should stick to 4 partitions per disk. If you want more than that, use 3 primary and one extended, then put any further logical partitions inside that extended. This is a limit of IDE and should be solved by SATA/AHCI but because most software was built with this limitation in mind, you may experience problems if you go past it.

    Also, your boot partition should always be on or near the start of the disk. It is common on Linux to create a small (100 MB) /boot partition with ext2 at the start of the disk and boot off that. Grub is then installed to your MBR and that partition, and it can then boot Windows or Linux from any area of the disk. This doesn’t seem to be as much of an issue now as it used to be but it may still cause problems on some systems.

  6. Jon says:

    Again thanks for the help.

    I think you are right about the hybrid sleep but I have left it on for at least an hour and the computer has not fully hibernated.

    I do have gparted on here and I checked but the windows 7 partition does have a boot flag on it. The recovery partition does not however. The main ubuntu partition does not have a boot flag on it either. Should any of this be changed?

    Also I figured that I had too many partitions but never really did anything about it because it didn’t really cause any problems yet. How do you suggest I fix this without having to reinstall any of my operating systems? Is that even possible. If not I can deal with not hibernating my windows partition. I spend most of my time on ubuntu now anyways….

  7. George Helyar says:

    The recovery partition does not need to be bootable (or even present). It’s just an image of your system as it was from the factory. It’s just there for reinstalling Windows without needing to use a Windows DVD, and having all your drivers and bundled bloatware pre-installed. If you’re comfortable installing Windows from the DVD, don’t want the bundled bloatware and want that space back, you can just remove the partition entirely.

    gparted can move and resize your partitions to however you want them but moving is a very time consuming operation and if it fails (e.g. power loss or kernel panic during move) you end up with a corrupt partition that you can’t use.

    The only partition which should need a bootable flag is the partition with GRUB on it. Which Windows partition is booted is changed by editing your /boot/grub/menu.lst. You could try changing it from your C: to your “system” Windows 7 partition but honestly I don’t think this has anything to do with partitions at all.

    Try taking a look here:
    http://windows.microsoft.com/en-US/windows7/Sleep-and-hibernation-frequently-asked-questions

  8. Jon says:

    Thank you so much for your help. The problem probably lies in the fact that my partitions are messed up. However Since I don’t really want to try and go through the difficult task of fixing that and don’t wanna risk messing anything up I doubt I’m going to try and fix it. I’m on ubuntu most of my time anyway so its not a huge deal that hibernation doesn’t work on windows.

    I wanted to thank you again though for all of your help though. It was much appreciated.

  9. cyril says:

    I had exactly the same problem! Your solution solved my problem 1:1. Thanks for that George!

  10. Elad says:

    Hey guys,

    Being stupid enough I installed grub on my dell, now windows 7 won’t start, trying to install XP was giving me an 0x00000007x0 error (i’m not sure about the number of zeros), now I’m stuck with no OS… What should I do? Is there a way to fix it?

  11. George Helyar says:

    It’s not stupid. I’ve put GRUB on Dells before and it has worked fine.

    It’s a 32bit number so it will be 8 hex digits after the “0x” including the 7 so if you want to search for it, search for 0×00000007

    How to fix it depends on what you have left. If you still have a Windows 7 installation on there, you can use what is in this post. If you do not, you can try using dell’s recovery solution, which will image the disk back to how it was out of the factory with Windows pre-installed. If you have nothing, you may as well just wipe every single partition and install a new copy of Windows to it, but this will remove any existing files.

    You can try to recover existing files with something like DiskInternals NTFS Recovery from another computer if there are files that you want to try to recover, even if the partition is gone. I have had some success with this in the past but it is not 100% even if you have not overwritten anything, and as far as I know, there are no free NTFS recovery tools, only FAT32.

  12. Nano says:

    thank you dude , you’re my rescue circle .

  13. Mario says:

    if some people haven’t found a solution heres another thing u can try

    http://whatiiknow.blogspot.com/p/restorefix-missing-windows-7-mbr.html

  14. brx250 says:

    Hi all,

    I’ve been using several platforms for years now and I must say, the problem lies within the way windows 7 was built. I’m sure you guys are familiar with the 100mb partition the installer makes whenever you setup windows,right?
    Well it just so happens that you only have to make sure that this has a boot flag when you install grub. Windows 7 needs this partition as bootable in order to get things running again. Once you take care of that, you should be golden. Cheers!

  15. George Helyar says:

    Hi brx250,

    While this is true, I don’t know if that’s really a problem.

    I’ve been using a 100mb GRUB partition for years, likely for the same reason of booting multiple operating systems. In fact many distributions of Linux do this by default if you choose automatic partitioning, although the distribution I use, Debian, does not. This just seems like a case of Microsoft seeing a good idea that was already in use by Linux and using it.

    The problem in my case was that I had Windows on one physical disk and Debian on another physical disk, but GRUB installed to the wrong MBR i.e. the GRUB partition was on one hard drive and the MBR it used was on another, overwriting the Windows MBR instead of using the MBR on its own drive. While GRUB can be used to boot both, I wanted to have each OS isolated to its own drive, so that I could remove or replace one drive without affecting the other. As it was, I needed *both* drives to be installed and working in order to boot *either* operating system, which was not ideal. With isolated drives I can still use GRUB for both but then if I remove the Linux drive, it will just fall back to using the Windows boot loader directly.

  16. Shola says:

    How ever owns this website, I just wanna say a very big thank you from the depth of my heart. Cos the solution really worked like magic. I have consulted so many Linux forum to no success. I run Windows 7, Ubuntu 12.04 L.T.S, And Backtrack5 on my Compaq notebook. But it was the Backtrack 5 Grub that really gave me the scare. Cos If not for you, for once I thought I’ve lost my PC for good this time. After having been lucky on so many times. Now I’m safely back in my Windows 7 environment. Thanks.

  17. Gonza says:

    Thank you. I deleted my Ubuntu partitions and with them grub. So, my Windows partition wasn’t able to boot. The repair routines on the windows 7 DVD didn’t work neither. So, with your two simple commands I was able to boot into Windows again.

    Thank you!! This is why I love Internet haha.

  18. busel7 says:

    Thanks alot it work!

  19. Jayson Pagara says:

    To sir George Helyar

    I would to say a BIG Thank you for your page. I solved my problem on matter…

  20. jake says:

    You are a gentleman and a scholar. This saved me from a full restore.

  21. sunnny says:

    THANK YOU

  22. bernard says:

    awesome! That simple tweak fixed my system. thank you very much

  23. bart says:

    That totally worked for me just now since I have run into pretty much the same trouble as you have. Many thanks!

  24. Marco says:

    Good explanation, you are right about it. I did a headshoot with this solution, thx. I’ll be carefully next time with linux installers.

  25. hubert says:

    You sir just saved my life :p

  26. Kevin H says:

    You saved my life! I was afraid I totally buggered things up but this solved the problem, thanks!

  27. Nvrb4 says:

    thxxxxxxxxxxxxxxxxxxxxx

    U are great

  28. Roch says:

    Thank goodness for these posts it saved my life

Leave a Reply