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:
- The only supported Operating Systems for the dual boot will be Windows 7 and Windows 2008 R2
- The partitions being used must be unencrypted and uncompressed
- 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
- Build the host Operating System
- 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).
- 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.
- Create the new Virtual Hard Disk
- Navigate to "Computer Management" (Start Menu -> Administrative Tools -> Computer Management)
- Under Storage right click on the "Disk Management" node
- Select "Create VHD"
- Browse to the location you want to store the virtual hard disk (VHD) remembering it should be located on an unencrypted and uncompressed drive
- 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.
- 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.
- Once you have finished the wizard you should see a drive mounted that matches the size and is set as Unallocated space.
- 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"
- When prompted click "OK"
- Take note of the fully qualified file name of your VHD file
- Install the Dual Boot Operating System
- 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
- Select the option such as custom to allow you to choose the hard disk to install on (the drive options)
- When you get to the drive selection press Shift + F10 to display a command prompt
- At the command prompt we will tell it to mount our VHD for boot
- Determine the volume letter of your vhd file
- Diskpart
- List Volume
- 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)
- Mount the VHD
- select vdisk file=e:\vhds\wn7demo.vhd
- Remember to change the fully qualified path to one that matches the location of your VHD
- attach vdisk
- exit
- exit
- select vdisk file=e:\vhds\wn7demo.vhd
- Display the newly mounted VHD
- Click the refresh button on the drive list and your newly mounted VHD should appear
- Complete the install of your operating system on the newly mounted Virtual Hard Disk
- Change the boot information in the launch screen,
- At an elevated command prompt
- bcdedit
- 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
- bcdedit /set {identifier} description "Windows 7 demo boot"
- exit
- At an elevated command prompt
- Change the default boot operating system instance
- At an elevated command prompt
- bcdedit
- 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
- bcdedit /default {identifier}
- exit
- At an elevated command prompt
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.