in

ASP.NET Weblogs

J e r o e n ' s   w e b l o g

Copying virtual machines made easy (sort of)

As I mentioned in my previous post on Virtual Server 2005, it's very easy to create a base virtual machine that contains (for instance) a fully patched version of Windows XP Pro and copy it around to work with multiple instances since all a VM really is is just a .vmc (Virtual Machine Configuration) and .vhd (Virtual Hard Drive) file. Making a copy of a VM is just a matter of creating a new machine in the Virtual Server web interface and copying the .vmc and .vhd files over the ones created. The only changes required are two values in the .vmc xml file: one pointing to the absolute path of the .vhd file to use and another that points to the relative path of the same file (in my experience if you change only one of these it will use the absolute path, don't ask how I discovered that, it wasn't very funny, especially the part where throwaway.vmc's VM wrote to donttouchthisbaseimage.vhd). After that you can start up the just created VM and it'll be a copy of the base image.

One problem remains however: machine name. This didn't seem like much of an issue, but having multiple instances running will mess with file sharing, besides producing annoying error messages. Fortunately, there's a solution to this, one that's probably known to system administrators but not to a developer like me. What you need is deploy.cab in /support/tools on the Windows XP or Windows 2003 installation disk. Install the files from this archive on the base image and first run setupmgr.exe. This tool will help you create a sysprep.inf file. First you choose to do a fully automated install, next select the options you want to automatically configure on a copied image, like generating a machine name. When you're done the tool will have automatically created a sysprep-directory with the sysprep.inf file in it (it will ask you to save the sysprep.inf file but regardless of where you save it, it will also place it in the correct directory).

Next you can run the sysprep.exe tool. Here you choose to do a mini-setup and click "Reseal". This will freeze the VM shortly and then shut down. Now you can create a copy of the virtual machine. When you boot into that copy for the first time, you'll see an automated configuration taking place and a reboot, after which the virtual machine is done: fully customized with a unique machine name! This is especially useful if you plan to do automated resets of a virtual machine using a script or a custom application: just copy the .vmc/.vhd files and change the path in the .vmc file. After that you're set to start over again from scratch. This might seem like a far-fetched solution, but being able to select what to automatically set during configuration and what to ask the user is very useful: for instance setting the localization during setup can be used to test localized versions of your application without having to maintain a bunch of localized base images.

A note on licensing though: I've called Microsoft to ask about licensing in such a scenario and they've told me that my MSDN Universal subscription is enough for doing it like this when I'm the only user of the virtual machines. I'm not a lawyer so I can't say anything about what you're allowed to do in other situations/with other licensing schemes.

Published Aug 03 2005, 04:15 PM by jvdbos
Filed under:

Comments

 

Justin said:

If you are looking for base images, I would look in differencing disk. What you can do is create a vhd that has for wxample a fully patched version of XP that I call the base image. Then you can create a 2nd vmc with a differencing hard disk and use the base image as the parent. When you create a differencing disk, it will ask for the parent.

Make sure though to make the base image read-only as changes to it will break all of the vmc that reference it. The use of differencing disk has saved me a ton of disk space since it only stores the differences between the base image. It also makes it very easy to create new vmc without having to copy files around.

After you have created the child vmc above, you will want to also run NewSid from SysInternals to change the machine name and all of the SID info. NewSid does the same this as sysprep but it is much easier. With NewSid you just run an exe tell it the new machine name and click next and it does the rest.

As well dont forget to install the Virtual Server Additions.
August 3, 2005 12:25 PM
 

DaveTrux said:

Another pitfall with copying virutal machines is the MAC address. If you simultaneously run multiple copies of the same VM with the same MAC address you will have strange network problems. Sysprepping the VM is not enough. You can fix the MAC address in the .vpc file by removing data between the ethernet address tags, see my post below:

http://dotnetjunkies.com/WebLog/davetrux/archive/2005/02/22/56204.aspx
August 3, 2005 3:09 PM
 

Jeroen van den Bos said:

Justin: Thanks for the information! I will look into using differencing disks as an alternative, although I have to say that installing third-party applications is something I would like to avoid - the images are used for testing application compatibility and deployment and I want the images to be as clean as possible.

I.e. I want to avoid having users on the phone and eventually recommending they install NewSid :-)

DaveTrux: I haven't had these problems yet, but I will see if it works the same way with Virtual Server and adjust my code accordingly.
August 4, 2005 1:34 AM
 

ganeshwar nayak said:

this does not interest me at all i rate it  "1/2 on 5

October 23, 2007 9:57 AM
 

vmc vhd said:

Pingback from  vmc vhd

June 5, 2008 1:11 AM

Leave a Comment

(required)  
(optional)
(required)  
Add