Hyper-V enables you to move VM details and VM storage to a new location. Moving a VM and moving a VM's storage are two important features you can use to manage your Hyper-V hosts.
In this recipe, you are going to move configuration details for the PSDirect
VM within the HV1
server. Then, you move the entire VM to another server, HV2
, and view the results. The two Hyper-V servers, HV1
and HV2
, were set up in the Installing and configuring the Hyper-V recipe. The VM, PSDirect
, was created in the Create a virtual machine recipe.
PSDirect
VM on HV1
and verify that it is turned off:Get-VM -Name PSDirect -Computer HV1
(Get-VM -Name PSDirect).ConfigurationLocation
Get-VMHardDiskDrive -VMName PSDirect | Format-Table -Property VMName, ControllerType, Path
C:PSDirectNew
folder:$MHT = @{ Name = 'PSDirect' DestinationStoragePath = 'C:PSDirectNew' } Move-VMStorage @MHT
(Get-VM -Name PSDirect).ConfigurationLocation Get-VMHardDiskDrive -VMName PSDirect | Format-Table -Property VMName, ControllerType, Path
HV2
:Get-VM -ComputerName HV2
HV1
and HV2
:Enable-VMMigration -ComputerName HV1, HV2
$SVHT = @{ UseAnyNetworkForMigration = $true ComputerName = 'HV1', 'HV2' VirtualMachineMigrationAuthenticationType = 'Kerberos' VirtualMachineMigrationPerformanceOption = 'Compression' } Set-VMHost @SVHT
HV2
:$Start = Get-Date $VMHT = @{ Name = 'PSDirect' ComputerName = 'HV1' DestinationHost = 'HV2' IncludeStorage = $true DestinationStoragePath = 'C:PSDirect' # on HV2 } Move-VM @VMHT $Finish = Get-Date
$OS = "Migration took: [{0:n2}] minutes" ($OS -f ($($Finish-$Start).TotalMinutes))
HV1
:Get-VM -ComputerName HV1
HV2
:Get-VM -ComputerName HV2
((Get-VM -Name PSDirect -Computer HV2).ConfigurationLocation) Get-VMHardDiskDrive -VMName PSDirect -Computer HV2 | Format-Table -Property VMName, Path
In step 1, you ensure that the PSDirect
VM is stopped, which looks like this:
In step 2, you view the VM configuration location for the PSDirect
VM, which looks like this:
With step 3, you view the details of the two virtual disk drives used by the PSDirect
VM. You created one drive when you installed the PSDirect
virtual machine (using the Creating a virtual machine recipe), and you created the second drive based on the Configuring VM hardware recipe. The output of this step looks like this:
In step 4, you move the PSDirect
VM and the VMs hard drives to the C:PSDirectNew
folder. There is no output from this step.
With step 5, you get the new location for the PSDirect
VM's configuration files and get the details of the VM's disks, including their new location, which looks like this:
Before you migrate the PSDirect
VM, in step 6, you view the VMs currently residing on HV2
, which looks like this:
In step 7, you enable VM migration on both HV1
and HV2
. In step 8, you configure VM migration on both servers. In step 9, you perform a migration of the PSDirect
VM from HV1
to HV2
. These three steps produce no output. In step 10, you display how long the migration took, which looks like this:
With the migration of the PSDirect
VM to HV2
completed, in step 11, you get the VMs on HV1
. Since the PSDirect
VM has been migrated, you have no VMs running in HV1
, thus there is no output from this step.
In step 12, you get the VMs running on HV2
, which shows the PSDirec
t VM is now running on this server (in addition to the five VMs you saw in step 6), as follows:
In the final step, you examine the configuration location for the PSDirect
VM (on HV2
), and the disk details for this VM's two disks, which looks like this:
In this recipe, you first view the storage location details of a VM, before moving the VM and again after. You first move the PSDirect
VM within the HV1
VM, then you move the VM to a different server, HV2
.
In step 3, you moved the storage for the PSDirect
VM. If you had an RDP connection open to the PSDirect
VM, you would have seen the VM functioning normally during the migration. You may have seen a brief flicker as the VM movement completes and Hyper-V begins to use the new VM details.
In this recipe, HV1
and HV2
are two non-clustered systems. In step 8, you move the PSDirect
VM from HV1
to HV2
. In this case, since there is no shared storage involved with the VMs, Hyper-V needs to perform a full storage migration migrating the storage between the two servers. If you store the VM on shared storage, for example, using an SMB Scale-Out File Server or storing VHDX files on an iSCSI server, moving a VM between cluster nodes is significantly faster.
At the completion of the VM movement in step 8, Hyper-V drops connectivity to the VM on HV1
and establishes it on HV2
. This means that for a moment, you lose connectivity to the VM. If you open an RDP connection into the PSDirect
VM before you move the VM, you can see that as the movement finishes, the connection stops for a moment, then reappears with the VM running on HV2
. Using VMConnect would mean having to reopen the connection on the other Hyper-V host.
You could also open up a PowerShell window on another system, say DC1
, and ping the VM continuously during the movement of the VM. You may notice a moment of dropped pings, before they pick up again once the live migration has completed. An application running on the PSDirect
VM would be unaffected by the momentary loss of connectivity during the move.
3.18.220.243