I recently got an MSDN Universal subscription via the Microsoft Empower for ISV program ($375 for MSDN Universal), which comes with only all Windows OSes, Visual Studio, SQL Server, Biztalk, Office, and lots of other software. One such program is Microsoft’s Virtual PC 2004, which lets you create any number of virtual machines (VMs) each of which acts like its own computer.
Since I’m currently working on 3 different projects (one in .NET 1.1 & SQL Server 2000, one in .NET 2.0 & MySQL, and one in ASP.NET 2.0 & SQL Server 2005), I wanted to have separate development environments for each project to reduce the likelihood of cross-environment contamination (SQL 2000 affecting SQL 2005, .NET 2.0 messing up .NET 1.1, etc.). Not to mention that keeps it cleaner.
Virtual PC Benefits for Developers
Three big benefits for developers from Virtual PC (along with other VM solutions like VMWare and Virtual Server) are
- you can easily whip up a VM to try out beta software, etc without messing up your main machine
- you can keep different dev environments separate so you can switch between projects without having to uninstall or pollute your files
- you can have multiple VMs running at the same time in order to simulate an entire network of computers. For example you could have a VM emulating Windows 2003 & IIS 6, and have that VM communicate with another VM running SQL Server 2005 and Biztalk.
So for me, I’ll start by creating a base VM with XP Pro SP2, Firefox, and Office. No dev tools yet. Using that XP Pro VM as a base, I’m then going to make at least three different VMs: one with .NET 1.1 & SQL 2000, one with .NET 2.0 and MySQL, and one with .NET 2.0 and SQL 2005.
When you create a VM based on an existing one, the advantage is you don’t have to install anything that’s already in the base VM (e.g., I won’t have to install XP Pro, Firefox, or Office for my three dev environments). The decision you have to make is whether you want to just make a plain ol’ copy of your base VM, or create a new “differencing disk” VM.
Copying your Base VM
Making a copy of a base VM is easy and performs well. You’re literally making a copy of the VM files. The downside is it can take up a lot of disk space. To make a copy of a VM:
- go into My DocumentsMy Virtual Machines (or whatever your VMs live) and create a new folder for the new VM, e.g. My DocumentsMy Virtual MachinesNewVMCopy.
- find the .VHD file of the base VM, and make a copy of it into My DocumentsMy Virtual MachinesNewVMCopy. Rename it to something like NewVMCopy Hard Disk.VHD.
- start up Virtual PC 2004, click
- New->Next
- Use default settings to create a virtual machine->Next
- Click Browse, go into BaseVMCopy and enter a name for a new VMC file (e.g. NewVMCopy.VMC)->Next
- Click Finish
- The settings dialog will come up, click Hard Disk 1 in the left, check “Virtual Hard disk file:” on the right and browse to the .VHD file you put into the NewVMCopy. Bump up the Memory setting to 256MB RAM or more, and you may want to ensure the Networking option is set to a valid NIC or Shared (NAT).
- Click OK
- Your copy is now ready to start up, but before you do, make sure the VM you copied it from isn’t running.
- Now fire up NewVMCopy. Once you get it started, you’ll want to give it a new machine name and SID so that it doesn’t conflict with any other VMs on the network. To do this, download Sysinternal’s NewSID and run it from the command line as “newsid /s <new name>” where “<new name>” should be a new, unique name for this VM. It will run a bit and then automatically restart your VM.
Congratulations, you’ve made a copy of a VM! Now you can back this VM up (by just backing up the VHD file), install beta software on it, lots of fun stuff. It’s “virtually” hassle-free. ๐
Making a Differencing Disk VM
The other way to make a copy of a VM is to create a “differencing disk.” The big disadvantage with copying a VM like we did above is that it can take up a lot of space. XP Pro and Office can make a 2gb .VHD file. Copy that .VHD file four more times and you’ve now got 10 gigs of space taken up.
A differencing disk VHD only stores what’s different between itself and the base VHD. So if you create a differencing disk and only install a small program, the VHD file is going to be small, too. The downside is differencing disks can perform more slowly (although that seems to be debated), and if you change anything in a VHD you’ll break any differencing disks based on it.
Rather than reinvent the wheel, I’ll link to a few good articles on differencing disks. BTW, some sites refer to VMs created in Virtual PC 2004 as VPCs (Virtual PCs).
http://blogs.msdn.com/donsmith/archive/2005/06/16/429700.aspx
http://weblogs.asp.net/cumpsd/archive/2005/03/08/389738.aspx
http://andrewconnell.com/blog/articles/UseVirtualPCsDifferencingDisksToYourAdvantage.aspx
And a special bonus link: Top Ten Tips for Virtual PC 2004
And two more links to Griffin Caprio’s thoughts on VMs: Why he likes VMs and Just in time development. And dammit Griffin you should turn on SEO-friendly URLs. ๐