Welcome to MSDN Blogs Sign in | Join | Help

Hyper-V - Export & Import (Part 1)

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

Published Tuesday, August 26, 2008 7:55 PM by Virtual PC Guy
Filed under:

Comments

Wednesday, August 27, 2008 9:50 PM by RobN

# Huge required disk for export

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]

Wednesday, August 27, 2008 11:59 PM by TK

# re: Hyper-V - Export & Import (Part 1)

Any recommendations on scripting exports/imports?

Thanks.

Friday, August 29, 2008 4:54 PM by Chuck vdL

# re: Hyper-V - Export & Import (Part 1)

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/

Friday, August 29, 2008 4:58 PM by Chuck vdL

# re: Hyper-V - Export & Import (Part 1)

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

Monday, September 01, 2008 10:15 PM by Zac B

# re: Hyper-V - Export & Import (Part 1)

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.

New Comments to this post are disabled
 
Page view tracker