Cloning Hyper-V Virtual Machines the Right Way (Part 3)

If you would like to read the other parts in this article series please go to:

Introduction

Although Microsoft’s System Center Virtual Machine Manager automates the process of cloning a virtual machine, you can perform the cloning process manually without the aid of additional software. This article starts with the explanation of the manual cloning process.

In my previous article in this series, I showed you how you could use SYSPREP to prepare a virtual machine for cloning. Once we prepared the system image, we used System Center Virtual Machine Manager to perform the actual cloning process. Although this technique works really well, I realize that not everyone owns a copy of System Center Virtual Machine Manager. That being the case, I want to show you a cloning method that you can perform using only native Windows tools.

Before I Begin

Before I get started, I want to point out that regardless of which cloning method you are going to be using, you are going to have to prepare your model machine for the cloning process by using SYSPREP. Even though I am going to be using a completely different cloning process in this article, Windows still expects every server on the network to be uniquely identifiable. Therefore, you will still have to run SYSPREP ahead of time so that you can strip the model machine of uniquely identifying information prior to cloning it.

One more thing that I want to point out before I get started is that the technique that I am about to show you is actually geared towards moving virtual machines from one Hyper-V server to another. By slightly altering the technique, we can use it as a method to clone virtual machines.

Since the technique to migrate a virtual machine is so similar to the technique for cloning a virtual machine, I am going to show you how to do both. The most important thing to keep in mind is that if you are only migrating a virtual machine to a new host server, then you should not run SYSPREP on that machine. If you are going to be cloning a virtual server though, then running SYSPREP prior to the cloning process is required.

 As always, remember that you never run SYSPREP against a production server, because doing so will essentially destroy that server. You should only run SYSPREP against virtual machines that you have specifically created to act as models for clones.

The Process

The process that I will be showing you involves using Hyper-V’s Import and Export functions. While there is nothing inherently difficult about performing an export or an import, you need to have a basic understanding of what is going on behind the scenes. That being the case, I want to talk about virtual machine portability.

Virtual Machine Portability

As I have already mentioned, Hyper-V allows you to move virtual machines from one host server to another by using the Import and Export functions, and this process can easily be adapted to create virtual machine clones. You may be wondering why this process is even necessary though, and why you can’t just make a copy of the virtual hard drive file (the .VHD file) and build a new virtual machine around it.

I think that I may have mentioned earlier in this series that I was building a new virtual server out of a copy of a virtual hard drive from a virtual machine that had been running Windows Server 2003, but that I was not able to make that particular technique work for Windows Server 2008. The technique that I am going to be showing you is preferable to just copying the virtual hard drive file because it works regardless of which operating system is running on the virtual machine.

Of course this leads me to a second question. What makes the Import/Export process so different from a copy of a virtual hard drive file? In order to answer this question, think back to the last time that you set up a virtual machine on Hyper-V. The setup process involved a lot more than just installing an operating system. You had to tell Hyper-V how much memory and how many virtual processors to allocate to your new virtual machine. You also had to tell Hyper-V how the virtual machine was going to connect to the network, and where the virtual hard drive files should be stored.

All of this configuration information becomes a part of the virtual machine, but it is not stored on the virtual hard drive file. Remember that Hyper-V is depending on the configuration information to tell it which virtual hard drive file to boot the virtual machine from. This wouldn’t be possible if the configuration information was embedded in the virtual hard drive file.

Earlier I mentioned that the Import and Export functions exist as a way of facilitating virtual machine portability. In order for a virtual machine to truly be portable, the virtual hard drive files need to be packaged with the other configuration information that Hyper-V is going to need. Only then does the virtual machine become truly portable.

So now that I have explained the concept of packaging a virtual machine to make it portable, I need to talk about the anatomy of an exported virtual machine. As you will recall, cloning a virtual machine requires you to adapt the import and export process, and part of that adaptation involves making some modifications to the exported virtual machine. Understanding the components that make up an exported virtual machine is therefore the key to the cloning process.

The Basic Structure

When you perform an export of a virtual machine, Hyper-V will ask you to provide it with an export path. When the export process completes, Hyper-V will create a folder within the path that you have specified. This folder will bear the name of the virtual machine that was exported. That is how you can identify a virtual machine once it has been exported.

Even after the export process has completed, the original virtual machine remains on the host server. Microsoft does this as a safety precaution. The idea is that if something goes wrong with the export process, you have not lost your original virtual machine. This does mean however, that we are going to have to do some cleanup work after the migration or cloning process completes.

The folder that Hyper-V creates contains three sub folders; Snapshots, Virtual Hard Disks, and Virtual Machines. The folder also contains a file named CONFIG.XML. The CONFIG.XML and each of the folders that I have listed are involved in the cloning process. I will show you why in Part 4.

Conclusion

In this article, I have explained that the easiest method to clone virtual machines in a Hyper-V environment using Microsoft’s System Center Virtual Machine Manager. Even so, you can complete the cloning process manually without the aid of any additional software. The process involves using SYSPREP to prepare a virtual server, and then exporting it in a special way. In the next article in this series, I will finish explaining the anatomy of an exported virtual machine, and then I will show you what you have to do to make a clone off of the exported virtual machine.

If you would like to read the other parts in this article series please go to:

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top