Partager via


Boot to VHD / Boot from VHD

I recently learned about boot to/from Virtual Hard Disk (VHD) and how it makes it very easy to set up and manage multiple system configurations. After having my Windows 7 configuration get completely messed up and being really lazy about creating clean OS images, I figured I would give the VHD route a try and discovered it's much easier than I expected - if you can create an image in Virtual PC, you can change it to be bootable. The gist of how it works is you create a virtual image for use within a VHD (I used Hyper-V from Server R2) and then you use bcdedit (the Windows boot manager, BCD stands for Boot Configuration Data) to copy an existing entry and point that entry to the VHD file.

Here are the steps I took with some details where things get a little tricky:

First, I installed Windows Server 2008 R2.

Next, I opened Server Manager and added/enabled the Hyper-V role.

Next, I opened the Hyper-V manager and added a new Virtual Machine (VM).

I installed Windows 7 in the VM.

After the VM was set up, I shut it down and copied the virtual machine file [Win7.vhd] from the default folder [C:\ProgramData\Microsoft\Windows\Hyper-V\] to a new folder named  to [c:\VHDs\Win7.vhd].

Finally, I opened an administrator command prompt and modified my boot configuration.

To modify my boot configuration, I needed to use bcdedit to add a virtual hard disk to the boot menu.  All I did was run the following commands:

 C:\>bcdedit /copy {current} /d "Windows Server 2008 R2-Boot from VHD"

This returned a GUID, I copied that GUID and ran the following commands with the GUID set:

 bcdedit /set {newguid} device vhd=[locate]\VHDs\Win7.vhd
 bcdedit /set {newguid} osdevice vhd=[locate]\VHDs\Win7.vhd
 bcdedit /set {newguid} detecthal on

And that was it.  When I rebooted my machine, I had a new option "Windows Server 2008 R2-Boot from VHD". And I had a full booted version of Windows 7 that I could conveniently manage and use. After I got everything set up the way I like it, I made sure to create a backup of the VHD file that I can use to boot into a freshly installed and set up instance of Windows.  This is extremely convenient for me because I frequently need a full sandbox for running and testing programs without worrying about messing up my main setup.

There were tons of blog posts that I read over the past year that inspired me to do this, many which describe the process with gotchas and more details than I provide.  I'll try and reference the ones I used. If you work in an environment where you need to run multiple OSes, boot to VHD is a much more robust option than dual booting, lets you easily manage and run your images from Virtual PC or Hyper-V,  and makes backups super easy.  I strongly recommend this option!

See Also