Migrating Hyper-V Virtual Machines Using Import/Export
The Hyper-V Import/Export feature allows virtual machines to be migrated from one Hyper-V server to another. In this chapter of Hyper-V Essentials we will cover the concept of virtual machine migration in detail.
The Capabilities and Restrictions of Virtual Machine Migration
Before attempting to migrate a Hyper-V virtual machine between servers 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, an exported virtual machine may only be imported by one Hyper-V server. It is not possible, therefore, to import an exported virtual machine into multiple servers.
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.
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 sever host system, including local disk drives, removal storage or remotely mounted volumes on the target Hyper-V Server. The only requirement is that the designated volume have 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 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 folders 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.