Monday, October 31, 2011

Creating BCD from scratch with BCDedit.exe and add "Repair my computer" WinRE Recovery Environment

My Boot Configuration Data (BCD Store) for my Windows 7 got hosed and I had to delete it and boot off a Windows DVD, hit Shift + F10 to get at a command prompt, delete my old BCD and run Bootrec.exe /rebuildBCD to even be able to boot my system. But RebuildBCD left the file with the bare minimum necessary to boot, nearly blank, and I lost the option to run "Repair My Computer" from the F8 screen. I found a useful website: http://forum.acronis.com/forum/6758 that helped me get back on the right track, but I had to dabble around myself to get all the settings that Windows 7 Installation would normally handle. Follow these instructions to restore your BCD file so that you can run "Repair" off the hard drive instead of digging around for a DVD. "bcdedit /enum all" lists your BCD config and "bcdedit /enum all /v" lists all GUIDs instead of friendlynames. the GUID's I have listed ARE different (make sure you check the 8th digit). Before you begin you might want to do "bcdedit /export C:\before.BCD".

  • 1. Create necessary optional entries

bcdedit /create {globalsettings}
bcdedit /create {bootloadersettings}
bcdedit /create {resumeloadersettings}
bcdedit /create {emssettings}
bcdedit /create {dbgsettings}
bcdedit /create {hypervisorsettings}
bcdedit /create {badmemory}
bcdedit /create {memdiag}
  • 2. Establish proper settings for these optional entries
bcdedit /set {bootmgr} INHERIT {globalsettings}
bcdedit /set {current} INHERIT {bootloadersettings}
bcdedit /set {globalsettings} INHERIT {dbgsettings} {emssettings} {badmemory}
bcdedit /set {bootloadersettings} INHERIT {globalsettings} {hypervisorsettings}
bcdedit /set {resumeloadersettings} INHERIT {globalsettings}
bcdedit /set {emssettings} bootems YES
bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200
bcdedit /hypervisorsettings SERIAL DEBUGPORT:1 BAUDRATE:115200
bcdedit /toolsdisplayorder {memdiag}

bcdedit /set {memdiag} description "Windows Memory Diagnostic"
bcdedit /set {memdiag} device partition=\Device\HarddiskVolume1
bcdedit /set {memdiag} path \boot\memtest.exe
bcdedit /set {memdiag} locale en-US
bcdedit /set {memdiag} inherit {globalsettings}
bcdedit /set {memdiag} badmemoryaccess Yes

  • 3. Link "Windows Boot Manager" and primary "Windows Boot Loader" to your existing "Resume from Hibernate" identifier (replace the GUID)
bcdedit /set {bootmgr} resumeobject {8de128fe-03a5-11e1-a7d3-a215a48a5459}
bcdedit /set {current} resumeobject {8de128fe-03a5-11e1-a7d3-a215a48a5459}

  • 4. Create loader entry for the "Recovery"(Repair My Computer)
  • Check C:\Recovery\ (gain access by adding "Users" READ permission)
  • Copy & Use that GUID here for device and osdevice - in my case 8de128ff-............ omitting the curly braces { } after [C:]\Recovery
  • On Line 2 and Line 3, for device and OSdevice, the final GUID after \Winre.wim doesnt exist yet (if you look carefully the 8th digit is changed - and will now have to be created .... 
  •  after \Winre.wim, create a NEW UNUSED GUID (change the 8th digit) - it will be used in step 6.
bcdedit /create {8de128ff-03a5-11e1-a7d3-a215a48a5459} /application osloader
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} device ramdisk=[C:]\Recovery\8de128ff-03a5-11e1-a7d3-a215a48a5459\Winre.wim,{8de128f5-03a5-11e1-a7d3-a215a48a5459}
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} osdevice ramdisk=[C:]\Recovery\8de128ff-03a5-11e1-a7d3-a215a48a5459\Winre.wim,{8de128f5-03a5-11e1-a7d3-a215a48a5459}
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} path \windows\system32\winload.exe
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} description "Windows Recovery Environment WinRE"
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} inherit {bootloadersettings}
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} systemroot \windows
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} nx OptIn
bcdedit /set {8de128ff-03a5-11e1-a7d3-a215a48a5459} winpe yes

  • 5. Enable the {current} OS to allow the Recovery Sequence you just created
bcdedit /set {current} recoverysequence {8de128ff-03a5-11e1-a7d3-a215a48a5459}
bcdedit /set {current} recoveryenabled Yes
  • 6. With that NEW UNUSED GUID you just created in step 4, create the "Ramdisk Options" entry for the Recovery Sequence
  • On Line 4, after \Recovery\ - use the GUID you found in C:\Recovery\ -again Omit the Curly braces { } 
bcdedit /create {8de128f5-03a5-11e1-a7d3-a215a48a5459} /device
bcdedit /set {8de128f5-03a5-11e1-a7d3-a215a48a5459} description "Ramdisk Options"
bcdedit /set {8de128f5-03a5-11e1-a7d3-a215a48a5459} ramdisksdidevice partition=C:
bcdedit /set {8de128f5-03a5-11e1-a7d3-a215a48a5459} ramdisksdipath \Recovery\8de128ff-03a5-11e1-a7d3-a215a48a5459\boot.sdi

Now you are done, and might want to export again to not lose your work, "bcdedit /export C:\AFTER.BCD"

5 comments:

Unknown said...

As I said on g+, nothing like some saved free time! Thank you, mate, for spending that free time (and learning all of that) and sharing with us!

After I moved my Windows installation, everything was really okay, except Startup Repair. And now I got it back and working. Thank you very much!

Diamanti said...

In UEFI not work for me also changing winload.efi. Freze in loading...

Corhsin said...

Saved me a ton of time and frustration, thank you.

Gleep said...

Excellent write-up. Thanks for putting in the effort to publish your work. Thanks mate.

Aditi Gupta said...

Good Post! it was so good to read and useful to improve my knowledge as an updated one, keep blogging. Golden Triangle Tour Package