Mini-Howto: Restore Windows MBR/Bootloader with Linux

August 26, 2009

I’m often, at least more than I care, asked how to restore a Windows MBR/bootloader without having a windows install cd or a dos boot disk at hand. It’s quite easy you need just a Linux live cd like (the Ubuntu live cd or Knoppix) or an installed Linux you want get rid of. I really don’t know why you want to do the second, but anyway here are the 2 solutions I know of.

Boot Linux and make sure you’ve a working Internet connection and type following on the terminal/konsole.

1. Solution


sudo apt-get install syslinux

if the package got installed use following to write the MBR.


sudo dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda

2. Solution


sudo apt-get install mbr

if the package got installed use following to write the MBR.


sudo install-mbr -i n -p D -t 0 /dev/sda

Common for both

Replace sda if you want to install the MBR to a different drive. Take a look at your hard disks with sudo fdisk -l if you’re unsure. Finally reboot and your windows should boot.

 

On request I put this comment from a guy (whats to be anonymous) up to the main article.

Dear Robert,

You have given an excellent article. And I know how much useful it may be to a frustrated person trying to get their work done.

But I sincerely request you to do one last job of giving them a last revealing information about alleged non friendliness of linux derivatives. I think at the moment when people are visiting your post they are frustrated and they vent their ire on linux without getting the other side of the story.

Please consider my suggestions below:

In response to your post, people have been wrongly complaining (in the comments) about the user unfriendliness of ubuntu and other linux variants etc in favour of Microsoft Windows. They think that after installing a linux variant they are unable to install the Microsoft’s Windows back, even after deleting all the partitions.

This actually happens because as soon as a Microsoft Windows OS installer sees a non Microsoft bootloader (for example, GRUB), it refuses to install and says something like the environment is incorrect. Sadly further, it does not explain the ‘environment’ (which could allow a user may look up a solution). And neither does it provide there, a straightforward option to overwrite the other bootloader with its own (even if you delete all the partitions on the disk from the Windows Installer or from the outside!).

I think the Windows implementers chose not to overwrite a foreign boot loader because they did not want to support a non Microsoft OS alongside their own. But the unfortunate thing is they should not do this when not even a single partition is allocated (then obviously there can be no OS installed).

Please let the readers know that it is the Microsoft windows which does not support any non Microsoft OS sitting along side itself and not necessarily the other way round. Please put this information in the main post itself, since otherwise it gets buried under the volume of the comments.

70 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Thank you, thank you , thank you! I tried Ubuntu, could not get anything to start w/o the live CD, couldn’t get to Windows. Tried the beginner forum, got some input that didn’t work, but somewhere in there was the link to your page. It worked like a charm. I am done experimenting.

    Comment by Dave — December 9, 2009 #

  2. thanks so much for sharing. it’s so difficult nowadays to find in the great amount of resources emerging every day smth that is worth my attention. you helped me a lot:)

    Comment by Mike Hunter — March 2, 2010 #

  3. It worked like a charm. I am done experimenting.

    Comment by labatterie — April 27, 2010 #

  4. It’s THAT SIMPLE????
    [tries it]
    THANK YOU! THANK YOU! THANK YOU! THANK YOU!
    WINDOWS BOOTS AGAIN!!!!!
    THANK YOU! THANK YOU! THANK YOU! THANK YOU!
    [prints out the instructions and adds it to the “Important Computer Stuff” folder.

    Comment by Fred Doolie — June 27, 2010 #

  5. I OTOH am not done experimenting at all!. Now that I know how to re-windowize my system from a total Linux install I’m free to play around a lot more. The restore CDs that came with the system don’t restore the MBR; only the OS. In other words Grub is still in the MBR. I even tried using gparted to totally wipe the drive as if it was a new clean HDD. Windows partitioned the drive and installed but kept rebooting since there was no MBR info. Your little trick added that and now it”s all good!

    Comment by Fred Doolie — June 27, 2010 #

  6. Now that I know how to re-windowize my system from a total Linux install I’m free to play around a lot more.

    Comment by batterie — June 29, 2010 #

  7. It friggin worked, thanks dude!!!!

    Comment by Wim — September 8, 2010 #

  8. Yes! This solution was just what I needed. Thank you!

    Comment by Grady — September 25, 2010 #

  9. did not work…ALAS!

    Comment by kaykav — November 18, 2010 #

  10. [...] det om du kun har én.Start maskinen på nytt.Vips! Verre var det faktisk ikke, utrolig nok.(Kilde: Robert Penz blog)Skrevet av Alexander Karlstad 6. januar 2011 klokken 00.30Postet i Linux,Tips og triksStikkord: [...]

    Pingback by EDBloggen » Fikse boot-laster/MBR for Windows i Linux — January 6, 2011 #

  11. Did you rewrite the MBR and then immediately reboot successfully?

    Or did you need to rewrite the partition table and/or recopy the data on the disk after that?

    Comment by Nate — April 4, 2011 #

  12. ubuntu should be user frendly, messing up a disk like this so u cant even boot or INSTALL windows anymore isnt very user frendly is it.. and i never had a chooise in this… wasted hours in this crap, iam totaly done with ubuntu, only had problems with it,
    3d accel didnt work (even crashed had to reinstall) cant use my daily progs (like cs4/cs5, it did work in virtualbox but that way is crap)
    something went terrible wrong with .crypt had files over 5g and after removing those bang everything gone…, and when i removed ubuntu, icouldnot boot or install windows, real user frendly yes…, next time i will use opsuse or something in vmware or an isolated disk, neve ubuntu again bah

    Comment by whitewidow01 — April 12, 2011 #

  13. @Nate: just reboot nothing more to do

    Comment by robert — May 5, 2011 #

  14. So I tried what you have written, but maybe I’ve typed something wrong, and now all the computer ever does is show a screen that says “MBR 1F”

    Doesn’t even boot off the CD, Is there a way to fix this?

    Comment by Tom — May 23, 2011 #

  15. @Tom: you need to choose the boot media in the bios. Often a text like “Press F12 for boot menu” is shown. this would be the key to press for you.

    Comment by robert — May 29, 2011 #

  16. if I could second comment #4. Thank you so much! I had almost given up hope with all of the mindnumbing alternatives

    Comment by Tom — June 9, 2011 #

  17. Thank you!!!

    Comment by Sam — June 23, 2011 #

  18. Hi, after trying solution 2 (sda = sda1) at reboot grub2 was still there and windows vista did not start anymore. I have kubuntu 11.04 and window vista installed.
    Could you pls help me?

    Comment by sempreelo — August 9, 2011 #

  19. Thank you, it is veeeery easy solution. I was reading this page few minutes ago in a browser loaded from Linux live USB, and now I’m writing from WinXP with repaired mbr as a result of following your instructions.

    Comment by Sasha — August 9, 2011 #

  20. @sempreelo: Than you most likely used the wrong device name. sda would be the mbr and sda1 the boot loader of the first partition and if the first partition is your windows partition you overwrote the wrong sectors.

    Comment by robert — August 15, 2011 #

  21. Awesome, thanks dude.

    Comment by matt — September 21, 2011 #

  22. Thanks a lot for this article.. very useful. Used solution#1 w/ ubuntu live cd..

    Comment by Trilok — September 22, 2011 #

  23. Will this remove the Grub from the MBR?? that is now only windows will come as a option to boot??

    Comment by Arjun — October 5, 2011 #

  24. It will remove Grub from the MBR and will install a MBR which boots the “active” partition. You can set the active partition in almost any partition manager, if Windows is not on the active one.

    Comment by robert — October 6, 2011 #

  25. Should probably put a warning and a better description to NOT overwrite your Windows boot drive.

    It destroys your install of windows rather than helps it.

    Find out what your drive is called (sda1) via GNOME
    aka GPartition (its on Ubuntu Live already) – and do NOT, DO NOT write to it. It destroys your windows and you have to do a full reinstall again.

    Thanks for the post and that, but should have more
    clarity tbf.

    Comment by Peter — October 29, 2011 #

  26. If you use a partition device file instead of a whole hard disk file you’ll write the master boot record into the partition … thats not good!! you will need to repair the file system after that, in most cases this should also work as only 512 bytes are over written (as the mbr is not bigger). But in this case you should really know what you do and than it would not happen in the first place …..

    Comment by robert — October 31, 2011 #

  27. Worked like a charm. I need to get my linux parttion back, though. Thank You, anyways!!

    Comment by anuz — November 9, 2011 #

  28. Didnt work on ubuntu 11.10. i had an internet connection but this is what i got.

    cannot locate package when i did sudo apt-get mbr.

    Comment by Taz — December 28, 2011 #

  29. did you an apt-get update before?

    The package is available:

    http://packages.ubuntu.com/oneiric/mbr

    Comment by robert — December 28, 2011 #

  30. Spent the past two hours trying to figure out how to make Windows boot instead of Linux through Grub. Thanks SO SO SO SO SO much for solving my problem!

    Comment by JReckitt — February 17, 2012 #

  31. [...] Källor: Tips 1 av Thameera | Tips 2 och 3 av Robert Penz [...]

    Pingback by Laga windows med Linux | OruVersum — February 23, 2012 #

  32. Wunderbar! You can use this to create a bootable flash drive from which to install MSW on a netbook.

    1. Start parted on the flash drive, create an msdos table, add a primary partition, and turn it’s boot flag on

    2. Format the partition with mkfs.ntfs -f

    3. Unpack the MSW iso and copy all files to the flash

    4. Run the install-mbr command (syslinux didn’t work for this particular task)

    5. Install MSW

    6. Wash your hands / do an enema

    7. Deliver the netbook to the ignorant fucker who refuses to learn Linux (in my case – me dad)

    Comment by Ted — April 17, 2012 #

  33. Win7 MBR was screwed up from an infection, nothing else would fix it, couldn’t even boot the pc into recovery mode. Solution 1 fixed it for me. (had to use sda3 for the partition that was goofy, pay attention to which sda# you need.)

    FANTASTIC fix. Saved me from trying to ferret out hundreds of files to back up before reinstalling Win7!

    Comment by Michael — June 4, 2012 #

  34. [...] some googling I used the dd command (it’s “1 solution” on this page) to (I think?) copy a clean file from syslinux’s backup stash to my laptop’s MBR on the [...]

    Pingback by WinMagic SecureDoc Whole-Disk Encryption (WDE) + Dual-Booting Windows 7 and Linux = Bad Things, Man « Darrin L Rogers — July 20, 2012 #

  35. Hi Mr. Robert I have executed the code with the wrong sda, it should be sda2.

    My windows 7 starts fine thanks for this guide but there an “MBR” text that shows for a few seconds then dissapears then the windows starts.

    I think this is the result of executing the code with the wrong sda..

    How would i remove the “MBR” text that appears before windows 7 starts?

    Comment by stray wolf — July 30, 2012 #

  36. Follow-up: I mean is it possible to delete created mbr to the wrong sda using ubuntu live cd?

    Comment by stray wolf — July 30, 2012 #

  37. I followed this how to in an attempt to fix my Windows XP machine after deleting an Ubuntu partition.

    I used the dd approach. The result is that I have traded an Error 22 for a Stop 24 BSOD.

    (Moral of the story: really know what you’re doing!)

    The interesting thing is: I can still boot from an Ubuntu Live CD and browse my “C:” drive. Data is not lost, Windows is just choking.

    At this point, trying to decide if I should use XP Recovery Console to “FIXBOOT” or if I should just copy off all my important files and reinstall an OS.

    Any thoughts appreciated.

    Comment by Noah — August 4, 2012 #

  38. This killed my boot entirely. I now have “Missing operating system” where I used to have GRUB

    Comment by Jacques — August 4, 2012 #

  39. work!!!!! big problem simple solution

    Comment by Szym — August 26, 2012 #

  40. Works like a charm, saved my day!! A Big Thanks :)

    Comment by Arun — August 27, 2012 #

  41. Best tutorial ever ! Thanx

    Comment by p3ace — August 31, 2012 #

  42. [...] http://robert.penz.name/221/mini-howto-restore-windows-mbrbootloader-with-linux/ [...]

    Pingback by Dual Boot Fedora and Windows | Open Ideas — September 30, 2012 #

  43. How do I repair a windows 7 x86, x64 ultimate ISO files MBR so I can install x64 again?

    Comment by Robert — October 5, 2012 #

  44. How do I repair a windows 7 x86, x64 ultimate ISO files MBR so I can install x64 again? all I have to use is PartedMagic. And Im installing the ISO to a USB 8gig Drive. Please help.

    Comment by Robert — October 5, 2012 #

  45. do you want to wipe the whole disk? if so type dd if=/dev/zero of=/dev/sda (or the device you want to wipe) and press CRTL-C after some seconds. This will overwrite the first blocks on the hard disk with zeros and will therefor look like a new disk.

    Comment by robert — October 5, 2012 #

  46. There was a working win7x64 on sda1 and working LMDE on sda4… now I got only “\windows\system32\winload.exe not found”. Fabulous tool :/

    Comment by A — December 29, 2012 #

  47. If there is a file missing on the file system it has nothing to do with the mbr .. you deleted some files ;-)

    Comment by robert — January 1, 2013 #

  48. Hi, thanks for the tutorial!
    Do I install the MBR to the NTFS partition that windows is installed on? Thanks.

    Comment by Kurt — January 20, 2013 #

  49. [...] looking for options to fix this, I found this site which suggested the following to restore the Windows [...]

    Pingback by Installed Lubuntu as dual boot to Windows 7 and now Windows won't load — February 5, 2013 #

  50. Great, works like a charm and ends a painful 2 hour search for a solution.

    Comment by Cor — March 17, 2013 #

  51. thankk you thank you … you are great genius

    Comment by mohan — March 26, 2013 #

  52. I will recommend it to all the ones who have a problem with this … great you are .. cant appreciate n words

    Comment by mohan — March 26, 2013 #

  53. An installed version of Linux you want to get rid of? Do your solutions damage Linux? (Will try them)

    Comment by Mike — May 2, 2013 #

  54. Please the commands seem not to work with my fedora, which command should I use for fedora?

    Thanks

    Comment by Cubby — May 16, 2013 #

  55. i mistakenly used sda1 instead of sda ….i am getting some different type of problem…how to undo what i did??

    Comment by shubham — May 24, 2013 #

  56. Great. It works!

    Comment by slwk — May 24, 2013 #

  57. Thank you :)

    Comment by Ken — June 19, 2013 #

  58. Solution 1 worked like a charm. Thank you!

    Comment by Dobly — June 23, 2013 #

  59. Thanks a lot. Just in case somebody’s as dumb as me: in BIOS, I first had to change diskmode back to AHCI (I had set it to compatibility mode…) – then it worked fine!

    Comment by Jaydot — July 16, 2013 #

  60. Thanks man, you just saved my day

    Comment by Rafael — July 25, 2013 #

  61. THANK YOU. I COULD KISS YOU SIR. After attempting to install 13.04 from an old usb stick you got my family’s laptop working again. I love you man.

    Comment by Will — August 21, 2013 #

  62. […] Ref: Mini-Howto: Restore Windows MBR/Bootloader with Linux | Robert Penz Blog […]

    Pingback by 復原 Windows MBR 的各種方式 « Jamyy's Weblog — September 13, 2013 #

  63. Software 1 was already on Wary Puppy Linux CD and the proposed solution did the trick in seconds…
    Thanks for sharing.

    Comment by Michel — October 14, 2013 #

  64. Dear Robert,

    You have given an excellent article. And I know how much useful it may be to a frustrated person trying to get their work done.

    But I sincerely request you to do one last job of giving them a last revealing information about alleged non friendliness of linux derivatives. I think at the moment when people are visiting your post they are frustrated and they vent their ire on linux without getting the other side of the story.

    Please consider my suggestions below:

    In response to your post, people have been wrongly complaining (in the comments) about the user unfriendliness of ubuntu and other linux variants etc in favour of Microsoft Windows. They think that after installing a linux variant they are unable to install the Microsoft’s Windows back, even after deleting all the partitions.

    This actually happens because as soon as a Microsoft Windows OS installer sees a non Microsoft bootloader (for example, GRUB), it refuses to install and says something like the environment is incorrect. Sadly further, it does not explain the ‘environment’ (which could allow a user may look up a solution). And neither does it provide there, a straightforward option to overwrite the other bootloader with its own (even if you delete all the partitions on the disk from the Windows Installer or from the outside!).

    I think the Windows implementers chose not to overwrite a foreign boot loader because they did not want to support a non Microsoft OS alongside their own. But the unfortunate thing is they should not do this when not even a single partition is allocated (then obviously there can be no OS installed).

    Please let the readers know that it is the Microsoft windows which does not support any non Microsoft OS sitting along side itself and not necessarily the other way round. Please put this information in the main post itself, since otherwise it gets buried under the volume of the comments.

    Comment by Helper (Anonymous) — November 15, 2013 #

  65. I’ve added the comment to the article.

    Comment by robert — November 15, 2013 #

  66. In following your instructions I rather mucked up by attempting to do it to a partition rather than a drive.

    I ran:
    sudo dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda1

    GParted is now unable to detect the file system of sda1.

    I would consult your Linux knowledge in how to reverse my muck-up.

    Thanks!

    Comment by Zig13 — January 1, 2014 #

  67. By using sda1 instead of sda you overwrote the first 512 byte of the partition. The fix depends on the file system you used on sda1. General information on that topic can be found at https://help.ubuntu.com/community/DataRecovery

    Comment by robert — January 2, 2014 #

  68. I thought this was THE fix I was looking for but I think I made a big mistake by executing these commands.

    Basically, my problem was that when I was installing Fedora on top of Windows XP. I accidentally or unknowingly shrink the windows partition as far as I can to make more space for Fedora Linux. That was a huge mistake. As a result, my window xp MBR is destroyed and XP is not listed as part of the grub bootloader. So, I was trying to recover Windows XP MBR. I tried other website work around. Still, didn’t work, even though it recognized Fedora partition. I came to your website and tried your commands. Now my desktop is completely dead. The only think that comes up is NO OS found, please insert CD/DVD or something like that. I am simply dumbfounded as to what to do now. I even tried Boot-Repair-Disk and it also didn’t fix my problem. I really don’t care for the Windows OS, it is the files I had in my windows partition I desperately want.

    I hope I didn’t destroy the files or the filesystem. I am still going to around the Internet for solution.

    Comment by David — February 11, 2014 #

  69. Awesome – thanks so much. It seems this is a pretty common problem. I installed Mint beside Windows and then, after I didn’t like it and decided to go for Ubuntu, I resized my Windows partition to take away Mint. Little did I know how important Grub2 was, that it had taken over booting sequence, and that by deleting it I had taken Windows out of commission! But your option 1 worked a charm. Many thanks!

    Comment by David W — May 2, 2014 #

  70. Thanks a million. All other guides said i needed a windows boot cd, this is perfect!

    Comment by Frederik — May 4, 2014 #

Leave a comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress
Entries and comments feeds. Valid XHTML and CSS. 24 queries. 0.177 seconds.