How to Create a New Virtual Machine from a Hyper-V Snapshot Part 1

Without a doubt Hyper-V snapshots can be quite useful. They make software and systems testing a little less stressful because you know you can roll back any changes. They can provide a “quick and dirty“ backup solution. Or you can use them as starting points for new virtual machines.

You could take a snapshot and use it as the basis for a new VM on another Hyper-V server. Perhaps you want to roll a snapshot from a production virtual machine to a virtual machine on your test server. Or if resources are limited, perhaps even on the same server. That’s what I want to demonstrate: creating a new virtual machine based on a snapshot of an existing virtual machine.

Using the Hyper-V Manager

To begin, we’re going to need a snapshot. I’m going to “clone” my XP LAB virtual machine. In the Hyper-V Manager select Snapshot in the Actions pane as I’ve highlighted in Figure 1.

create snapshot hyper-v manager

Figure 1 Taking a Snapshot with the Hyper-V Manager

Or right-click on the VM and choose Snapshot from the context menu. Once I have a snapshot, I’m going to export it. This will write all the necessary files to disk in a new location. I want this so that I can work with the exported files and not worry about disturbing the snapshot itself. I can either right click on the snapshot as you see in Figure 2 or select Export from the Actions pane.

Export the Hyper-V snapshot

Figure 2 Export from the Context menu

Export the Virtual Machine

In the prompt I’ll specify the path for my exported files in Figure 3 and click Export.

Export Path

Figure 3 Export Path

The export will create a folder for the hard disks and virtual machine as you can see in Figure 4.

exported files

Figure 4 The exported files

The disk will be copies of any VHD or VDHX files. Under Virtual Machines you’ll find an XML configuration file. To create a new virtual machine I have a few options. I can create an entirely new virtual machine in Hyper-V Manager using the exported hard disk. Or I can re-import the virtual machine.

Note: There are ramifications regardless of how you use the exported snapshot. Because the hard disk is already configured with an operating system, at least in my example, when the virtual machine comes on line there may be naming, network or licensing conflicts. You’ll need to take this into account either through additional virtual machine modification or through changes to the underlying operating system.

Import the Virtual Machine

Creating a new virtual machine is pretty straight forward so I won’t cover that. My intention is to use the exported virtual machine as a new virtual machine. In Hyper-V Manager I’ll select Import Virtual Machine from the Actions pane and specify the top level path to the exported snapshot (Figure 5).

import folder

Figure 5 Import the virtual machine folder

Clicking Next displays the exported virtual machine snapshot (Figure 6).

Select virtual machine

Figure 6 Select the virtual machine

On the next screen you have to be careful. Because my original virtual machine still exists and I’m importing this on the same system, I need Hyper-V to create new identifiers. So I choose the appropriate option in Figure 7.

import type

Figure 7 Choose Import Type

Another alternative would have been to create new virtual machine using the exported files by using the Register option. This only works if you are importing on a different Hyper-V server or if the original virtual machine disk files are in a different location other than the default.

But I’m going to copy the VM anyway. Next, I can decide where to store the new virtual machine (Figure 8).

choose folder

Figure 8 Choose folders for virtual machine

I’m going to use the default settings. Finally, Hyper-V wants to know where to store the import virtual disk. It will display the default location, as you see in Figure 9.

Folders to store virtual disks

Figure 9 Folders to store virtual disks

I have to specify a different path if the disk files from the original machine virtual machine still exist in the default location. The import process will re-copy the VHD file (or files depending on the virtual machine) to this location. See Figure 10.

completing the wizard

Figure 10 Complete the wizard

When the process is completed I have a new virtual machine as you see in Figure 11.

new virtual machine

Figure 11 The new virtual machine

The name isn’t very friendly, but that is easily changed. Actually, if you edit the XML configuration file, you can modify the name prior to importing.

<global_id type="string">876F9EF2-3C1C-48CB-8339-BDE6D5097592</global_id>
    <highly_available type="bool">False</highly_available>
    <last_powered_off_time type="integer">130054318094417485</last_powered_off_time>
    <last_powered_on_time type="integer">130011093383728297</last_powered_on_time>
    <last_state_change_time type="integer">130054325974483199</last_state_change_time>
   <strong> <name type="string">XP Lab - (2/15/2013 - 3:09:57 PM)</name></strong>
    <notes type="string"></notes>

All I would need to do is modify the name which I’ve boldfaced. The import process will use this value. Ultimately, which ever technique you use will depend on your end goal.

Summary

The steps I’ve gone through should work if you are migrating the snapshot to a different Hyper-V Server or using the same as I’ve done here. As you can see, there is a lot of manual interaction here. I suppose if you only need to clone a single virtual machine from a snapshot is no big deal. But for real efficiency we will need to turn to Windows PowerShell, which we’ll cover in Part 2 of this series.

 

Altaro Hyper-V Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

25 thoughts on "How to Create a New Virtual Machine from a Hyper-V Snapshot Part 1"

  • Ian Yates says:

    Thanks for the article. Obvious when you think about it (as is everything with hindsight) but it hadn’t occurred to me that such functionality was available from snapshots. Cheers 🙂

    • Jack Meove says:

      This is wrong, and is a Hack Copy way,,,, No Sysprep?

      • There are many paths to the same destination. Sysprepp’d virtual machine images is certainly another way and has plenty of benefits.

      • Eric Siron says:

        You can use these techniques to duplicate a production environment into a test environment with no impact on the source system. Sysprep can’t do that. There are a lot of uses this can be applied to that Sysprep cannot.

  • Brett Jay says:

    What version of Hyper V are you using? I am running Hyper ‘V server 2012 and when I select on any snapshots I do not get the eport option. I can export my VM if there are no snapshots for that VM but not from the snapshot itself.

    • I am running the latest version of Hyper-V. You are saying that if you duplicate my actions in Figure 2, you don’t see an Export option in the context menu? Is the virtual machine running? I don’t think you can export the snapshot if the virtual machine is running. Try again on a snapshot for a VM that is not running.

  • Gabriel Cor says:

    Thanks Jeffery!
    Just what I was looking for.

  • bekir says:

    Very good,
    q: what is the advantage to keep the default locations for the virtual machines and virtual disk created in hyper-v 2012, or in what situation vm and vhd should be created in location other than default?

    q: vhd should be dynamic or fix in size?
    thanks again.

    • An advantage to keeping the default location is that it is known and easy to find. You might want a different location for VHD and VHDX files for performance such as a separate, faster disk. Whether the disk should be dynamic or fixed in size really depends on the VM and your server configuration. Personally, I go with dynamic disks because I do not have unlimited space and it helps keep my backups smaller. You may want fixed disks to reduce fragmentation or improve performance.

      • Kamran Ali says:

        If i want to start the import & export feature then i will prefer to save all configuration files along with vhd & avhd in a one folder which should be only one folder.

        Q. if i do the above exercise, may i face any problem?

        My another question regarding snapshot..
        i have taken snapshot manually on daily basis, my base machine hyper-v console shows last 10 days snapshot list, i want to delete previous 7 snapshot and want to save currently 3 snapshot……..

        i removed 7 snapshot from hyper-v console, all 7 snapshot have been deleted successfully…… but didn’t remove from storage area and all avhd files exist there…..

        i read an artical that when you delete snapshot from console then we must shutdown the vm machine, after shutdown the vm machine and started again then merging process starts, and take long time for merging process…

        my vm machine size in storage area folder is 2.23TB, so i want to know that how much time it will take, i have 2giga network speed.. kindly calculate time how much require?

        because i read that when merging procedure will be finalize then your deleted 7 snapshot avhd files will be merge in vhd…. is it true?

        waiting your quick response. i hope you can understand above all

        thanking you,
        Kamran Ali
        00923074776018

        • When you use Export-VM, everything is under one folder. Snapshot files on disk should be deleted and updated once any merging completes. Since you kept some snapshots you will see snapshot files on disk. Although I don’t think you can tell at a glance what snapshot those files belong to. As for merging, I have no idea how long it might take. I’m not aware of any formula you can use to calculate it. It will take as long as it needs to take. It sounds like what you really need to do is have a test Hyper-V environment, even on a Windows 8 or 8.1 client, and try these features out for yourself.

  • Dave Gibbins says:

    I have followed the guide and all seems to have worked fine, except when I come to connect to the new machine. I dont want it on the network, so there is no card installed, but when I use the replica server Hyper-V manager to ‘Connect’ I just get the black screen attempting to connect and noting I can actually use.
    Any ideas?

    • Without knowing the details of your process, I don’t have any idea on what to suggest. You don’t have to remove any network adapters, you can simply not connect the VM to a VMSwitch. But it sounds like the OS in the guest is failing.

Leave a comment or ask a question

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

Your email address will not be published.

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.