Hyper-V Migration Guide: Migrating Hyper-V
Updated: February 11, 2010
Applies To: Windows Server 2008, Windows Server 2008 R2
Migrate the Hyper-V Role
The steps to migrate the Hyper-V role are the same for all of the scenarios defined in “Supported migration scenarios,” earlier in this guide.
Perform migration steps on the source server
To perform migration steps on the source server
Prepare the virtual machines for migration by either turning off the virtual machines or saving the state of each one. If the source server is running Hyper-V version 1 (KB950050) or if the processors of the destination server are not compatible with the source server (as described in “Migration scenarios that are not supported,” earlier in this guide), turn off the virtual machines. If the source server is running Hyper-V in Windows Server 2008 R2 and the processors in the destination and source servers are compatible, save the state of the virtual machines.
Open a Windows PowerShell session with elevated user rights. To do this, click Start, click All Programs, click Accessories, open the Windows PowerShell folder, right-click Windows PowerShell, and then click Run as administrator.
Load Windows Server Migration Tools into your Windows PowerShell session.
If you opened the current Windows PowerShell session by using the Windows Server Migration Tools shortcut on the Start menu, skip this step. Only load the Windows Server Migration Tools snap-in into a Windows PowerShell session that was opened by using some other method (and into a session where it has not already been loaded). To load Windows Server Migration Tools, type the following, and then press ENTER.
Add-PSSnapin Microsoft.Windows.ServerManager.Migration
From Windows PowerShell, collect data from the source server by running the Export-SmigServerSetting cmdlet as an administrator. The Export-SmigServerSetting cmdlet creates an XML file, StoragePathMappings.xml, that contains information about where the virtual machine storage (.vhd and .avhd) files and saved states (.bin and .vsv) are stored, in the form of folder paths on the source server. The import process uses the StoragePathMappings.xml file to associate the storage and saved state files to the appropriate virtual machines on the destination server. If the destination server will use the same drive mapping and folder structure for virtual machine storage and saved state files as the source server, you do not need to edit the file after the Export-SmigServerSetting cmdlet creates it. Otherwise, you must edit this file before you import it to the destination server. Before you run this command, review the following information to determine the information to include in the command:
Determine where to store StoragePathMappings.xml. The -Path parameter is a required parameter that specifies the location. You can either choose a location that can be accessed by both the source server and the destination server, such as a network location, or copy it from the source server to the destination server.
To export user groups, which are used for access control by the Hyper-V security policy and the Hyper-V remote management tools, include the -User and -Group parameters:
-User <Enabled | Disabled | All> -Group
To recreate the same IP settings on the physical network adapters on the destination server as are configured on the source server, include the -IPConfig parameter. The -IPConfig parameter collects IP information when it is used with the Export-SmigServerSetting cmdlet on the source server. The -IPConfig parameter applies settings when the Import-SmigServerSetting cmdlet is used on the destination server.
-IPConfig
After you determine the parameters, run the Export-SmigServerSetting cmdlet, where <storepath> specifies the path to the folder where the configuration data file (Svrmig.mig) will be stored. (For example, C:\Migration.) The StoragePathMappings.xml file is created in a subfolder of the <storepath> folder, named VirtualMachines. (For example, C:\Migration\VirtualMachines.)
Export-SmigServerSetting -FeatureId Hyper-V -IPConfig -User All -Group -path <storepath> -Verbose
Migrate virtual machine data
The following steps show you how to use Robocopy and a Windows PowerShell script to copy the data from the source server to the destination server. The script parses the folder paths specified in the StoragePathMappings.xml to migrate the data. You can use the StoragePathMappings.xml file stored under <storepath> as a reference to determine which folders need to be transferred.
Important
If you want to use a different drive mapping and/or folder structure on the destination server, edit the StoragePathMappings.xml file before you attempt to migrate the data to the destination server.
To migrate virtual machine data
Copy the data from the source server to the destination server. The recommended way to do this is to use the Robocopy command. You can run the command for each file and specify the source and destination locations. (You can use the StoragePathMappings.xml file to determine the source paths.) Or, you can automate this process by using a Windows PowerShell script. Before you run the script, update the StoragePathMappings.xml file with the locations where you want to paste the files on the destination server. The script can parse the StoragePathMappings.xml file and then call the Robocopy command to copy and paste the files.
The following is an example of such a script. To use this sample, copy the code and paste it into a text editor, then save the file with a .ps1 file name extension in a directory where you want to run the script from. For example, save CopyData.ps1 to C:\migration\.
param( [string]$xmlFilePath = $(throw "Must pass the fully qualified file name of Storage Path XML in the command string"), [string]$destinationHost = $(throw "Must pass the Destination Host Name (NetBiosName), where the files will be copied to") ) Write-Host "XML File Path: " $xmlFilePath Write-Host "Destination Host Name: " $destinationHost # Get the content of the XML file [xml]$xmlFile = Get-content $xmlFilePath # For each storage path, if the "Copy" attribute is true copy the files to the destination Host. foreach ($storagePath in $xmlFile.StoragePaths.storagePath) { if($storagePath.Copy -eq "true") { # Get the Source directory $sourceDirectory = $storagePath.Source # Get the Destination directory $destinationDirectory = $storagePath.Destination $destinationDirectory = $destinationDirectory -replace ":","$" $destinationDirectory = "\\" + $destinationHost + "\" + $destinationDirectory # Copy the files to the destination host robocopy $sourceDirectory $destinationDirectory /E /XF *.xml /R:5 /W:60 /V } }
To run the script, type the full path to the script at the command prompt and pass the fully qualified file name of the StoragePathMappings.xml file (full path and file name) and the name of the destination server as parameters. The file name extension of the script is optional. For more information, see Support for Scripting (https://go.microsoft.com/fwlink/?LinkID=178144).
For example, if you used the folder and file name example shown above, type:
c:\migration\copyData.ps1 <XMLPathName> <DestinationServerName>
Disconnect the source server from the network so that you avoid any potential MAC address conflicts between the virtual machines on the source and destination servers. MAC address conflicts may impact the availability of the workloads that run on the virtual machines.
Perform migration steps on the destination server
If the <storepath> is located anywhere other than locally on the destination server, edit the permissions of the shared folder to grant Full Control to the following accounts:
The user account that will run the import and export commands. If the same account is used, only one entry is required.
The computer account of the source server.
The computer account of the destination server.
If you used another method instead of the Robocopy command to copy data to the destination server, check the destination folder and delete any .xml files that were copied to that folder.
Open a Windows PowerShell session with elevated user rights. To do this, click Start, click All Programs, click Accessories, open the Windows PowerShell folder, right-click Windows PowerShell, and then click Run as administrator.
Load Windows Server Migration Tools into your Windows PowerShell session.
If you opened the current Windows PowerShell session by using the Windows Server Migration Tools shortcut on the Start menu, skip this step. Only load the Windows Server Migration Tools snap-in into a Windows PowerShell session that was opened by using some other method (and into a session where it has not already been loaded). To load Windows Server Migration Tools, type the following, and then press ENTER.
Add-PSSnapin Microsoft.Windows.ServerManager.Migration
To import the Hyper-V settings to the destination server, run the Import-SmigServerSetting cmdlet and all additional parameters that you used with the Export-SmigServerSetting.
Import-SmigServerSetting -FeatureId Hyper-V <additionalparameters> -path <storepath> -Verbose -Force
Additional parameters:
To import the same IP settings on the destination server that were on the source server, where <SourcePhysicalAddress-1> and <SourcePhysicalAddress-2> are comma-separated lists of the physical addresses of the source network adapter, and <TargetPhysicalAddress-1> and <TargetPhysicalAddress-2> are comma-separated lists of the physical addresses of the destination network adapter, include:
-IPConfig All -SourcePhysicalAddress "<SourcePhysicalAddress1>","<SourcePhysicalAddress2>" -TargetPhysicalAddress "<TargetPhysicalAddress1>","<TargetPhysicalAddress2>"
To import the user groups that are used by the Hyper-V security policy and remote administration, include:
-User <Enabled | Disabled | All> -Group
If a failure occurred while running the Import-SmigServerSetting cmdlet, review the Setupact.log and Setuperr.log under %localappdata%\SvrMig\Log.
Use the information you gathered about physical-to-virtual network connections to establish the connections between the physical network adapters and external virtual networks on the destination server. All external virtual networks are migrated to the destination server as internal virtual networks because the import process cannot map virtual networks to physical networks. To establish the connections:
Open Hyper-V Manager. (Click Start, point to Administrative Tools, and then click Hyper-V Manager.)
In the Action pane, click Virtual Network Manager.
In the left pane, under Virtual Networks, click the name of the first internal network that you want to convert to an external network.
In the right pane, under Connection type, select External. From the drop-down list, select the physical network adapter to use for access to the physical network.
Click OK to save the changes and close Virtual Network Manager, or click Apply to save the changes and modify another virtual network.
For each virtual machine that used a physical disk connected directly to the physical computer, establish this connection on the destination server:
Open the Disk Management snap-in and verify that the disk is in an Offline state. If the disk is not in an Offline state, it will not be available when configuring storage for a virtual machine.
Open Hyper-V Manager. (Click Start, point to Administrative Tools, and then click Hyper-V Manager.)
Under Virtual Machines, select the virtual machine that you want to connect to the physical disk.
In the Action pane, under the virtual machine name, click Settings.
In the navigation pane (left pane), click the controller that you want to attach the disk to. If you plan to use the disk as a startup disk, make sure you attach it to an IDE controller. Click Add.
On the Hard Drive page, select the location on the controller to attach the disk.
Under Media, specify the physical hard disk. If the disk does not appear in the drop-down list under Physical hard disks, make sure the disk is in an Offline state in Disk Management.
Select Physical hard disk, and then click OK.
Restore any customizations you made to the WMI namespace security settings. For more information, see WMI namespace security customizations are missing after upgrading to Windows Server 2008 R2(https://go.microsoft.com/fwlink/?LinkId=178143).
If you turned off any exceptions in Windows Firewall on the source server, turn off those same exceptions on the destination server.
If you have granted remote access to the server for Hyper-V management to any user account that is not a member of the Administrators group or Distributed COM Users group, open the registry and navigate to the HKLM\Software\Microsoft\OLE\ key. Add the MachineLaunchRestriction value that you recorded from the source server.
Warning
Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.
See Also
Concepts
Hyper-V Migration Guide
Hyper-V Migration Guide: Preparing to Migrate
Hyper-V Migration Guide: Verifying the Migration
Hyper-V Migration Guide: Post-Migration Tasks