Feb 102009
 

I have installed Windows 7 to VHD (Virtual Disk) file a while back now. I did like it, so I killed Vista and decided to install Windows 7 on my primary partition also. During installation of it, I formatted boot partition. Unfortunately, that also killed any possibility to boot into Windows 7 system within virtual disk file.

In order to boot from this disk image, some play with bcdedit is needed (in elevated prompt). First we need to discover identifier of our original installation (marked red in following text). Once we have it, we can make a copy and perform all further editing on newly created entry (marked blue). Then we set device and osdevice settings. With that step, we are ready for booting. Here are exact commands that worked for me:

C:\bcdedit /v
...
Windows Boot Loader
-------------------
identifier       {2fae45a6-f1ca-11dd-bde6-c5438ada3082}
device           partition=C:
path             \Windows\system32\winload.exe
description      Windows 7
locale           en-US
inherit          {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {2fae45a7-f1ca-11dd-bde6-c5438ada3082}
recoveryenabled  Yes
osdevice         partition=C:
systemroot       \Windows
resumeobject     {2fae45a5-f1ca-11dd-bde6-c5438ada3082}
nx               OptIn


C:\bcdedit /copy "{original_id}" /d "Windows 7 VHD"
The entry was successfully copied to {2fae45a9-f1ca-11dd-bde6-c5438ada3082}.

C:\bcdedit /set "{new_id}" device "vhd=[D:]\Virtual Machines\Native\Windows7.vhd"
The operation completed successfully.

C:\bcdedit /set "{new_id}" osdevice "vhd=[D:]\Virtual Machines\Native\Windows7.vhd"
The operation completed successfully.

C:\bcdedit /v
...
Windows Boot Loader
-------------------
identifier       {2fae45a9-f1ca-11dd-bde6-c5438ada3082}
device           vhd=[D:]\Virtual Machines\Native\Windows7.vhd,locate=custom:12000002
path             \Windows\system32\winload.exe
description      Windows 7 VHD
locale           en-US
inherit          {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {2fae45a7-f1ca-11dd-bde6-c5438ada3082}
recoveryenabled  Yes
osdevice         vhd=[D:]\Virtual Machines\Native\Windows7.vhd,locate=custom:22000002
systemroot       \Windows
resumeobject     {2fae45a5-f1ca-11dd-bde6-c5438ada3082}
nx               OptIn

If you moved image from another system and you with to boot from it, you may also need to turn on HAL detection:

C:\bcdedit /set "{new_id}" detecthal on
The operation completed successfully.

At this point, there is nothing more to do. You may restart and boot into your favorite VHD.

[2009-05-17: Adjusted bcdedit commands so they work both in cmd.exe and in PowerShell]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>