Hyper-V - Export & Import (Part 1)

Hyper-V - Export & Import (Part 1)

Rate This
  • Comments 15

Before I get going I want to get this out of the way:  Export / import in Hyper-V is by no means intuitive or easy to use.  It is definitely something that I hope we can improve in a future release - but for this release it is functional.

So with that behind us, let's start pulling this apart.

If you want to move or copy a virtual machine with Hyper-V, then you will need to use the export / import functionality provided by Hyper-V. 

The first thing you need to do is to pick the virtual machine that you want to copy and / or move, and then select Export... from the action menu / pane.  You will be presented with the following dialog:

export

Today I will be looking at the case where you specify an export path (in my case: "C:\Export") but do not check the option to Export only the virtual machine configuration.

Before going further I need to cover virtual machine names and IDs.  Each Hyper-V virtual machine has one of each of these. 

The virtual machine name is what you called the virtual machine.  For today's post I am using a virtual machine with a name of "Test Export VM".  While you are likely to give each of your virtual machines different names - the virtual machine name is not required to be unique.

The virtual machine ID is a GUID that Hyper-V generates automatically for each virtual machine.  This ID is used to uniquely identify one virtual machine from another.  For the most part the virtual machine ID is never displayed in the Hyper-V user interface (with the exception of error messages).  The virtual machine I am using for today's post has a virtual machine ID of "6D59FE56-6D20-4129-9BF3-2457DDB58A9A".

Beyond this, each snapshot that a virtual machine has has its own name and ID.

Hitting Export will result in Hyper-V copying everything that makes up the selected virtual machine into a new folder under the export path you specify.  This new folder will be named after the virtual machine name (in my case: "C:\export\Test Export VM").  Under this new directory will be the following items:

  • The Virtual Machines folder

    • This folder will contain a single .exp file, which will use the virtual machine ID for its name (in my case: "6D59FE56-6D20-4129-9BF3-2457DDB58A9A.exp").  The .exp file is the exported configuration of the virtual machine. 

      There will also be another folder in this folder, which is also named use the virtual machine ID.  If the virtual machine was in a saved state when it was exported this sub-folder will contain two saved state files (a .vsv and a .bin file), otherwise it will be empty.

  • The Virtual Hard Disks folder

    • This folder contains copies of each of the virtual hard disks associated with the virtual machine.  Note that if you have two virtual hard disks with the same name (but different locations) associated with a virtual machine, exporting the virtual machine will fail.

  • The Snapshots folder

    • This folder will contain:
      • A .exp file for each snapshot the virtual machine had (name after the snapshot ID)
      • A folder named after the snapshot ID that contains the saved state files for the snapshot in question.
      • A folder named after the virtual machine ID that will contain the differencing disks used by all of the snapshots associated with the virtual machine (.avhd files).

  • config.xml

    • I will look at this file in more detail another day.  It is not necessary for standard export / import usage.

You can freely move / copy / backup this entire directory structure now.  When you are ready to import the virtual machine you will need to go the the Hyper-V Manager and select Import Virtual Machine... from the action menu / pane.  You will see:

import

Before clicking Import there are three important things to know:

  • You need to specify the folder that was created during export, not the folder that was used for export.  So in my case I need to specify "C:\Export\Test Export VM" instead of "C:\Export".

  • When you import a virtual machine it will be left in its current directory (in my case "C:\Export\Test Export VM") and it will be impossible to move the virtual machine after import.  So make sure that you move the exported virtual machine to your desired location before you import it.

  • Importing a virtual machine deletes the .exp files, which stops you from importing it again.  If you want to use an exported virtual machine as a backup / template that you will import multiple times - you need to make a copy of it before importing it.

After you click Import the file structure of the exported virtual machine will remain roughly the same, with the following exceptions:

  • The .exp files will be deleted and will be replaced with .xml configuration files.
  • The config.xml file will be deleted.

And now the virtual machine will appear under the Hyper-V manager and you will be able to interact with it directly.

Cheers,
Ben

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
  • I have a virtual machine I am trying to export.

    The virtual machine's size based on it's GUID in the folders \programData\Microsoft\Windows\Hyper-V\Snapshots and Virtual Machines is 35.8 GB.   However, when I try to export the VM, it fails bc the required space for export is 120GB.

    What's the deal?   How is this calculation being made?

    [Window Title]

    Hyper-V Manager

    [Main Instruction]

    An error occurred while attempting to export the virtual machine.

    [Content]

    Failed to export virtual machine 'O14 Main Enlistment' because of low disk space under 'H:\Hyper-V\'.

    [Expanded Information]

    Failed to export virtual machine 'O14 Main Enlistment' because of low disk space under 'H:\Hyper-V\'. The required space is '119128.975285' MB, and the available space is '50516.031250' MB. (Virtual machine ID ACB01786-8CA7-4565-9061-A2879A2C19B3)

    [^] Hide details  [Close]

  • Any recommendations on scripting exports/imports?

    Thanks.

  • Robn,

    my best guess would be that there must be some differencing disks or something else you failed to count up when you were figuring out the footprint of the current VM.

    Rather than seeking support in the comments section of a blog, I'd suggest you try the Technet Hyper-v forum instead.  Odds are you will get a rapid response there, which is not likely here as Ben is doing a lot of travelling right now.

    http://forums.technet.microsoft.com/en-US/winserverhyperv/threads/

  • Oh as for scripting the exports    dude, learn to google!  a search on "hyper-v export script" will find several useful hits on the first page, including this gem here

    http://blogs.msdn.com/taylorb/archive/2008/06/07/hyper-v-wmi-cloning-virtual-machines-using-import-export.aspx

  • It would be good practice to set the VM's network adapter(s) connection property to "Not Connected" before exporting. If not a warning message will occur after the import. If moving to a different machine then... I think "Unknown" display's if the adapter was left to a setting.

    No matter what (as far as I've been) it's not a problem because you can just go in and select the new server's correct adapter. Nobody likes a little warning notice when importing a machine. Personally I start to wonder if I could have messed something else up too.

  • Unfortunately, Microsoft didn't make this any better with Windows Server 2008 R2.  Customer expect a right-click "Move..." button, but instead they get the old mess.  It is unfortunate that Microsoft hasn't improved it.  Here are the 3 problems I have experienced:

    1. You can't export to a network location (ie: straight to the destination server)

    2. It doesn't calculate the size properly (I have no differencing disks, and I checked the size of the export).  Same problem as the other poster.

    3. I didn't disconnect the network adapter before exporting.  I have a warning in import, but it is NOT as simple as removing the network definition in the VM and then adding it back in again.  My VM does not get any network connectivity.

    So instead of a simple right-click operation, I have burned 6 hours of my time today, the VM has been down the entire time, and I still don't have network connectivity, so I may have to spin the VM back up on the source server and start all over again tomorrow.  

    Please do us a favor - please tell whoever in Microsoft needs to hear this that the experience MUST be fixed.  And while you are talking with them, please tell them that it is completely unacceptable to not support 64-bit clients in VPC.

  • Hi,

    can you import the VMs from Microsoft for Sharepoint?

    www.microsoft.com/.../details.aspx

    I can't import the folder.

    Tobias

  • Ben, I just following the export instructions and I did export the folder over to the storage location.  But...

    1. I do not see it go away from the Hyper V manager and

    2. I did not see the folder get deleted from its original location.

    Do I have to do these things manaually?

  • Could you update this for 2008R2? The Export command isn't there...  If you have come back to this topic in this blog, my apologies, but I couldn't find it.

  • You need to shutdown the machine on 2008R2 for the export command to appear.

  • Can you export from a Hyper V 2008 R2 and import it into a 2008 non-R2?

  • Thanks Ben, i'm so glad this is all much easier in server 2012!

  • Ben pls confirm Bill S query below about backward compatibility.

  • It would be nice if it gave you some sort of progress bar while it was doing the exporting.  As it is now, it just kind of sits there without any indication that it is work while the export is happening. It takes several minutes to complete and your just left to guess when it's done.  Needs better feedback. Am I missing something?

  • As for a status on the exporting, I was thrown for a second too that I didn't see a progress bar.  Then I realized I needed to scroll all the way to the right of my highlighted virtual machine that I was exporting and it had a status column there with progress percentage.  :)

Page 1 of 1 (15 items)