Creating VM Clones in Microsoft Hyper-V
If you’re a virtual machine freak like me, then you’ve most likely upgraded to Windows 8 Pro already due to its awesome built in Hyper-V client! No longer do you need to install Windows Server 2012 or the standalone hypervisor operating system just to be able to build your virtual machine infrastructure on your home laptop or desktop. Sure, some of the features are missing in the client hypervisor in Windows 8 but for the most part, the base client hypervisor software is the same as the hypervisor used in Windows Server 2012, which of course is used in business and production environments around the world. The purpose of this article is to show you how you can save a ton of time by utilizing a feature known as virtual machine cloning. No doubt when you build virtual machines for your mini lab environment on your client Windows 8 system, you’d often find yourselves installing the same operating system over and over again because it’s highly likely that you’ll need more than one virtual machine with that same base operating system to complete your lab setup. Installing this base operating system over and over again wastes time and quite frankly it’s quite a bore! We’ve all done it a million times by now already and so do you really want to look at that same install screen yet again? Probably not. In VMware Workstation, you’re able to create what is known as Full Clones and Linked Clones. In Microsoft Hyper-V, you are also able to create these clone types albeit in a different way.
What are VM Clones?
We should all be familiar with the benefits of virtualization by now. By creating virtual machines, we are essentially creating a virtual operating system that can be moved around as we like within the infrastructure. The one other major benefit of a virtual machine is being able to quickly make a copy of it. Because an entire virtual machine consists of just a couple of configuration files and a base virtual hard disk, we can essentially create a clone by simply copying the virtual hard disk file and creating a new virtual machine attached to that file.
So why would you want to create a clone? Simple. To save time. When you think about cloning in a physical environment, you’d typically create a master or gold image. This image is basically your base operating system of choice along with all of the software you’d require already pre-installed. These can include anything from your typical software applications, Windows software updates to special configuration options. Once this is done, you’d would then roll out that image to multiple computers. Once installed, that system would then resemble and function exactly the same as the master image. As you can see, this saves a heck of a lot of time because you no longer have to manually configure each and every system. You just configure it once and that’s it. With VM clones, the same theory applies except you have a bit more flexibility.
Types of VM Clones
There are typically two types of clones you can create in Hyper-V: full and linked or differencing disk/clone. Which type of clone you create will definitely depend on what it is you are trying to create in your lab environment.
This type of clone is what users typically associate with a “clone” in that it is taking a single virtual machine and duplicating the entire thing so that we have a second, exact replica as the original source. This clone is completely independent of the source VM in that it does not share nor require anything from it. If the original VM gets deleted or corrupted, it will not in any way affect the clone. This independence from the source VM comes at a price, however. Because it is a full clone, the clone will originally take as much hard disk space as the source VM. If the original VM is 20GB in size, then the clone will also be 20GB in size.
I’m not entirely sure if Microsoft has an official name for this type of clone. In VMware, it is called a Linked Clone. With Microsoft’s Hyper-V platform, you’d create a “differencing disk” to be able to create the same type of clone. Another name for this type of clone is a Parent to Child clone. Basically you’d start with the same master or gold virtual machine that is configured to your liking. Whereas in a full clone where we make an exact duplicate, with a parent to child clone we create a differencing disk (the child) that is “linked” to the master (the parent). Any changes to the child clone is written to its own disk and does not in any way affect the parent. When you perform this kind of clone, the child VM is obviously dependent on the parent and so if anything bad were to happen to the parent such as its virtual hard disk being deleted, then the child VM will cease to function. The major advantage to using this type of clone over the full clone type is the amount of disk space you will save. Because only the changes to the child are written (the differences), you can save a whole lot of disk space if you will be needing to create many separate virtual machines based on the parent.
Dude, What About Snapshots?!
Snapshots are definitely useful and I’m sure that feature was what got so many users excited about using virtual machines in the first place. I know it did for me. However, snapshots aren’t really considered clones. Snapshots provide a point in time copy/restore for a single virtual machine. Keyword there is single. When you create a clone, you are essentially create a completely separate virtual machine that has its own computer name, IP address, user accounts, etc. With a snapshot, you’re still working with that one individual VM. You can go back and forth between snapshots but on the network, you still have just one VM.
With that being said though, snapshots do have a lot in common with a differencing disk clone. In fact, it actually works quite the same. When you create a snapshot, a differencing disk actually gets created just like when creating a linked clone. The base VM image actually freezes and goes into read-only mode. Any changes from then on gets written only on the newly created differencing disk in order to protect the VM. Therefore, creating snapshots is not the same as creating clones.
With that out of the way, let’s begin first by creating a full clone in Hyper-V since it is the more easier of the two to get up and running.
Creating a Full Clone VM in Hyper-V
For this demonstration, I have a simple Windows 8 operating system called “Win8_source” that I will be using for both the source of the full clone example here and as the parent for the differencing disk in the next section. There is nothing really special about this VM at the moment. As you can see, I have some basic applications installed and that’s basically it. The size for this VM is about 9.5-9.6GB.
Before I clone the VM though, I should prepare it with the Sysprep utility. This awesome utility basically allows you to strip away specific security identifiers for the VM. This step is only necessary to perform if you will running multiple versions of this clone VM on the same network AND you want to join them to the same Active Directory domain. In a lab scenario, this is usually the case and so Sysprep’ing the VM is definitely something you should do to prevent any headaches later on. If this does not concern you as your virtual machines, both master and clones, will only be in Workgroups then you can usually skip this procedure. Prior to performing the Sysprep process, make sure that the VM is configured exactly to your liking! You generally don’t want to re-power back on the sysprepped image.
The Sysprep utility is included in most versions of Windows and can be found in:
Within the Sysprep folder, simply launch the sysprep utility. Although one can get extremely fancy with sysprep, all we need to do is select the ‘Out-of-box Experience’, enable the Generalize check box and have the system Shutdown once the process has completed. At the end, your source VM should have shut down and is completely ready to be cloned.
For the cloning process, there are actually two different ways to do it. The first and more correct way to do it is to perform an Export operation by right-clicking on the source VM within the Hyper-V manager. You specify a folder location to save the clone and you would then perform an Import operation. The second way to clone a VM is to simply just “copy” the source VM’s vhdx file, create a new virtual machine and finally, attaching the cloned virtual hard disk to it rather than creating a new one. I will be using the second method. An Export operation is great when you need to actually move virtual machines between different Hyper-V hosts and need to keep everything intact such as snapshots.
To begin, I simply head over to the location of my virtual hard disks and perform a copy/paste operation of the source VM. Here is the outcome. You can definitely rename the cloned VHD file to something else so you won’t get confused in the future. I renamed mine to ‘Win8_clone”.
Now that I have the cloned hard disk, it’s time to create a new VM for it. You’d go through the same usual process except when it comes to the part where it asks you about creating a VHD for the VM. On this page, you’d select the option of using an “existing virtual hard disk” rather than creating a new one. As expected, hit the Browse button and select the newly copied VHD file.
With the clone virtual machine configured, I can now power it on. Because I chose to sysprep the machine, it will initially go through the entire setup screen again as if the system was newly installed. Once that has completed though, I can see that the new virtual machine has all of the applications I installed on the source VM and that everything is exactly as how it was. You can now clone as many VM’s as you want base on the master VM. Also, don’t forget that you DO NOT have to sysprep your source VM! However, if your Windows virtual machines are going to be joining a domain, then I would definitely recommend you doing so.If you did not sysprep the source VM and power on both the source and clone together, you might get errors about having two computers on the same network with either the same IP address if the source was not configured with DHCP or more likely that both computers have the same machine name. Simply change the information on the clone or source to solve the problem.
Creating a Differencing Disk in Hyper-V
As mentioned earlier, creating a “differencing disk” in Hyper-V is similar to creating a Linked Clone in VMware’s parlance and it’s an awesome and quick way to spin up many similar yet different virtual machines all the while helping you save disk space as well. In this scenario, we do things just a bit differently because of the special parent-to-child relationship of the virtual machines.To start off, I will be using the same VM I used above in the full clone tutorial as the parent for this one. The VM is a simple Windows 8 machine called Win8_source. Once again, I have properly ‘sysprepped’ the virtual machine and I highly recommend you to do so as well. When you create differencing disk clones, you normally should not power on or change anything within the parent VM. Basically, once the parent VM is finalized, it should be sysprepped and left alone. From that point on, you can spawn as many different child virtual machines from that parent as you’d like. Hey, if only creating a child in the real world was that easy eh?!
Another thing you can do to protect the parent VM is to change the permission of its VHDX file so that it is read-only. This should add an extra layer of protection on the parent VM so that no changes can be made on it. Simply open the Properties of the VHDX file for your parent VM and enable the Read-Only check box and hit OK.
Next we create a new differencing disk in Hyper-V manager. In the Actions toolbar menu, select New –> Hard Disk and the wizard should appear. There are a couple pieces of information we need to specify and its important you get them right. When you select the option of either creating a VHD or VHDX disk, select the same type as the parent VM.
In the virtual disk type window, you’d want to select Differencing option.
Next, give your differencing disk a name and location.
Finally, you’ll need to specify the vhdx of the parent virtual machine. In my example, I am using Win8_source as the parent.
Now that the differencing disk as been created, it’s time to create a new VM and attach that disk to it. So, first create a virtual machine like always. When you get to the Connect Virtual Hard Disk page, we specify to attach an existing disk, similar to what we have done when we created our full clone. This time, however, we’ll obviously pick the differencing disk we’ve just created earlier. Do not pick the parent VM!
And that’s it! Once you start your new VM, you’d go through the same process earlier in the full clone procedure if you’d taken the time to sysprep the machine. Once I’m back on the desktop and everything is running as it should be, you can see below the size difference between the parent VM and the child VM. From now on, every new change I make on the child VM is only written to the differencing disk and the parent virtual disk is left completely alone. To make more clones, I simply repeat the process of first creating a new differencing disk based on the parent disk, creating a new VM and finally, attaching the differencing disk to it. It’s that simple.
In the End…
You can see how easy creating VM clones is in Hyper-V. Quickly being able to spin up virtual machines is one of the main benefits of virtualization and it’s a godsend for users at home who need to quickly create a small lab environment. Rather than needing to sit through installation and installation of the same operating system installation, you can now install everything just once and mass deploy that image out onto new virtual machines within a few minutes. Granted, it does take a few more steps on Microsoft’s Hyper-V client platform than on VMware’s Workstation product but the outcome is relatively the same. Please take advantage of virtual cloning whenever possible to maximize its potential!
Filed Under: MICROSOFT, VIRTUALIZATION
For Windows 8 users on desktops and laptops, how often do you actually use "apps" downloaded through the Microsoft Store?
- Every session. This is what I like best in Windows 8!
- Somewhat. I open them just to mess around but I can do without them.
- Hardly. I hate apps that take up my full screen!
- Don't care. I don't use Windows 8 at all but just feel like voting and clicking on something.
- OHWOW says:
Managed to sysprep my host that I reached remotely and have no KVM.
10/10 ruse, author.
Time to travel for a few hours and reinstall the entire machine.
September 29, 2015 at 10:09 am
That was a bit daft, considering you clearly don’t know what you’re doing.
I tried the copy and paste and the original will now not restart because ‘files in use by another process’..?
KEN COLEY says:
You need to shutdown the VM before you try to make the copy.
KENNETH COLEY says:
Would be nice if they made automated procedure for doing this. I need to clone 150 copies of a windows 7 desktop for testing purposes. Then I have to do the same for 150 copies of Windows 8 desktop.
REMO ULMI says:
Remove “User cannot change password” if set before applying sysprep or you will get troubles.
B WOOD says:
Simon, does this process work the same for cloning DCs?
Hello B.Wood. Sorry for late reply. You can safely clone a Windows Server 2012 domain controller but the steps are a bit different due the Generation ID feature in Hyper-V. Here is an article after a quick search:
MARK HARBY says:
Nice post Simon.
Very clear and precise information.
It’s such a shame Microsoft can’t produce clear documentation that just tells us what we need to know.
Thanks Mark for the positive comment! Hope you enjoy Hyper-V.
Thank you for this detailed post. My thoughts after reading this post were whether snapshots can be merged to be something useful in the linked clones pattern of work.
What I did was to create a basic machine with a few snapshots, then, right click a specific snapshot and choose “Export” which got me vhdx containing all snapshot history up to the snapshot I chose, and then I used referencing disk to get myself the linked clone. This seemed to be like a safe approach with regards to the original machine (used the exported disk) and also a way to make the changes and snapshots only on one original machine and then exporting the one I need for clones.
Thank you again for the post,