Windows 7 Boot from VHD

Boot from VHD

 One of my favorite new capabilities in Windows 7 (and Windows Server 2008 R2) is the ability to boot from a virtual hard disk (vhd).  This allows me to develop a Windows 7 image without needing a separate machine.   Because the image is in a vhd format I can then convert it into whatever format I need.

There are a couple of pre-requisites that need to be in place before using Boot from VHD.

  1. The host needs to be either Windows 7 or Windows Server 2008 R2.
  2. The vhd needs to be either Windows 7 or Windows Server 2008 R2.
  3. The vhd needs to be the Hyper-V version NOT Virtual Server 2005 or Virtual PC 2007.

 Depending on the method used to create the vhd, you may need some knowledge of the Boot Configuration Data (BCD) command line tools to edit the boot to recognize the vhd. 

To start you will need to have a vhd that is an installed or sysprep version of Windows 7/Windows Server 2008 R2.  There are many different websites that show how to create this vhd for use in a Boot from VHD. 

Note: After a couple of failed attempts at creating the vhd, I discovered that the vhd’s internal size could not be larger than what is still available on the host disk.  For instance, I had used a standard vhd configuration of 127 GB for vhd hard drive space.  The host drive (C:) only had 80GB of space left.  This dictated that my vhd internal drive space was 40GB.

After creating the vhd, follow these steps:

  1. Place the vhd on the desired location and within a folder that allows you to easily discern its purpose, for example C:\VHD\Win7.vhd.
  2. Open up a Command Prompt in Windows 7 or Windows Server 2008 R2.  Make sure to Run as Administrator if you’re on Windows 7.
  3. At the command prompt type: bcdedit /copy {current} /d “Windows 7 VHD”.

Note: This created a GUID that is attached to Windows 7 vhd.  This will be used in successive steps.  Windows 7 VHD is an arbitrary name for this demo.  This is what will show up in the Windows Boot Manager list on start-up.

     4. Continue typing: bcdedit /set <GUID from the copy command> device vhd=[C:]\VHD\Win7.vhd

     5. Next, add: bcdedit /set <GUID from the copy command> osdevice vhd=[C:]\VHD\Win7.vhd

Note:  This now associates the GUID with the physical location of the VHD file. 

     6.  Finally type: bcdedit /set <GUID from the copy command> detecthal on

Note:   This last step allows the vhd to access the physical computer.  This includes the processor and any advanced virtualization technology embedded, any USB drives, or even any other physical hard drives on the computer.

     7.  To ensure that everything is correct, then type in bcdedit /v and the all of the individual Boot Loaders should be available.   Below is an example of a vhd currently set up on my computer for a Windows Server 2008 R2 vhd I use to create Hyper-V images.  This is typical of what will be displayed when completing the BCD editing for a Boot from VHD.

Example of BCD entry for Boot from VHD

     8.  Close out of command prompt.  Restart the Windows 7 computer and choose Windows 7 VHD (or whatever name you chose in Step 3) to start into the vhd environment.

 On yeah, and if you ever need to clean up after a vhd is not needed, then:

  1. Open up a command prompt and use the bcdedit /v to discover the GUID.
  2. Type: bcdedit /delete <GUID of the vhd image> /cleanup

 This should clean up the BCD entry and all that is needed to finish is to delete the vhd from the host system.  Good luck and have some fun.

Advertisements

3 thoughts on “Windows 7 Boot from VHD

  1. talesfromitside says:

    I want to thank Jeremy Chapman from the Windows 7 product team on correcting me about some of the pre-requisites for Boot from VHD. The post now reflects that you do not need VT on the processor to do Boot from VHD. Thanks Jeremy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s