Cloning Virtual Machines in Hyper-V

Microsoft introduced Hyper-V as a virtualization platform in 2008, and it continued to release new Hyper-V versions with new Windows server versions. Since Hyper-V’s debut, it has always been a Windows Server feature, which could be installed whenever a server administrator decided to do so. It’s also available as a separate product called Microsoft Hyper-V Server.  These days its also available in the Windows Client OS versions since Windows 8. So IT Pros and other people can quickly create their own VMs (or Virtual Machines) as and when they need it.

Cloning Virtual Machines refers to creating another copy of the existing virtual machines. It is a very useful feature from deployment standpoint of view, which allows a system to be copied and duplicated without the need to perform installation again. In addition, cloned virtual machine also preserves current system and apps environment in production, allowing testing and evaluation to be done before any changes or updates been applied to production virtual machine.

If you right click the existing virtual machine in the Hyper-V Manager Console, you would not find any option to clone:

Default context menu options for existing image
Default context menu options for existing image

However this can simply be overridden by exporting and importing the virtual machine.

Exporting the existing VM

Before cloning a VM, you may want to prepare the source VM with the Sysprep utility to reset and remove the unique security identifier (SID) for the VM, and avoid issues such as two computers have a same IP address or two computers have the same computer name. This step is recommended for VM that is joined to Active Directory (AD) domain on the same network, but is not required most of the time, and can usually be skipped for virtual machines running as workstation.  Once its done, right click the existing VM in Hyper-V manager console and select ‘Export’:

Right click the existing image and select export
Right click the existing image and select export

Specify the location where you want to save the exported VM. You can click on Browse button to select a folder:

Specify the location to save virtual machine
Specify the location to save virtual machine

Avoid choosing the same location as the .vhd file (virtual hard disk file) for the existing VM.

Import the saved VM files

From the right pane in Hyper-V Manager Console, select the ‘Import Virtual Machine’ option:

Select import virtual machine option in hyper-v console
Select import virtual machine option in hyper-v console

This will open a pop-up wizard for you. In wizard, click next and then specify the location where you saved the files during export time:

Specify the location where virtual machine was exported
Specify the location where virtual machine was exported

Click next, and then it will show the name of virtual machine if its able to read the exported files. Click next here and select import type as shown:

Select import type as copy virtual machine
Select import type as copy virtual machine

We have chosen the third option as we would not like to interfere with existing VMs in the console. Click next and it will ask to specify a folder location to store the virtual machines configuration files. You can leave it as default as Hyper-V will create a unique ID for the cloned VM:

You can choose to specify path for clone virtual machine
Specify path for clone virtual machine configuration files

Click next and it will ask to specify a folder location to store the virtual machines file (.vhd files). Here you must specify a folder location which is different from virtual hard disks of source virtual machine if you’re cloning the VM on the same host, which is the case for this blog post:

You can choose to specify path for clone virtual machine
Specify path for clone virtual machine files

Click next, review the summary shown and then click finish.

Review the summary shown in the import wizard
Review the summary shown in the import wizard

It may take few minutes to complete the import process depending upon the size of the existing virtual machine. If existing VM has any snapshots or saved state, this method preserves the same. So its better than simply copying and pasting the vhd files using windows file explorer.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s