Building a Dual Boot Machine with VHD's

For years I have struggled with the typical developer decisions when building their workstation.  Do I make this a dual boot machine and how much space should I leave to each partition if I do?  With Windows 7 and Windows 2008 R2 I have finally been able to handle this with far less pain.  The answer for me is always yes I will make it a dual boot and I will figure out how much space each partition needs as it needs it.  This has been made possible by leveraging Windows 7 and Windows 2008 R2's ability to use Virtual Hard Disks as if they were physical.

There are a few key requirements here to keep in mind:

  1. The only supported Operating Systems for the dual boot will be Windows 7 and Windows 2008 R2
  2. The partitions being used must be unencrypted and uncompressed 
  3. If you have encryption (ex. Bitlocker) enabled on any of your drives you will want to disable or suspend it before doing any of these steps as they change the boot configuration

The way that I set up my dual boot machine is to perform the main Operating System install with the entire disk as a single partition.  The reason I do this is because I will be on the primary Operating System most of the time and want to ensure that the other installations do not impede my experience in any way.  The operating system I want to make my dual boot is then created on a VHD.  I personally use a dynamic VHD for my dual boot so I do not have to make the decisions up front about the size of partition I will need for each machine, dynamic will allocate the space as required for the secondary Operating System.  This goes against best practices and it is strongly advised that you select a fixed partition size if at all possible. 

The steps to create this workstation setup is as follows

  1. Build the host Operating System
    1. Install the original operating system, in my case it is Windows 7 as you would normally, but use the entire hard disk as a single partition (obviously you can change the size if you want).
    2. After completing the install I like to finish loading the main operating system the way I want it and ensure it is fully service packed. This allows me to ensure the tools used are fully patched.
  2. Create the new Virtual Hard Disk
    1. Navigate to "Computer Management" (Start Menu -> Administrative Tools -> Computer Management)
    2. Under Storage right click on the "Disk Management" node
    3. Select "Create VHD"
    4. Browse to the location you want to store the virtual hard disk (VHD) remembering it should be located on an unencrypted and uncompressed drive
    5. If you want to use have your hard disk expand as required and have a fear of commitment like I do select "dynamically expanding" and make the "Virtual hard disk size" something reasonable such as 10 GB. Please remember that this is not the recommended mode to use with your VHD, you should try to make it fixed if at all possible.
    6. If you are using a fixed sized VHD select the "Fixed size (Recommended)" option and set the "Virtual hard disk size" to the appropriate maximum size.
    7. Once you have finished the wizard you should see a drive mounted that matches the size and is set as Unallocated space.
    8. To the left of the new partition is a square of text that will say something like "Disk 1". Right click on that square and select "Detach VHD"
    9. When prompted click "OK"
    10. Take note of the fully qualified file name of your VHD file
  3. Install the Dual Boot Operating System
    1. Start the install of the next operating system as you would any other install (ex. From bootable media), remembering that it must be Windows 7 or Windows 2008 R2
    2. Select the option such as custom to allow you to choose the hard disk to install on (the drive options)
    3. When you get to the drive selection press Shift + F10 to display a command prompt
    4. At the command prompt we will tell it to mount our VHD for boot
    5. Determine the volume letter of your vhd file
      1. Diskpart
      2. List Volume
      3. Look through the output to find the volume your vhd is on. Based on that you will want to use that as the prefix for your fully qualified vhd name (ex. If in my primary operating system the file was "d:\vhds\win7demo.vhd" I may find that it is actually on volume E in my list and have to reference it as "e:\vhds\win7demo.vhd" in the next commands)
    6. Mount the VHD
      1. select vdisk file=e:\vhds\wn7demo.vhd
        1. Remember to change the fully qualified path to one that matches the location of your VHD
      2. attach vdisk
      3. exit
      4. exit
    7. Display the newly mounted VHD
      1. Click the refresh button on the drive list and your newly mounted VHD should appear
    8. Complete the install of your operating system on the newly mounted Virtual Hard Disk
  4. Change the boot information in the launch screen,
    1. At an elevated command prompt
      1. bcdedit
      2. Find the instance of the operating system that you want to change the boot label of and copy the identifier (this will be displayed as {identifier} in the next step
      3. bcdedit /set {identifier} description "Windows 7 demo boot"
      4. exit
  5. Change the default boot operating system instance
    1. At an elevated command prompt
      1. bcdedit
      2. Find the instance of the operating system that you want to make the default boot and copy the identifier (this will be displayed as {identifier} in the next step
      3. bcdedit /default {identifier}
      4. exit

That is all there is to it.  You now have a dual booting machine which if you used a dynamic partition will size itself appropriately.  Please remember that changes to encryption or use of dynamic partitions is up to you to determine the appropriateness and I do not recommend any of these without weighing out the options in your environment first.