Create and boot from VHD with Windows 7

A VHD file is a file that you can mount as a Virtual Hard Drive, or you can (as we are going to do here) create a VHD file which contains Windows 7 and boot from it. You can read more about VHD’s here.

Prerequisites

  1. Windows 7 ISO,DVD or files (Must contain sources/install.wim. The Professional version have this. Not sure if any other versions has it.)
  2. Windows Automated Installation Kit (AIK)
    (NOTE! This ISO is a 1.5GB file. This file must be burned on a disk, mounted or extracted(e.g. 7-Zip) then installed)
  3. Windows Image to Viritual Hard Disk (WIM2VHD) (small script file)

Getting started

  1. Download AIK and WIM2VHD
  2. Install AIK. After installation copy the ImageX.exe from C:\Program Files\Windows AIK\Tools\{_CPU_Type_}\ to “c:\”
  3. Copy wim2vhd.wsf to “c:\”
  4. Create a folder to hold the VHD file, e.g. “C:\VHD”
  5. (optional)Copy the files from the Windows7 Professional edition to “c:\win7\”

Create the VHD file

  1. Open Command Promt as Administrator. (Press the Windows button. In the search field at the bottom type in “cmd”, on top you should get a file called cmd. right click the file and select “Run as Administrator”)
  2. In the command promt window type  cd\  to get to root.
  3. Some options when creating the VHD:
    • /wim: the location of the install.wim file
    • /vhd: the location where the vhd file goes
    • /sku: the windows version to install (Professional, Ultimate etc.). You can check for the available versions like this:
      •  imagex.exe /info c:\win7\sources\install.wim 
    • /disktype: Sets the kind of vhd disk type:
      • dynamic : (defaul)The file only uses the space it needs. Note: When booting from a dynamic file the file grows to full size(40GB if size is not set). So remember to have enough free disk space.
      • static : The file gets a fixed size(40GB is size is not set).
    • /size:30720 : Size i MB (For /disktype:fixed disks, this is the size in MB of the VHD that will be created. For disktype:dynamic disks, this is the maximum size in MB that the VHD can grow to as additional space is required. If unspecified, a default value of 40960 MB (40 GB) will be used.)
    • Even more settings are described here
  4. Execute the create VHD script:
     cscript wim2vhd.wsf /wim:c:\win7\sources\install.wim /sku:ultimate /vhd:c:\VHD\MyVhdFile.vhd 
  5. This creates a VHD file in c:\vhd\ with Windows 7 Ultimate installed, Dynamic disk with a max size of 40GB. This process takes some time to complete, 10-15 minutes on my dual core laptop.

Remember when using a dynamic vhd disk, ensure that you have sufficient free space on the physical drive. Because the vhd file will expand to max size (40 GB unless otherwise specified with /size:) when you boot from it.
Otherwise you might end up with the infamous BSOD… (Blue Screen Of Death)

If you make a copy of this VHD file before you boot from it you can use the copy to create new VHDs to boot from without having to repeat the above steps.

Add VHD to Boot Manager

  1. First we need to register a new boot option in Boot Manager:
     bcdedit /copy {current} /d "My_Boot_Option" 
    This is going to print out a guid which we need later. Right.Click, select “mark”, mark the guid(with the {} brackets), press “enter”.
  2. Now we have to register the VHD file:
     bcdedit /set {_guid_} device vhd=\VHD\MyVhdFile.vhd 
     bcdedit /set {_guid_} osdevice vhd=\VHD\MyVhdFile.vhd 
     bcdedit /set {_guid_} detecthal on 

    • More on detecthal here
  3. The check that it was successfully registered:
     bcdedit /v 
    This lists all the options in the Boot Manager. If it doesn’t work, you can run:
     bcdedit /delete {_guid_} /cleanup 
    and try again.

Now the machine is ready for booting from the VHD. Restart the computer and select the “My_Boot_Option”. When booting the VHD for the first time you have to complete the Windows installation. And again, make sure you have enough disk space when having a dynamic VHD!

Tips:

  1. The VHD boot option can be removed from Boot Manager using the msconfig utility. (Windows-button+R, type “msconfig” press enter, Select the “Boot” tab. The rest is obvious.)
  2. If you log Live Messenger history you probably don’t want to have separate logs for each VHD machine and the host machine. This is pretty easy to avoid: (This assumes that you already have enabled logging on the host machine.)
    • Start up the VHD machine you want to save Messenger logs from.
    • When in Windows start up Live Messenger and log in.
    • In the main Messenger window press “Alt+T+O” to get to the Options window
    • Select “Messages” in the left side box.
    • Check the “Automatically Keep a history of my conversations” checkbox.
    • Press the “change” button to change the path where the log files is stored.
    • Digg your way to where the files are on the host machine. Since the VHD file is now the c:\ drive, the physical C: drive is now shown as something else (e.g. g:\). The file path should be something like : “G:\Users\{WindowsUserName}\Documents\My Received Files\{MessengerUserName}\History”
    • Press “OK” twice and you are done
  3. To gain easier access to your personal files on the host machine add a shortcut on the desktop of you VHD machine which routes to the Documents foldet on your physical hard drive(Again, this disk is no longer the C drive.) The file path should be something like : “G:\Users\{WindowsUserName}\Documents”

That wraps it up. It’s a somewhat lengthy article (also my first one btw…) but i wanted to try to cover all the steps necessary to make it work like a charm. I’m now running 2 different VHD installs on my computer, and I’m not going back to running virtual machines…

So far I have not noticed any performance loss by running on a VHD. The only thing missing that I could find is the “Hibernate” option when I’m in VHD, which i never use anyway…

Hope this helps you out : )

Happy virtual booting!

Share
    • Bill
    • February 22nd, 2010

    I keep getting this error. I have copied Win7ent\sources\install.wim to C:\ and made a virtual drive a C:\VHD\win7vhd

    C:\>cscript wim2vhd.wsf /wim:c:\win7ent\sources\install.wim /sku:1 /vhd:C:\VHD\win7.vhd
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.

    C:\wim2vhd.wsf(0, 1) Windows Script Host: : VBScript

    What have i dont wrong?
    Thanks

    • Befriend
    • July 10th, 2010

    THnx Complete and Good Article for WIM2VHD, however, i am geting error when i want to boot system in vhd before boot manager an error window appears with this message

    “The configuration for an element within the object is invalid in the boot configuration data store

    status 0x000000e

    What is it and y? please tell me… thnx

    • Peter
    • July 27th, 2010

    I’ll check with Thomas if he can research some more around the error. Until then, have you exactly followed his instructions? And, any more info you can provide could perhaps help us spot if there is any error to this recipe. That said, others have used it with success.

    • Rajesh
    • January 11th, 2011

    Hi,

    I am having a .VHD copied from my friend’s PC. I tried to create that as BOOT from VHD option I am always getting BLUE SCREEN. How can I make the copied VHD in boot able way in my machine?

  1. August 18th, 2010