Dual Boot from VHD Using Windows 7 and Windows Server 2008 R2


Executive Summary

Boot from VHD is a new technique for installing and maintaining operating system environments.  Unlike virtual machines, the operating system that is running from a “boot from VHD” environment is using the actual hardware instead of emulated hardware.  This means a developer could easily use WPF and the full GPU processing power of a high end graphics card.  In another scenario, this technology makes it easy to setup and run Windows Server 2008 R2 with the Hyper-V role, thus supporting 64 bit virtualization workloads.

The Virtual Hard Disk (VHD) is the container for the installed operating system.  Because everything is inside a single file, there are a number of benefits that can be realized for data center server environments, as well as managed desktop environments.  The following article dives into the technical details of implementing two operating systems.  Both are installed in a VHD file and can easily be booted by selecting the preferred environment at power on.  This could easily be scripted and automated.

The Installation Foundation – Windows PE

The Windows Preinstallation Environment (WinPE) has been updated for Windows 7 and Windows Server 2008 R2.  One of those improvements is the ability to use a Virtual Hard Disk (VHD) file as the target for an installation of the operating system (OS).

This has some interesting implications.  Booting from a .VHD file that contains an entire OS seems rather magical.  I mean think about it.  You go to look at a hard drive and there’s a single file but Windows Server 2008 R2 is installed inside it.  This would certainly simplify the ability to boot your servers on a completely new environment with little effort.  This is going to turn change management on its ear.

The same is true for the desktop OS, Windows 7.  You can install Windows 7 inside a .VHD file.  Again, the OS is installed inside a single file and thus makes it rather easy to move or change out and bring up a completely different version of the environment.  This will make test environments for developers super easy to construct and test discrete sets of applications or components.

One thing that is not well known is how easy it is to create the initial .VHD file and install the operating system into it.  The supported and documented ways are geared towards very well defined support scenarios.  You can see the supported scenarios in the Windows Automated Installation Kit (WAIK).  Most people have been reluctant to take the time to learn this because it involves the use of imagex captures and applies.

What if you could install with just the DVD?

You can.  All you need is a hard drive with disk space and the DVD for Windows 7 RC or Windows Server 2008 R2 RC.  In fact, when I was investigating the tools for this article I used a brand spanking new Hitachi 2.5” 320GB 7200rpm hard drive and both DVDs to create a dual boot environment.  Nothing more.  And it’s much simpler than I thought.  The key is WinPE and DISKPART.  Here is the screencast demonstration of the tools in action.

The Screencast Video – 23 minutes – Win7 and R2 Dual Boot via VHD

Get Microsoft Silverlight

The Command Sequence Used in the Video

  1. Boot your machine with a blank hard drive using the Windows 7 DVD.
  2. Click next on the language screen if English is appropriate.
  3. SHIFT+F10 to launch a WinPE command console.  Although the commands below are in upper case, the commands are not case sensitive.  I am only using upper case for readability here.
  4. Enter DISKPART to run the utility.
  5. LIST DISK to see the available disks in your system.  I am assuming a single raw disk.
  6. SEL DISK 0
  10. ASSIGN
  11. LIST VOL
  12. CREATE VDISK FILE=c:\windows7rc.vhd MAXIMUM=200000 TYPE=EXPANDABLE
  13. SELECT VDISK FILE=c:\windows7rc.vhd
  18. LIST VOL
  20. exit DISPART
  21. exit WinPE command console
  22. Install to the newly created 200GB (fuzzy math) virtual hard disk which looks just like a partition to Windows Setup
  23. Repeat steps 11-18 for the Windows Server 2008 R2 VHD but with the obvious changes for the vdisk filename, size, etc.

Other References and Articles

Windows Automated Installation Kit (WAIK) for Windows 7 and Windows Server 2008 R2 RC – get it @ https://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=60a07e71-0acb-453a-8035-d30ead27ef72.  This is the bible for the supported methods of using “Boot from VHD”. 

Windows Virtualization Blog – see their VHD boot post at https://blogs.technet.com/virtualization/archive/2009/05/14/native-vhd-support-in-windows-7.aspx.  Particularly interesting is the performance area of the post.

Knom’s Developer Corner – another nice post at https://blogs.msdn.com/knom/archive/2009/04/07/windows-7-vhd-boot-setup-guideline.aspx.

So What’s Next ???

Tomorrow I am going to backup my existing Windows 7 production hard drive.  Windows 7 is installed in the traditional fashion on a 200GB drive right now.  I am going to restore the backup to a larger disk then install Windows Server 2008 R2 RC into a .VHD and test mixing them.  That’s a bit of a hybrid and one I think a lot of developers might be interested in.  It would certainly demonstrate you can have a traditional implementation of your production OS, but flip to any other Windows Server 2008 R2 or Windows 7 testbed very easily.  I’ll follow-up here or another post when I get that implemented.  Enjoy.

[UPDATE for 5/23/2009] As I indicated just above, I wanted to run an extension of the test I recorded.  I backed up my 200GB Windows 7 RC environment then restored it to a 320GB drive.  After that, I booted from the Windows Server 2008 R2 RC DVD and created a bootable VHD with R2 inside.  The VHD is stored in a folder at the root of my 320GB disk.  The R2 setup program fixed up the bcdstore area and I now have a dual boot hybrid.  Windows 7 is installed in the traditional manner.  R2 is booting from the VHD.  Both are available on the selection menu at power up. Interesting stuff for sure.

[UPDATE for 5/25/2009] Since I received a couple of questions out of band on how I captured the demo, let me explain.  The demo was captured using Camtasia v6.0.2.  The demo was a Hyper-V virtual machine, not native hardware.  I had mentioned that in some of the preliminary takes but I guess I didn't make that clear in the final take.  Therefore, the booted OS in the screencast is actually using the emulated hardware of the virtual machine.  Everything you see in the demo works on my native hardware, a Lenovo ThinkPad T61p.

One other thing, the VHD that is being booted from will expand to the maximum size specified at creation.  It will revert to the used size when you shut it down.  Keep this in mind because that buffer must exist at boot time or else.

[UPDATE for 6/14/2009]   Although this article was originally written using a blank hard drive, I have received a few suggestions for adds, so here they are. 

  1. Backup your machine first.  Yep, this is a good idea as always if you are messing with a drive you care about.
  2. Decrypt the drive if using BitLocker.