Notes on Running on “Boot from VHD”

As someone who works for Microsoft and does a lot of showing the latest release of things I’ve had to deal with the challenge of building a decent presentation machine. You might think this is easy, but with the rapid rate of change and releases of software, OS’s, Tools and Platforms, having the right configuration is not just good, it’s critical. So how do you do it?

What I’ve done for this is to use Win7’s feature “Boot from VHD”, where you don’t need to install Server 2008 R2 and Hyper-V (it doesn’t support sleep or hibernate on a Laptop!). The idea is to mount the VHD as a disk and have an installed OS to run. The nice thing is I can copy the VHD to an external drive (even while it’s running) and have the exact same environment even if I move it to another machine. Of course there are driver issues and licensing to be aware of, but this is a nice option to have. So this post is to share what I’ve learned.

I found a great post on how to do this (https://thelazyadmin.com/blogs/thelazyadmin/archive/2009/01/12/windows-7-boot-from-vhd.aspx) but it basically goes like this.  You start by launching a Command Prompt as Administrator, once that is done run the following commands…

c:\> bcdedit /copy {current} /d “myVHD”

Copy the CSLID that is displayed and then run…

c:\> bcdedit /set {CLSID} device vhd=[C:]\vhds\vhdname.vhd

c:\> bcdedit /set {CLSID} osdevice vhd=[C:]\vhds\vhdname.vhd

c:\> bcdedit /set {CLSID} detecthal on

You can replace [C:]\vhds\vhdname.vhd with the path and name of your VHD.

I created my VHD from a machine running Server 2008 R2 with Hyper-V, since it supports creating the right version of vhd files. From there I tweaked the installation to include Office, Visual Studio, etc. Then shut down the VM and copy the vhd into a folder on the target machine…I used c:\vhds…

Couple things to keep in mind

  • You can’t create the VHD image with Virtual PC
  • When you create the virtual machine, create a dynamically resizeable drive that’s reasonable size. When Boot From VHD starts it checks to make sure it could expand to it’s maximum size even if it doesn’t currently need it. Ie if you set max size to 127 GB it will not start unless 127 GB is free on your physical disk. I’ve sized mine at about 40 GB max.
  • There are tools to resize a VHD if you need to…I’ve used VHDResizer (https://vmtoolkit.com/files/folders/converters/entry87.aspx) to enlarge an existing VHD that needs more space…after resizing and restarting the vhd os you need to go to the computer management panel and open the disk and expand the partition size…
  • Keep a backup of the VHD somewhere in case you need to go back to it later. This has saved my bacon more than once…

Enjoy!

Mike