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
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.
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.
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
Comments
Anonymous
January 28, 2009
ok I'm stumped, is this vhd thats the result of using ntbackup that now creates a vhd file or can you take a vhd from a hyper-v system and run it also? thanks trAnonymous
May 18, 2009
I’m loving the new Windows version, I’ve been using it on my work and my demo computers since the releaseAnonymous
February 20, 2010
I would like to start the machine in HDV, only the VHD already have Windows installed. That is, only need to include. VHD in BCD. Know how to do this?