Share via


How to boot from a VHD with Windows 7

One of the new functionalities of Windows 7 and Windows Server 2008 R2 is that you can boot directly from a VHD file.

Next to that you will also be able to natively create and mount VHD files using either the diskpart command or the Diskmanagement mmc console.

In this post I”ll explain to you how I created my VHD file, deployed an OS onto and added as a boot device. The OS we are going to deploy is my Windows 7 demo machine. I like the fact that I now have a multiboot machine without the need for local installations. So my default boot device is just my normal production installation and my second boot device is my VHD file.

 

Let’s start with creating the VHD file. First open the Computer Management MMC and right click onto Disk Management

image

You will se that there is now the option to create or attach (mount) a VHD file. In our case we will create the VHD file.

image

Here you have the choice between a dynamically expanding disk which allows you to start with less disk space allocated comparing to a fixed size disk. However this comes at a cost, which is a slight performance impact.

 

For my demo machine i decided to create a fixed disk of 25GB called W7Demo.vhd, know that you will need at least 25GB of free space on your physical disk. The fixed size disk takes the defined amount of disk space even if you don’t use it within the VHD file. This takes a while to create.

Once the VHD file is created the system will mount it as a drive and you need to initialize it and finally create a partition onto the disk.

image

When this step if finished you will see that you have an additional disk into your system that you can use to write data onto it.

My goal now is to get an OS deployed onto the VHD file. This is actually a quite simple process:

 

First you take either a Windows DVD or an existing WIM file. In my case I had a WIM file that was used to deploy Windows 7 demo machines. The WIM file included the W7 OS install and all Office application I needed for my demo machine. Now you use the tool called ImageX which you can find onto the  “Windows Automated Installation Kit” (WAIK).

 

Open a command prompt with Administrative rights and type the following command to deploy the image:

imagex /apply d:\mywim.wim 1 f:\

 

D:\mywim.wim is my WIM file that I want apply.

F:\ is my mounted VHD file.

 

Now that our OS is deployed we need to add the VHD as a boot device.

 

Bcdedit.exe /copy {current} /d “Description”

Note: Returns a GUID that you’ll use to replace ‘GUID’ below

Bcdedit.exe /set GUID device vhd=[locate]\<dir>\<fname>

Bcdedit.exe /set GUID osdevice vhd=[locate]\<dir>\<fname>

Bcdedit /set GUID detecthal on

 

Now just reboot your system and you will be able to select the VHD entry we just made and boot from the VHD file. You will notice that you have access to all HW resources and that the only the disk is loaded through a Virtual Disk Service. Just to be clear this has nothing to do with Virtualization as we are running the OS directly onto the physical box and not from a virtualization platform.

 

Make sure that the VHD or WIM you deploy is a Sysprepped one which will remove all HW specific information. For more information about sysprep visit How sysprep works ? and What is Sysprep ?

 

Technorati Tags: Windows 7,Windows Server 2998 R2,VHD