Monday, November 09, 2009

Windows 7 – Boot from VHD – Simple as pie instructions

Here is the simplest set of instructions for setting up Windows 7 to boot from VHD.

First of – why would you want to boot from VHD – because it gives you a experimental machine which is faster than running with VirtualPC but slower than running it natively. The reason I did it is so that I could test out Visual Studio 2010, without having to muck up my machine.

Having said that remember this important piece of information: Boot from VHD is only supported by the Ultimate and Enterprise editions of Windows 7. I learnt this the hard way and wasted at least an hour trying to setup a Win7 Starter boot from VHD machine.

Step 1: Create the VHD:

  1. Go to Start –> Right Click on My Computer –> Choose Manage. This will bring up the Computer Management Window
  2. Under the Storage node –> Select Disk Management.
  3. Right click and select Create VHD
  4. Set the location and choose dynamically expanding. Choose a size of at least 15GB. (I choose 20gb). Dont worry, because it is a dynamically expanding disk, it will use only what it needs.
    image
  5. You should now have a hard-disk appear in your disk-management window
    image
  6. Right click on the newly added disk and select initialize.
  7. Leave the default options and select OK.
    The disk will not report its status as being Online.
  8. Right click on the disk again and select “New Simple Volume”
  9. Select the defaults and keep clicking through.
    On the 3rd screen, note down the drive letter the volume will be assigned
    image 
  10. On the next screen, choose a name for your volume label. Also make sure that the FileSystem selected is NTFS
    image
  11. On the next screen select Finish.
    If everything went correctly you should see something like this: (The size will be different).
    image

Step 2: Use ImageX to Setup the Windows 7 on the VHD volume:

  1. First we need to download the Windows Automated Installation Toolkit (WAIK). Get it from the download center.
    Unfortunately its a big download (1.7GB) for a small file that we will end up using.
  2. Once you install the WAIK onto your computer, you can copy out ImageX.exe to a convenient folder (like c:\). (You will find ImageX.exe in the following folder - C:\Program Files\Windows AIK\Tools\x86)
  3. You will also need the Windows 7 installer DVD. On the DVD you will find the install.wim file in the sources folder.
  4. Run the following command:
    imagex /info "d:\sources\install.wim"
    This will output a whole lot of text to the screen, and will provide you with information regarding the available images in the install.wim file.
    Two parts are important – the image index and the “EditionID”. You want the image index that corresponds to the Enterprise edition or the Ultimate edition of Win7.
  5. Now to apply the selected image to the VHD drive. (Remember we selected drive G in 1.9 above).
    imagex /apply d:\sources\install.wim 1 g:\
    The process should take about 15 minutes to complete.
    In the above command the 1 represents the 1 image index we obtained in step 4 and we are applying it to drive g – which is the VHD drive we created.
  6. Now you can disconnect the drive.
    Right click on the disk and make it go offline.
    On the dialog – make sure that the option to delete the VHD file is not selected:
    image

Step 3: Add an entry into the boot menu:

  1. This step will provide you the option to select the VHD boot drive during startup.
  2. There are multiple bcdedit commands that need to be run:
    bcdedit /copy {current} /d "Win7 on VHD"
    returns a GUID after copying the current configuration. Copy the returned GUID for use in the next few steps.
  3. run the following command
    bcdedit /set {guid} device vhd=[C:]\test.vhd
    {guid} is the GUID returned previously. vhd= points to the VHD file. The square brackets [] are needed.
  4. run the following command
    bcdedit /set {guid} osdevice vhd=[C:]\test.vhd
  5. run this final command
    bcdedit /set {guid} detecthal on
    This turns on hardware abstraction layer detection.
  6. Now restart your computer.
    After restart, you should be shown a menu with “Win7 on VHD” as an option.
    The first time you run Windows on the VHD drive, it will step you through the setup process. Keep your Win7 registration key handy, as you will need it.

And you are done!

In case you run into a problem while setting up BCDEDIT, run the following command to delete the entry and then run through the above steps to resetup the entry.
bcdedit /delete {guid} /cleanup

1 comment:

Matt said...

To those interested in creating native VHDs on systems such as Windows XP, Windows Server 2003, Windows Vista, etc...Take a look at this utility. This takes all the work out of setting up a dual-boot VHD environment and manages it as well.

http://www.portlock.com/products/leap_frog/