Anyone who knows me personally knows that I run all of my work in a virtual environment. Back in 2009 when Hanselman posted about the Boot-to-VHD option of Windows 7, I had it up and running by the next morning. I’ve not stopped using it since.
My Setup
I have VHD’s for:
- Different Clients – Therefore I can join their domain and have a computer (VHD) dedicated to their setup. Since each client usually requires a particular set up that normally conflicts (if I were running a single machine) with another client, booting to a VHD allows me to have various configurations with different tools and sets up.
- Beta products – I’m in the process of creating a Windows Phone 7 app, yet the tools are in Beta. We all know about Windows Tools and the “beta” work – AKA:Your stuff might come to a crashing halt. Therefore I have a couple VHDs for testing various environments and tools.
- Android – I have a VHD that I use specifically for Android development.
- Personal Use – Sometimes I need to develop code in VS2010 or Eclipse or RubyMine and would like it to be separate from the rest of the code I have. This is where I put this stuff.
This process has worked great and I love booting to VHD, I think its one of the best things about Windows 7, hands down.
Can I run it on a Mac?
I’ve never been a Mac person until recently. My wife got a mac about a year ago and I’ve only used it to surf the web and fix some minor issues she had with printing. Other than that, I haven’t really touched it. However I have the need to develop iPhone and iPad apps as I’ve been getting a ton of inquires at my mobile devleopment firm – Agilevent to do so. My Dell D630 was on the way out (video card was pooping out on me) and it was time to buy a new PC before Heartland Developers Conference, which I’ll be presenting at in less than a month.
So, with some advice from Aaron Kardell (thanks Aaron) I picked up a refurb MacBook pro from the Apple Store online.
Booting to Windows and Creating a VHD
I knew that with the MacBook Pro I could run Windows 7 (as it was Intel based). This was possible to do through Bootcamp. This is something thousands of people do every day. Nothing big. However I wanted to install Windows 7, and then create multiple VHD’s for the MacBook pro environment. I followed the instructions in the Bootcamp documentation to set up Windows 7 on a different partition. I have a 500 GB HD, so I split the space equally between OSX and Windows 7. I then installed Windows 7 on the Windows partition.
When you boot a MacBook Pro with Bootcamp, you’ll get two options (if you hold down the options key on the Mac while booting). One is the Mac partition, the other is the Windows partition. I select the Windows partition to boot to Windows. Once I was able to do that, I followed Hanselman’s instructions to create a 80GB expandable vdisk using diskpart after booting to the Windows 7 DVD. This allowed me to create a virtual disk which I was able to install Windows 7 to.
When you select this new partition in the Window setup, it will warn you that you cannot (or likely should not) install windows because of possible driver issues. Blaaaah… nonsense, do it anyway.
After I let the install rip for awhile it was done. The system did reboot a couple of times and here’s where the a small problem started. When I added the vdisk and attached it, Windows gave it the boot loader name of “Windows 7”. However my default instance was also named “Windows 7”. Therefore when I booted into Windows 7 I had TWO “Windows 7” options. I eventually figured out which one was the correct one – but watch out for this because it can be tricky.
Fixing the Same Name Issue
After everything is installed, you’ll want to go back into your default Windows 7 installation and fire up bcdedit from the command line.
Issue the command:
1 | bcdedit /v |
This will show you all of the entries in the boot loader for Windows. On one of those you’ll see a path to your .vhd file. That one is your VHD boot. Grab the id (the long guid deal) and copy it to the clipboard. Then type the following command –
1 | bcdedit / set {GuidGoesHere} description "VHD" |
Of course, replace the “GuidGoesHere” with the guid you copied from the previous step, also give it a different name other than VHD if you wish.
After that, issue another bcdedit /v command and you’ll see the name has changed. Now, when you reboot into the Windows partition you’ll see the following two options –
- Windows7
- VHD
Creating Multiple VHD’s
Once your VHD is set up, you’ll want to boot back into your default Windows 7 install and then copy the .vhd file somewhere safe. This will be your boilerplate Windows 7 install. At a later time if you’d like to have ANOTHER VHD to boot from (maybe to test beta software, you go to a new client, etc), you can copy this same VHD into a new folder on the default Windows 7 install, perform the bcdedit commands to add the VHD to your boot loader (as listed in great detail in Hanselmans post) and now you’d have three options to boot from:
- Windows7
- VHD
- <YourNewEntryHere>
Booting to the VHD
To recap, I have a MacBook pro, which I’ve used Bootcamp to install Windows 7. Once that was installed I created a VHD (after choosing Windows 7 from the initial boot loading screen). I have created, perhaps, many VHD’s to boot to, and used the bcdedit tool to add them to my Windows boot loader options.
To boot the any of the VHD’s I perform the following steps –
- Power on the Macbook Pro while holding down the option key
- Select the Windows Partition to boot into.
- Once Windows start to boot I will receive an option of what Windows installation I want to boot into (the default “Windows7” or any of the VHD’s)
- I select the VHD, and Windows starts, running with full hardware support*
Its that simple. I can now copy over a new VHD, install some software and test it out.
* Drivers & Full Hardware Support – Because the MacBook Pro hardware is different than a regular PC, you’ll need to put the OSX install CD into the drive and install the Bootcamp tools for Windows. This will install ALL of the hardware drivers you need. You will then be able to use the “command” key on the MacBook Pro keyboard AS the “Windows Key” as you would on a normal Windows keyboard. I advise that you install the Bootcamp tools and then create a copy of the VHD as your baseline/boilerplate VHD. This will allow you to quickly copy over the VHD and get up and running smoothly.
Visualizing the VHD Install
To help you understand what just happend, I’ve created the diagram in Figure 1-1 below. Click it for a larger view.
Figure 1-1: Visualizing the VHD install. OSX and Windows are boot options. If booted to Windows 7, the other options then become available during the boot process of Windows