Wednesday, January 18, 2012

Fix bcd the elegant way

Oh well, I messed up the bcd and the Win 7 installation CD didn't find the OS installed. Then I tried bootrec /rebuildbcd, which found one out of two installed OS, but it couldn't continue and complained that bcd is being used by another process.


bootrec.exe /fixmbr bootsect.exe /nt60 all /force
cd C:\boot
attrib -h -s BCD del BCD
bcdedit /createstore bcd.temp bcdedit.exe /store bcd.temp /create {bootmgr} /d "Windows Boot Manager" bcdedit.exe /import bcd.temp bcdedit.exe /set {bootmgr} device partition=C: bcdedit.exe /timeout 10 attrib -h -s bcd.temp del bcd.temp
bcdedit.exe /create /d "Microsoft Windows" /application osloader
bcdedit.exe should return a message with a GUID for the newly-created entry, something like this:
The entry {c0dfc4fa-cb21-11dc-81bf-005056c00008} was successfully created.

Then use this number/entry and type 

bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} device partition=C: bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} osdevice partition=C: bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} path \Windows\system32\winload.exe bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} systemroot \Windows
bcdedit.exe /displayorder {c0dfc4fa-cb21-11dc-81bf-005056c00008}

In my case the XP is on C: and Win 7 on E:. However, the winload.exe is missing in the XP partition(?), so I had to try a second time and set all the "C:" above to "E:" which solved the problem.

Another thought: Maybe I should have changed the attribute of the bcd file and tried /rebuildbcd? Anyway, the problem is now fixed.

Updated: A similar but more complete guide was found on http://idoneitmyself.wordpress.com/2009/11/15/windows-7-suddenly-wont-boot-reboot-and-select-proper-boot-device-or-insert-boot-media-in-selected-boot-device-and-press-any-key-repairing-the-windows-7-bootloader/