Repair a destroyed Windows 7 UEFI boot sector

I recently destroyed my Windows 7 UEFI boot sector by overwriting the corresponding EFI partition. This resulted in an error “Reboot and select proper boot device or insert boot media in selected”. This is how I fixed it (please be careful when dealing with partitioning and boot sectors, backup your data beforehand):

  1. Delete what is remaining of the Windows boot partition (not the Windows partition but the partition of around 128 MB size) and the EFI partition – you can use GParted for this. In the end, you should have at least 229 MB of free space on your hard drive – preferably at the beginning.
  2. Reboot from your Windows 7 DVD. Make sure you boot the UEFI part of the disk: When you open your boot menu by pressing F8, you will see two entries for your Windows 7 disk. One with “UEFI:” in front and one without. Select the former and then don’t forget to press any key if you are asked to – otherwise, the non-UEFI part would be booted.
  3. When Windows starts from the DVD, select the desired language and then press Shift+F10 to open the terminal.
  4. Now we will create the two missing partitions: the EFI boot sector and the Windows Boot sector. Type into the terminal (but leave the #… parts out – they are only comments by me):
    diskpart
    list disk
    select disk 0 #Select the desired disk
    create partition efi size=100
    list partition #Make sure that the 100mb partition is selected
    format quick fs=fat32 label="System"
    assign letter=B
    create partition msr size=128
    list partition #Check for errors
    list vol
    select vol 3 #Use the number corresponding to your windows installation
    assign letter=C
    exit
  5. Now copy the EFI files by typing:
    mkdir B:\EFI\Microsoft\Boot
    xcopy /s C:\Windows\Boot\EFI\*.* B:\EFI\Microsoft\Boot
  6. Now we will set the boot configuration data by typing:
    b:
    cd EFI\Microsoft\Boot
    bcdedit /createstore BCD
    bcdedit /store BCD  /create {bootmgr} /d “Windows Boot Manager”
    bcdedit /store BCD /create /d “Windows 7” /application osloader
    #This will return a GUID, referred to later as {guid}
    bcdedit /store BCD /set {bootmgr} default {guid}
    bcdedit /store BCD /set {bootmgr} path \EFI\Microsoft\Boot\bootmgfw.efi
    bcdedit /store BCD /set {bootmgr} displayorder {default}
    #Now it's not {bootmgr} anymore but {default}!
    bcdedit /store BCD /set {default} device partition=c:
    bcdedit /store BCD /set {default} osdevice partition=c:
    bcdedit /store BCD /set {default} path \Windows\System32\winload.efi
    bcdedit /store BCD /set {default} systemroot \Windows
    exit
  7. Restart. Additionally, I had two partitions with the boot flag which also caused trouble. I changed this with GParted.
  8. [Update] Configure the boot priority the UEFI menu so that the boot partition is the topmost.
  9. [Update] If you still have the problem that Windows is not booting automatically (i.e. the message “Reboot and select proper boot device or insert boot media in selected” is still displayed) but everything works fine when you open the boot menu and select the Windows bootloader yourself, this is the solution which worked for me:
    1. Power off the computer
    2. Unplug your hard drive
    3. Restart the computer, watch the booting fail and then power off again
    4. Replug your hard drive, restart and watch the booting succeed!


55 thoughts on “Repair a destroyed Windows 7 UEFI boot sector

    1. Tough problem. I only have experiences with the situation I wrote about and I hope you will find your solution.

  1. Thanks, finaly found a proper description to reconstruct a UEFI boot.
    Additional it is required to configure the boot settings/priority in the firmware,
    Many thanks.

  2. Thanks for posting this. Was extremely helpful! So hard to find clear, to-the-point doc but you sure came through! 🙂

  3. been able to solve my problem
    thank you
    i wish i have found this method earlier
    now i am not afraid of destroying efi partition

  4. Thank for tutorial. If I am installing Win 8.1 the line 5 in step 6 should be Windows 8.1 instead Windows 7? And I get error on line 7: The entry data is not valid as specified. The parameter is incorrect. but the next step is working. To me it looks like it can’t read the default. Any suggestions?

  5. i broke the partition again and here to fix one more time

    mascot did you replace {guid} part with the string of your drive printed in previous step

  6. Absolutely brililiant guide
    just few words

    1) as GARDAS mentioned : replace {guid} part with the string of your drive printed in previous step
    2) you dont have to unplug your disk
    3) make sure in BIOS is UEFI selected when you boot (unsecure preferably)
    4) Lastly after the whoel process boot from Windows 7 CD /select The REPAIR option / Cancel it / and on following screen () Systerm recovery options) choose STARTUP REPAIR
    5)remove CD and boot to system

  7. Philipp,

    Great, this did the job. I had to repair a computer with a dual SSD raid 0 setup with UEFI bios running Windows 7. It ran ok for a while, but the owner called last night that it wouldn’t start after it crashed while burning a dvd. The only thing it did was showing the bios message and restarted in a loop. Now it’s working like it allways did.

  8. Thanks a ton. I had a UEFI GPT disk I cloned with Acronis into a new SSD. It booted fine with the SSD as the main drive and the old drive as a slave… until I formatted the old drive to use as storage. I used Acronis “add a disk” tool in True Image to nuke all partitions on the old drive not thinking that the boot info was on that disk… I had the EFI and MSR partitions on the SSD from the clone operation but they wouldn’t work no matter what I tried… setting the right boot flags in gparted, running windows startup repair a half dozen times… tried the old fixboot and such but they are no good for this GPT setup…

    I used gparted to nuke the two totaling 229mb. Followed your instructions to a tee, booted into windows disc repair mode again and it detected startup issues and fixed them. BOOM back into windows!

    Thanks for the details that the internet is otherwise lacking. You sir, are a rock star.

  9. This is a wonderful tutorial. I am currently playing with a single disk tri-UEFI boot of Linux, Windows and OSX on my custom HTPC watercooled PC. Playing around with bootloaders and kexts, boot options etc. is nice but when I make a tweak and lose the ability to boot one or all OSes, this helped me get back into windows lickity split.

    I highly recommend everyone install Clover bootloader to have as a secondary bootloader. Shrink your final partition and make room, say 100MB for this incredibly useful loader; handles ALL OSes and I use it as my primary now. Though of course, this tutorial not only covers fixing the bootcode for your OS but also updates the bootcode in your PC’s UEFI firmware to boot said updated code as well so this is an invaluable guide for anyone!

    Well done and kudos. This handles pretty much any UEFI boot error you could face with Windows… now if you want to make one for Linux and OSX I’d be eternally grateful 😉

  10. Thanks a ton, did the job for me!!!

    After reading hours of other complicated guides, yours worked first up!

    Saved me a reformat!! Thanks again!

  11. Thanks a ton! I tried all sorts of automated repairs, but manually rebuilding the BCD was the only way I could build a valid EFI boot drive from my old MBR boot drive.

    You saved me a painful Windows reinstall on my media center computer! Thanks!

  12. Many many thanks for this Philipp!

    I was moving from a very old HDD (spin) to SSD, and was successful at doing it thanks to your help!

    One thing I noticed is that when booting, the Vista startup screen comes up very briefly (mainly also because the SSD is much faster and with more space/not fragmented). I followed the steps in [Fix] Windows 7 Boot Screen Changed to Vista Style which are to call: bcdedit /set {current} locale en-US, however, when I call that I get:
    The boot configuration data store could not be opened.
    The volume for a file has been externally altered so that the opened file is no longer valid.

    Any help on this is appreciated!

  13. This saved me a ton of work, thank you very much for posting! I had to restore a backup from Symantec System Recovery, but I was only able to backup/restore the main system partition (c:). This left me without an EFI partition and the Windows 7 repair was apparently unable to create a new one. I used the shell in the Windows 7 install utility to run diskpart. Your steps worked perfectly and I was able to boot my restored drive!

    Interesting side effect; the loading windows screen changed from the fancy multicolor windows logo, to the basic green progress bar. This must be a BCD setting, it wasn’t worth taking time to figure it out. 😉

    Thank you again!

    Matt

  14. Thank you so much. I recently used Rufus to format an SD card so I could load Windows 7 in EFI mode on my laptop and the darn thing wrote to my C: drive instead. Talk about a buggy program. . . The next time I rebooted my desktop computer it told me the .efi file was corrupt and Windows couldn’t load. I tried everything to fix it and was just about to pay for a piece of commercial software until I found your solution and, voila, it worked.

    Thank you a thousand times. The semester just started and I couldn’t afford to be without my main computer. 🙂

  15. unfortunately this did not work for me
    the problem is the system only works after fresh install and first restart, after that the system fails to close properly and when I try to reboot it it gets stuck in windows loading forever. Auto repair obviously does no good 🙁
    any ideas?

  16. Wow,

    All windows help (everything there, but we can’t understand, where to start and where to end; eg: diskpart flag offset, I really don’t know how to add GB offset) regarding bcdedit and bcdboot are confusing…for creating new EFI boot loader manually. This is so clear.

    Thank you!

  17. After installation of Windows 10 on a second hard drive, the old Windows 7 installation did not boot in secure mode anymore. The error message was, that the digital signature of \windows\system32\winload.efi could not be validated (0xc0000428). I tried several repair methods from about 10 articles starting with the repair options from the Windows DVD and the problem lasted some weeks (I was able to boot disabling secure boot) until I found YOUR great guidance!

    The only thing I did, was STEP 5 to copy the EFI boot files from the Windows installation to the EFI partition and the problem was solved in less than five minutes!

    Many Thanx!

  18. bcdedit /store BCD /set {bootmgr} default {guid}
    The entry data is not valid as specified.
    Run “bcdedit /?” for command line assistance.
    The parameter is incorrect.

    This command is not working for me… Can anyone help?

    1. Just bootrec /RebuildBcd and window do the rest of process.
      When appears the question “to add a Boot menu” just say “NO”

  19. Thanks for the article, saved me some time as well!

    @arn, replace {guid} with the string you got from running the previous command (something like: {3a768eea-cbda-4926-a82d-831cb89092aa}).

  20. Thank you so much! Works on Windows 10, just change “create partition efi” to “create partition primary” on step 4 line 4 above, if your drive isn’t GPT and diskpart can’t change it.
    Same for step 4 line 8.
    Well Done, saved me.

  21. This just saved my bacon – your write-up, as well as all the helpful comments. Just wanted to say thanks!

  22. Many many thanks buddy. I was trying to restore my crashed Windows 7 for three days until I found this article. You saved my life and the life of my PC!

  23. This man should be given an award of some kind.

    I was prepared to wipe my SSD and start over. That meant about 10hrs of reloading all my specialty software and ruining my weekend. Not to mention hoping against hope my last backup to the NAS included the latest versions of my work. Did this and was back in business in less than an hour.

    Thank you!

    PS: the only hitch was I used a “free” partition software that didn’t actually apply my changes until I purchased the $40 software. I didn’t notice this and ended up creating 2 boot sectors which cost me about 2hrs of frustration. No one’s fault but my own, but be aware.

  24. Amazing, this actually worked. I never even heard of bcdedit before today and now I have used it correctly, first time. Hooray!

  25. I also had a screwed boot partition and after hours of checking the web and trying out tutorials, I was finally able to get my windows booting like a charm again with the great help of this tutorial.

    But I had one major problem with this tutorial: I have completed every step until that point where you need to use the bcedit command. The dos prompt told me that there is no such file or command. I have every step correctly, but there was simply no bcedit neither in EFI\Microsoft\Boot or anywhere else to find. Then I got stuck 🙁

    But here comes the solution: Just type bootrec /RebuildBcd and let it check for your windows installation. It should find all your windows installations and you can choose then for each installation you have if you want to add it into the windows boot loader.
    This only really works if you perform the complete tutorial until the bcedit command. I have tried it without as well before, but only deleting the old partitions and recreating including copying the EFI files did the trick in combination with bootrec /RebuildBcd 🙂

    I hope this helps someone else as well, good luck!

  26. Mr. Hasper, thanks a lot for this blog entry. You are a true philanthropist. Very helpful work here. This

    > One without “UEFI:” in front and one without.
    The first “without” should only say “with”.

    Cheers

  27. Hi,

    Thank you so much. I had to waste entire sunday repairing my windows drive (/dev/sda) . I had 2 more hard drives(/dev/sdb & /dev/sdc) with linux fedora, i was trying to clone fedora to larger drive and some how it blew up windows.

    After following your instructions – I’m able to repair windows. Honestly I did not think it will work as it is Windows!!. After it worked like a magic.

    Thank you

  28. 1) as GARDAS mentioned : replace {guid} part with the string of your drive printed in previous step

    can someone tell us what {guid} should be replaced with exactly

    is it this d “Windows Boot Manager” or this d “Windows 7”

  29. Section 6/8 returns a ‘Store parameter not valid’ message.
    Checked the line again and again but can’t see a typo.

  30. Thank you, thank you, thank you! I was able to boot into Windows 10 computer using some of the instructions on this page. I didn’t have to change any partitions. I first named 100 MB system drive to B:. Then, I just overwrote all the existing EFI files on B: drive and did all the instructions in step 6 (bcdedit) and rebooted the computer and Windows came up. I changed “Windows 7” to “Windows 10” in step 6.5, but that was probably not necessary.

Leave a Reply

Your comment will be moderated.

seven × = 49