Thursday, April 23, 2009

Booting Windows 7/Server 2008 R2 from a VHD

Windows 7 and Server 2008 R2 support a new ability to boot directly to a VHD instead of a physical hard drive volume. The biggest advantage I’ve had to using this as opposed to running an additional OS under Virtual PC (or similar) is that under this scenario the OS will have full access to ALL hardware components installed in the system (smartcard readers, biometrics, special input devices, etc). My scenario is that I have been running Windows 7 beta (x86, build 7000) on my laptop and I wanted a way to be able to test Server 2008 R2 (in particular Hyper-V settings/configuration options). With Server 2008 R2 only being released in 64 bit and wanting to take full advantage of the hardware in my laptop for testing Hyper-V I decided to configure 2008 R2 to boot from a VHD.

  1. Boot to the 2008 R2 DVD
  2. Instead of “Install now” click on “repair your computer”
  3. Click “next” to skip the operating system to repair selection.
  4. You should now be on the “System Recovery Options”. From here launch the command prompt.
  5. Optional: I like to place the VHD files that I am going to boot from in a root folder called “C:\VHDs”. To create this folder from the command prompt type “mkdir C:\VHDs”.
  6. Type “diskpart” and hit Enter. This should take you from the command shell prompt (ex: “x:\sources>”) to the diskpart prompt (ex: “DISKPART>”).
  7. Optional: Verify the volume you want to place he VHD on  by typing “list volume”.
  8. Now we need to create the VHD file. “create vdisk file=’<full path and file name>’ maximum=<max size of VHD in MB>” (example: “create vdisk file=’C:\VHDs\WinServ2008R2.vhd’ maximum=20480). By default the disk will be created as a dynamically expanding disk. If you prefer the entire size of the VHD to be pre-allocated add the option “type=fixed” (example: “create vdisk file=”C:\VHDs\WinServ2008R2.vhd” maximum=20480 type=fixed).
    Note: if you used a fixed size VHD that is large be aware it may take some time to create and allocate the space for the VHD.
  9. Once the VHD has been created (you should have received the response “DiskPart successfully created the virtual disk file”) you need to select the disk and connect it.
    1. To select the disk (so we can perform additional actions against it) type “select vdisk file=’<full path and file name to VHD previously created>’” (from the example above would be “select vdisk file=’C:\VHDs\WinServ2008R2.vhd’ ”).
    2. To attach the disk so We can install the OS to it type “attach vdisk”
  10. At this point you are ready to install Windows. To return to the installation screen (DO NOT REBOOT or you will need to re-select and re-attach the vdisk as we did in step 9) type exit in at the DiskPart prompt to return to the command shell. Type exit again at the command shell to prompt to return to the “System Recovery Options”. Now close the Recovery Options by clicking on the close Window box (the “X”) in the top right corner.
    NOTE: if you do accidentally reboot you only need to reattach the VHD using the commands in step 9.
  11. You should now be at the “Install Windows” screen. Click “Install Now” to proceed. When you get to the disk selection (“Where do you want to install Windows?”) make sure you select the VHD and not the physical drive holding the VHD (and the original Windows 7 installation).
    Tip: The VHD disk should show “Disk # Unallocated Space” in the name.

No comments:

Post a Comment

Followers