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.

90 Comments »

RSS feed for comments on this post. TrackBack URI

  1. thankk you thank you … you are great genius

    Comment by mohan — March 26, 2013 #

  2. 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 #

  3. 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 #

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

    Thanks

    Comment by Cubby — May 16, 2013 #

  5. 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 #

  6. Great. It works!

    Comment by slwk — May 24, 2013 #

  7. Thank you 🙂

    Comment by Ken — June 19, 2013 #

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

    Comment by Dobly — June 23, 2013 #

  9. 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 #

  10. Thanks man, you just saved my day

    Comment by Rafael — July 25, 2013 #

  11. 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 #

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

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

  13. 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 #

  14. 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 #

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

    Comment by robert — November 15, 2013 #

  16. 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 #

  17. 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 #

  18. 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 #

  19. 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 #

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

    Comment by Frederik — May 4, 2014 #

  21. dude you are a genius!!!

    Comment by Raul — August 2, 2014 #

  22. I have a Lenovo Y50-70 Laptop with Windows 8.1 pre-installed. Two days ago it stopped booting into windows. There is a boot partition of SYSTEM_DRV with boot flag but it doesn’t detect anything in the BIOS. Before this problem the partition was listed in the BIOS now it’s not. I tried boot-repair too but it didn’t work. What to do so BIOS detects the partition & boots? Also i checked using TestDisk that the boot sector is with status Ok. Please help.

    Comment by Tanmay — December 16, 2014 #

  23. Thank you very much.

    Comment by Vasanth — January 7, 2015 #

  24. That was awesome Robert. Thanks. I was all out of options. Didnt think overwriting MBR of a syslinux bin would solve it, but it did!

    Comment by Ben — March 7, 2015 #

  25. […] Info habe ich von http://robert.penz.name/221/mini-howto-restore-windows-mbrbootloader-with-linux/ etwas abgeändert für […]

    Pingback by wie ich einen kaputten GRUB2 Bootloader repariert habe – a linux addict in a linux world — March 22, 2015 #

  26. Hi all,

    I have troubles to boot the win7. I have downloaded kubuntu liveCD that is booted like a flower and after I have followed the instructions:

    1) sudo apt-get install mbr

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

    3) reboot

    However, I obtained message after booting

    MBR
    bootmgr is missing press ctrl+alt+del

    What I have to do ?

    thx.

    Comment by Desesperate — May 2, 2015 #

  27. boot manager is not the mbr. you need to run the recovery function of the windows install cd.

    Comment by robert — May 3, 2015 #

  28. THANK YOU

    Comment by Stefan — June 8, 2015 #

  29. Would’ve been so wrong to just use ur solution and leave without thanking u. So, thanks a million, man. U save my ass.

    Comment by Issam Kenzi — September 12, 2015 #

  30. Great !!!

    Comment by François — October 10, 2015 #

  31. A wonderful tutorial.

    My windows installation disc is refusing to restore the windows boot loader while using the same disc used to install the system.

    “We cannot repair your windows install it is incompatible with this setup disc”

    Stupid brain dead POS.

    Well anyway thanks for the tutorial, helps a lot on restoring the boot loader to my Windows gaming drive. 🙂

    I keep my Linux install on a separate partition, so my dual boot setup still leaves the windows boot loader intact on its drive, but I accidentally nuked it.

    Comment by Dreyeth — October 21, 2015 #

  32. Worked for me.

    Comment by Brian Kevin Calmes — May 11, 2017 #

  33. Thanks a lot for this Robert. I was stuck on grub rescue and didn’t have a window live boot cd but this solved my problem.

    Comment by Oshal — May 25, 2017 #

  34. Very useful. One note: on the CloneZilla live CD I was using the mbr.bin was located in a slightly different path.

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

    Comment by Tim — July 12, 2017 #

  35. Thank you very much for this, I used a UBUNTU USB stick to reboot my Windows10 Laptop.

    Did not need to install syslinux as this was already installed, also the directory containing mbr.bin was in SYSLINUX rather than syslinux so just needed to run this command

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

    Comment by Peter — September 23, 2017 #

  36. Thank you so much.:)

    Comment by Andreas — January 21, 2018 #

  37. Well, I have the blinking cursor problem after having : – cloned xp from a compag slimsomething desktop on an SSD drive ( on the first partition of course ) … i then installed Ubuntu, and… same for Windows after grub2… i’ve tried your first solution, and i wanted to tell that for me the correct path to mbr.bin wasn’t in /usr/lib/syslinux/ but in ../syslinux/mbr/
    i was wondering what if i wouldn’t have checked before and just lauchned the command line as a noob who just su last command line to download and install syslinux and mtool… ? no boot and no boot loader… what a joke… but nice anyway…
    well, … rebooting.. ( Q9550 ) … not okay, as i expected, no bootloader at all, no menu, just the blinking cursor… pretty funny

    Comment by StonyCat — May 11, 2019 #

  38. Thank you so much! I was unable to boot from my Win-CD (no ps/2-keyboard). Now I could restore the MBR! Great!

    Comment by armin — October 7, 2019 #

  39. A jewel among the tutorials. It simpili-
    fies a problem, that can make your whole
    system not usable. It works for linux and
    windows.

    Comment by dudu — December 10, 2020 #

  40. Thanks a lot!

    Note: In my case, the mbr.bin file is inside a mbr directory so the correct command for my system is:

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

    You can direct this hint if you want in your main post to others with the same situation..

    Comment by MBR — October 17, 2021 #

Leave a comment

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

Powered by WordPress
Entries and comments feeds. Valid XHTML and CSS. 37 queries. 0.067 seconds.