Migrating Hyper-V Virtual Machines Using Import/Export
|Previous||Table of Contents||Next|
|Creating and Managing Hyper-V Snapshots||An Overview of Hyper-V Live Migration|
The Hyper-V Import/Export feature allows virtual machines to be migrated from one Hyper-V server to another regardless of whether the Hyper-V hosts are part of a Failover Cluster. In this chapter of Hyper-V Essentials we will cover the concept of virtual machine migration using this approach.
For details on how to perform a live migration between nodes in Failover Cluster, refer to the chapter entitled An Overview of Hyper-V Live Migration.
The Capabilities and Restrictions of Virtual Machine Migration
Before attempting to migrate a Hyper-V virtual machine between servers using import/export, there are some rules and restrictions that are useful to know about it advance.
Firstly, a virtual machine can only be exported if it is shut down or saved. A running or paused virtual machine cannot be migrated. Some readers may be familiar with the live migration capabilities of virtual solutions such as Xen and VMware VMotion which allow a running virtual machine to be moved from one server to another without any perceptible interruption of service. Whilst Microsoft are working on such a feature for Hyper-V, the current version supports only the static migration of a powered off virtual machine.
Secondly, the set of files comprising an exported virtual machine may only be imported once into a Hyper-V server. The reason for this is that the imported virtual machine will be stored and run from the location from which it was imported. The key advantage of this is that, whilst the export process can take a considerable amount of time to complete, the import is generally completed in a matter of seconds. If, however, an exported virtual machine is to be imported into multiple Hyper-V servers, separate copies of the export folder will need to be used for each import.
Thirdly, the Hyper-V Import feature is only able to import Hyper-V based virtual machines. The configuration format used by Virtual Server 2005 and Virtual PC is incompatible with that used by Hyper-V in this context.
Now that we have covered what Hyper-V cannot do, it is time to look at what it can do. Hyper-V can migrate any Hyper-V virtual machine from any Hyper-V server to any other Hyper-V server. The migrated virtual machine will include all the configuration information pertaining to the virtual machine, together with any virtual hard drives assigned to it. In addition, the export feature allows only the virtual machine's configuration to be exported, thereby excluding any virtual disk drives from the export package. This feature can be useful for situations where only the virtual machine's configuration needs to be duplicated on a different Hyper-V server.
In addition to virtual machine configuration and virtual disk image files, the Import/Export process will also transfer any existing snapshots for the virtual machine.
Exporting a Hyper-V Virtual Machine
The first step in exporting a Hyper-V virtual is to launch the Hyper-V Manager console (Start->Administration Tools->Hyper-V Manager). From within Hyper-V Manager, ensure that the virtual machine to be exported is either powered off or in a saved state by selecting it from the list of virtual machines and selecting the appropriate action from the Actions panel.
Once the virtual machine is power off or saved, click on the Export.. action link to display the Export Virtual Machine dialog as illustrated in the following figure:
Once the export dialog is displayed, the next step is to decide where to save the export files. The target location may be entered directly into the text field, or the Browse button used to navigate graphically to the target destination. The export location of the virtual machine can be any file system which is visible to the local Hyper-V server host system, including local disk drives, removable storage or remotely mounted volumes on the target Hyper-V Server. The only requirement is that the designated volume has sufficient free space to store the virtual machine configuration, virtual hard drives and snapshots. If only the configuration files for the virtual machine are to be exported, the Export only virtual machine configuration option should also be selected. Within the designated location, a sub-folder with the name of the virtual machine will be created to contain the exported data.
Once a suitable export location has been identified and specified, the export process may be invoked clicking on the Export button. During the export process the Operations entry for the selected virtual machine will change to Exporting followed by the current progress percentage. The duration of the export process will vary depending on factors such the performance and load of the host system, the size of any virtual disk drives and the number of snapshots associated with the virtual machine.
Once the Hyper-V Manager indicates that the export process has completed, navigate using Windows Explorer to the export location specified and review the files that have been created.
The Anatomy of a Hyper-V Virtual Machine Export
When a virtual machine has been exported, the following files and folders are created in the specified export location:
- config.xml - This file contains the basic configuration information for the virtual machine in XML format. The information recorded includes original locations of any virtual hard drives assigned to the virtual machine and some state information. If the Export only virtual machine configuration option was selected during the export process this is the only file which will be present in the folder. A typical file might appear as follows:
<?xml version="1.0" encoding="UTF-16" standalone="yes" ?> - <configuration> <SnapShotDataRoot type="string" /> <ExternalDataRoot type="string" /> - <vhd> <source type="string">C:\Users\Public\Documents\Hyper-V\Virtual hard disks\User Data Hard Disk.vhd</source> <target type="string" /> </vhd> - <vhd> <source type="string">C:\Users\Public\Documents\Hyper-V\Virtual hard disks\WinServer2008 Test.vhd</source> <target type="string" /> </vhd> <VmStateCopied type="bool">true</VmStateCopied> </configuration>
- Virtual Machines - The file contained within this folder is named using a combination of the virtual machine's globally unique identifier (GUID) and the .exp file extension. This file contains the detailed virtual machine configuration and is in binary format. When imported into the target Hyper-V server this binary information is converted to XML format.
- Virtual Hard Drives - This folder contains copies of any virtual hard drive file images associated with the exported virtual machine.
- Snapshot - Contains all snapshot data associated with the exported virtual machine including configuration files, saved state file, differencing disk image files and the memory image file.
If the option to export only the virtual machine configuration was selected, only the config.xml file and the .exp file in the Virtual Machines folder will be exported.
Importing a Hyper-V Virtual Machine
Once a Hyper-V virtual machine has been successfully exported, the next step is to import it into the target Hyper-V Server. If the files are not already on the target server, or are not accessible via a shared folder on the original server, begin by transferring the files to the target system.
Once the files are available on the target Hyper-V server, launch the Hyper-V Manager (Start->Administration Tools->Hyper-V Manager) and click on the Import Virtual Machine link in the Actions panel. This will display the Import Virtual Machine dialog as illustrated in the following figure:
Specify, or navigate to the folder containing the exported virtual machine files and then optionally elect to re-use the original virtual machine ID for the imported virtual machine. If the original virtual machine is to continue operating within the same Hyper-V infrastructure as the exported virtual machine this option is not recommended. Also note that once the virtual machine has been exported, the folder cannot be used to import a second time (since the new virtual machine will be using the folder for the imported virtual machine).
As the virtual machine is imported, a progress dialog will be displayed. Once the import is completed the dialog will close and the virtual machine is ready to run.