Part 1: Create a Hyper-V Host Using Boot-to-VHD

Introduction

The advent of Windows Server 2008 R2 and Windows 7 brought with it a fantastic new capability that greatly enhances our experience with creating lab and test environments: Boot to Virtual Hard Disk (Boot-to-VHD).  Unlike VirtualPC virtual machines, "Boot to VHD" VM's utilize underlying hardware resources directly rather than via emulation, and this translates into improved performance. The virtual hard disk file can host the operating system and all its contained resources in one easy-to-manage container.  Using "Boot to VHD" you can create a Windows Server 2008 R2 host server that runs the Hyper-V role that, in turn, can host an extensive environment made up of multiple guest systems that mimic an entire domain.  This approach eases the creation of development and test environments and can leverage most of the services and capabilties that would be found on a production network: Active Directory Domain Services, DNS, Certificate Authorities, File and Print Servers, Datababase Management Servers, Web and Application Servers, SharePoint 2010 Servers; the list goes on!  What's more, an entire lab environment can then be backed-up atomicly just by backing-up a single file.  Using this approach snapshots can be created that capture your lab environment at critical states simply by backing-up a single VHD file at strategic points during its development.

How to install a VHD-Boot machine

  1. First, format a USB thumb drive (4GB minimum) using Windows Server 2008 R2, and then copy the contents of a Windows Server 2008 R2 ISO file to that USB stick. 

    1. If you don't have a tool to open an ISO file, you can burn the ISO file to a DVD, and then copy its files to the USB stick.
    2. Optionally, you can boot directly from the WIndows Server 2008 R2 DVD.
  2. Next, boot the system using either the setup DVD or the USB Stick created in step 1.

  3. At the setup screen, instead of choosing “Install Now”, press “Shift-F10” to enter into the preboot command line mode .

  4. Type DISKPART and then press ENTER to start the disk partitioning utitlity.

  5. Create a new VHD file by entering:

    CREATE VDISK FILE=”X:\path\to\VHDImageFile.vhd” TYPE=expandable MAXIMUM=maxsizeInMegabyte
  6. To create a differencing virtual hard disk file you'll need to add the following additional parameter to the "CREATE VDISK" statement:

     PARENT=”X:\path\to\ParentVHDImageFile.vhd” .
  7. Now you can select the newly created VHD and attach it as a physical disk.

    SELECT VDISK FILE=”X:\path\to\VHDImageFile.vhd” ATTACH VDISK
  8. Proceed the normal setup, but make sure you install to the correct disk (normally the last one), ignore the “Windows cannot install to this disk” warning!!

  9. At next startup, you’ll see your new "Windows Server 2008 R2" in the boot menu!

Also, you can manually add an existing VHD to the boot menu by using a command-line tool called BCDEdit , you just need to copy an existing boot menu entry and set some parameters:

  1. First you must type the following command in order to make a copy of an existing boot entry.  Typically this will either be the {current} entry or the {default} entry (it's the same if only one entry exists):

    BCDEDIT /copy {current} /d "Windows 2008 Server R2"
  2. When the command completes it will return a GUID.  Copy that GUID (Including the curly-braces).

  3. Execute the following commands, replacing {newguid} with the GUID that was returned in the preceding step. 

    BCDEDIT /set {newguid} device vhd=[D:]\filepath\VHDImageFile.vhd BCDEDIT /set {newguid} osdevice vhd=[D:]\filepath\VHDImageFile.vhd BCDEDIT /set {newguid} detecthal on

 
NOTE: When supplying the drive letter where your VHD file resides, you must retain the square brackets; e.g., vhd= [D:] \filepath\VHDImageFile.vhd