Windows 7: Boot from VHD First Impression: Part 2

Windows 7: Boot from VHD First Impression: Part 2

  • Comments 65
  • Likes


In my previous post i.e. Windows 7: Boot from VHD First Impression: Part 1 we seen creating and attaching the VHDs. Using the Disk Management or Diskpart utility we can attach the existing VHDs. In this part we will actually cover the boot from VHD feature.

We will cover the different ways by which we can actually boot from VHD file. In order to boot from VHD, the bootloader needs to support boot from VHD file. So, what are the basic benefits of having VHD Booting.

You can use Boot for VHD feature in your test environment or development where you want to try out different applications or devices, which is not possible in Virtual Environment.

Booting from VHDs means booting the machine as if running from primary hard disk so your operating system will leverage all the hardware available in your system like Graphics, Wireless, USB etc. which is not possible in most of the virtual environment.

This is good for multi-boot environment where you want to run multiple operating systems on same machine without losing the performance. This is possible by VHD booting. As every VHD is like a Hard disk with primary partition; so you can create multiple VHDs with operating systems installed onto it.

In this discussion we will cover the following key points.

  • Booting a Windows 7 VHD or Windows Server 7 (aka Windows Server 2008 R2) VHD
  • Preparing VHD file using Windows 7 or Windows Server 7 Media or existing VHD running Hyper-V
  • Adding the VHD entry in Boot Menu for VHD Boot and then Boot from VHD


Booting a Windows 7 VHD or Windows Server 7 (aka Windows Server 2008 R2) VHD

This feature is only supported by the Windows 7 client VHD and Windows Server 7 aka Windows Server 2008 R2 VHD.

In order to boot from VHD we need to prepare the VHDs using any of the two methods.

  1. The first method is obtaining the existing Windows 7 or Windows Server 7 DVD VHD and make sure it is sysprepped to clear all the hardware information. So why sysprep ?

    Benefits of Sysprep

    Sysprep provides the following benefits:

    • Removes system-specific data from Windows. Sysprep can remove all system-specific information from an installed Windows image, including the computer security identifier (SID). The Windows installation can then be captured and installed throughout an organization.
    • Configures Windows to boot to Audit mode. Audit mode enables you to install third-party applications and device drivers, as well as to test the functionality of the computer.
    • Configures Windows to boot to Windows Welcome. Configures a Windows installation to boot to Windows Welcome the next time the computer starts. In general, you configure a system to boot to Windows Welcome immediately before delivering the computer to a customer.
    • Resets Windows Product Activation. Sysprep can reset Windows Product Activation up to three times.

    For more information about sysprep visit How sysprep works ? and What is Sysprep ? that will give you clear idea about sysprepping a system.

  2. Applying a WIM Image directly to the VHD file using ImageX utility. The ImageX utility can be used to extract the required operating system edition directly to the attached VHD file in Windows 7

The ImageX utility is part of WAIK. i.e. Windows Automated Installation Kit. You can download the WAIK for Windows 7 from here

Preparing VHD file using Windows 7 or Windows Server 7 Media or existing VHD running in Hyper-V


From my previous post create a new VHD and attach it using Disk Management. Now, you will have newly attached X: created with label 'Windows7', which is of size 20 GB.

Now, you will require the 'install.wim' file from the Windows 7 Media or Windows Server 7 Media. Along with that we will require ImageX utility.

In order to extract image to the X: we will use the following syntax.



d:\imagex>imagex /apply d:\install.wim 1 x:\

In the above syntax we can see we have used 'd:\install.wim' followed by '1' and 'X:\' (this is the attached VHD.)  Now this 1 denotes Image Index i.e. edition of the Operating System.

As you can see I have used the 'install.wim' file from the Media of Windows Server 7 Beta and 1 denotes Enterprise Edition.

In order to check the Image Index we will use the following command

d:\imagex>imagex /info "d:\Download\Windows Server 7 R2\install.wim" (i.e. the location of the install.wim file)


Once finished the extracting the OS using ImageX it will look like this


Once the image is applied to particular drive in our case X:\. Detach the X: Drive from the Disk Management. Now your VHD file is ready to boot.


Preparing the VHD file using Windows Server 2008 Hyper-V

If you have Windows Server 2008 running Hyper-V, launch the virtual machine running Windows 7 or Windows Server 7 aka Windows Server 2008 R2 and the run the following command

c:\windows\system32\sysprep>sysprep /generalize /shutdown


After running the above command in the virtual machine, this will launch the System Preparation Tool 3.14. Select the checkbox for 'Generalize' and click on OK.

Once the sysprep is completed the virtual machine will be shutdown and ready for booting. You can copy that VHD now.

Note: Sysprep does not work on upgrade. You need to have Clean Installed Windows 7


Adding the VHD Entry in Boot Menu and then Boot from VHD

Now that we have successfully created VHD files. The last step is adding boot entry for the VHD file in your Windows 7 or Windows Server 7 using BCDEdit.exe tool.

For this step open the Elevated Command Prompt with Administrator Privileges and type the following commands.

C:\>bcdedit /copy {current} /d "My New VHD Description"

Note: This will Return the GUID of the Loader Object that you will use to replace <guid> below
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>

Note: vhd=[driveletter:]\<directory>\<vhd filename> is the new syntax supported for BCDEdit.exe to locate VHD File and Bootmgr will locate the partition containing the VHD File to boot from.
C:\>bcdedit /set <guid> detecthal on


Following is the attached screenshot of the my machine. In this case I have Windows 7 as the default OS and I have added the VHD File in the Boot Entry.


Well just after that run the following command to test if your boot entry is successfully created using C:\>bcdedit /v



Similarly, if you want to add multiple VHDs into Boot entry you can use the following lines to the command prompt

C:\>bcdedit /copy {current} /d "New VHD Description"
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> detecthal on

Note:  detecthal is used to force windows to auto detect the Hardware Abstraction Layer.

If you want to delete any existing VHD entry from the Boot Menu you can always use the command C:\>bcdedit /delete <guid> /cleanup This deletes the specified operating system entry from the store and removes the entry from the display order.

Well, we are ready to Boot from VHD. Once you restart the computer you will see additional entry in Boot Menu along with the default Windows 7 or Windows Server 7 OS.

Here is the screenshot from newly booted Windows Server 2008 R2 Beta from VHD. I have installed Desktop Experience Pack and enabled Aero Glass.

win 7 server

Happy Virtualization

Update 1: Thanks much Mark Shyn for pointing out method 1 correction.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • /*以下内容根据 Aviraj Ajgekar 的博客文章编译和修改。*/ 之前的文章提到了Windows 7对VHD文件的内建支持,从此以后VHD文件的地位得到了提升:-) 它可以被操作系统认为是一块物理的硬盘进行管理和读写。

  • I follow yours instructions on your blog and i would know how you can directly attach the created vhd to Hyper-v

    I tried it and the boot manager is missing

    Maybe have i missed one step ?

  • Make sure you are attaching the VHD, which was already created with Hyper-V and not the the one that was created using imagex method.

    VHD created in hyper-v already contains primary 200 mb system active partition containing bootmgr. In case of VHD created with imagex, we are just extracting files onto the single partition.

  • Thanks a useful post and i have some problem regarding that.

    I am using Windows 7 as base os and i am try to install the Windows server 2008.

    First i created a vhd using diskmgmt.msc and then using imagex it applied the same as mentioned in the above.

    I found the boot entry while booting but it go for repair console.

    Aviraj previous blogger explained it i understood that.

    But is there is any way to do this i.e. without hyperv ?

  • NOTE: This is some advanced stuff and you may lose a finger. No warranty express or implied. There's

  • I received my brand new Dell Latitude E4300 laptop today and I wanted to make sure i could boot both

  • I guess you need to change the guid brackets to flower brackets in these 2 lines...

    C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>

    C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>

    So this should be edited as...

    C:\>bcdedit /set {guid} device vhd=[driveletter:]\<directory>\<vhd filename>

    C:\>bcdedit /set {guid} osdevice vhd=[driverletter:]\<directory>\<vhd filename>

  • Could we have the VHD's on an External HDD..

    Coz'.. There was blue dump error when tried with external hdd on Windwos Server 2008 R2..

  • Thanks for this information - but hae you any idea how I can make this boot from a USB stick?  I have it working with the bootloader on C: and my VHD on the USB drive but can't seem to get the BCD configured correctly for the USB drive to be the only disk in the system.

  • Not yet supported on USB drive

  • Do I get in trouble if I use this stuff on a SSD (is TRIM-Command trough a VHD "Container" supported?)

  • Having a bit of trouble with the last step.  After configuring everything, I reboot my Windows 7 box and it tells me that there is an error in the Boot Loader and it has to be fixed by an adminsitrator.  If I select the VHD, it instead just boots to Windows 7.

  • This entire process can be made way way more simple:

    * You need to download the following 3 files and run the script:

    * YOU WILL FIRST NEED the program ImageX.exe Here is a shortcut to get the 32 or

    64 bit versions (WITHOUT the need to download the 1 GB Developer's kit iso from

    Microsoft and burn it to cd to extract it.)

    * Second, You'll need to download "Wim2vhd.scr"

    * I STRONGLY recommend that you create a folder name VHD and put ImagX.exe,

    Wim2Vhd.scr and COPY BcdBoot.exe and BcdEdit.exe  (from your \windows\system32

    folder) into it - then go to the command prompt in the VHD folder, verify you

    have those 4 files and THEN run the script.

    As you will find (on that web page) the command line ( you run from the command prompt) is:

    cscript wim2vhd.wsf /wim:X:\sources\install.wim /sku:ULTIMATE /vhd:C:\Win7Ultimate.vhd /size:40960 /disktype:Fixed

    This command won't work  until you change the X to C because install.wim is on

    your C: drive by default. Make sure the path to install.wim is correct before

    you run the script. Install.wim also on the Windows 7 cd.

    NOTE the VHD file size is 40 gb in the example. Windows VHD only needs 7 gb for

    Win 7 BUT you need space for installing programs and downloading files, so I

    changed mine to 20 gb. The file size can be set to dynamic, rather than fixed...

    and it will expand if/when needed HOWEVER, you system will be VERY SLOW when/if

    it has to expand the file size. This is not recommended - but keep in mind that

    you can not increase the size of a fixed VHD once it has been created.

    * Here is the exact command I copied and pasted to the command prompt in my VHD folder:

    cscript wim2vhd.wsf /wim:C:\sources\install.wim /sku:ULTIMATE /vhd:C:\vhd\Win7Ultimate.vhd /size:20960 /disktype:Fixed

    Note I also put the Win7ultamate.vhd file in the VHD folder rather than the root

    drive in the example. This makes it easier to find, backup, and increment.

    * When your VHD file is ceated you can finish the process with this handy tool:

    VHD Mount for Windows 7 -- adds all VHD related action like Mount, Un-mount,

    Boot from VHD images right in your Right Click Context menu. After you run it,

    just right click on any VHD image and select "add to boot menu."

  • I have Win7 Ultimate as a host OS and am trying to boot a WinServer 2008 Enterpize VHD. I followed all of the instructions outlined in the blog. Everything goes smooth up until I attempt my first boot into the Win 2008 VHD. I am then greeting with a dialog telling me that my Boot Configuration is Corrupted (Error 0x490).

  • what are the locate=custom parameters into VHD config?

    Are they needed? How to locate this value for my VHDs ?

    And ... why don't you explain this ?