Archives For boot from vhd

{Every now and then I find that I have to do some kind of configuration magic to get my development environment working the way I want it to. I promptly forget it until I have to do it again 3-6 months later when I replace my machine. By then I have no idea what I did so I have to look it up again. The point of this Note to Self series is to remind me of exactly what I did so I don’t have to try to remember the name of some odd command line tool and the various parameters that go along with it.}

If you’ve seen me give a talk you’ve undoubtedly heard me evangelize the new “Boot From VHD” feature available in Windows 7 and Windows Server 2008 R2. In a nutshell, boot from VHD allows you to mount a vhd as a bootable drive and, as the name implies, boot from it. It’s a great scenario for creating multiple OS installations without having to create multiple OS partitions on your hard drive. It also enables you to create run a VHD on the metal, just about, on your machine without having to host in something like Hyper-V.

Recently, as in 2:00 AM this morning, I found myself in a bit of a pickle. I needed to build out a VHD that I could leverage for the new Windows Azure VM Role. The problem I was facing was that my laptop was running Windows 7. You may be asking yourself “Why is this a problem?” Well, VHD’s configured to run in the Windows Azure VM Role must be a Hyper-V image of Windows Server 2008 R2 Enterprise Edition. “Well,” you may think “couldn’t you just use this cool boot from vhd feature to create Windows Server 2008 R2 image with the Hyper-V role installed, boot into it and create your images for Azure?” You can probably guess the answer, one big resounding NO! The simply reason is that you can’t run a virtual machine inside of another virtual machine. If you did here’s a description of what would happen:

It would be bad… Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.

-Egon Spengler, Ghostbuster

OK, so maybe it wouldn’t be that bad, but you get the idea.

Let’s get back on track. To solve this problem, I had to do a fresh pave (on a different hard drive) with Windows Server 2008 R2 as the host OS. This was pretty easy and quick to do. However, I wanted to be able to use my existing development bootable vhd, so I copied it over to the new drive as well. Finally, I needed to make the dev vhd bootable on the new hard drive. To do this, I knew I had to use the Boot Configure Data Editor (BCDEdit for short), but I could remember the exact set of commands to use. After all, it’s not one of those things you do on a regular basis, well, at least I don’t. With a little tinkering around I finally got it ironed out. Here are the steps I took:

  1. Run bcdedit /copy {current} /d “Display Name”
  2. Copy the CSLID displayed
  3. Run bcdedit /set {CLSID} device vhd=[C:]\vhdname.vhd
  4. Run bcdedit /set {CLSID} osdevice vhd=[C:]\vhdname.vhd
  5. Run bcdedit /set {CLSID} detecthal on

I then rebooted and BAM, I was able to boot from the vhd I had been using on my old hard drive with everything working as before. Pure awesomeness.