Configuring VM and storage movement

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.

Getting ready

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.

How to do it...

  1. View the PSDirect VM on HV1 and verify that it is turned off:
    Get-VM -Name PSDirect -Computer HV1
  2. Get the VM configuration location:
    (Get-VM -Name PSDirect).ConfigurationLocation 
  3. Get virtual hard drive locations:
    Get-VMHardDiskDrive -VMName PSDirect | 
      Format-Table -Property VMName, ControllerType, Path
  4. Move the VM's storage to the C:PSDirectNew folder:
    $MHT = @{
      Name                   = 'PSDirect'
      DestinationStoragePath = 'C:PSDirectNew'
    }
    Move-VMStorage @MHT
  5. View the configuration details after moving the VM's storage:
    (Get-VM -Name PSDirect).ConfigurationLocation
    Get-VMHardDiskDrive -VMName PSDirect | 
      Format-Table -Property VMName, ControllerType, Path
  6. Get the VM details for the VMs from HV2:
    Get-VM -ComputerName HV2
  7. Enable VM migration from both HV1 and HV2:
    Enable-VMMigration -ComputerName HV1, HV2
  8. Configure VM migration on both hosts:
    $SVHT = @{
      UseAnyNetworkForMigration                 = $true
      ComputerName                              = 'HV1', 'HV2'
      VirtualMachineMigrationAuthenticationType = 'Kerberos'
      VirtualMachineMigrationPerformanceOption  = 'Compression'
    }
    Set-VMHost @SVHT
  9. Move the VM to HV2:
    $Start = Get-Date
    $VMHT = @{
        Name                   = 'PSDirect'
        ComputerName           = 'HV1'
        DestinationHost        = 'HV2'
        IncludeStorage         = $true
        DestinationStoragePath = 'C:PSDirect' # on HV2
    }
    Move-VM @VMHT
    $Finish = Get-Date
  10. Display the time taken to migrate:
    $OS = "Migration took: [{0:n2}] minutes"
    ($OS -f ($($Finish-$Start).TotalMinutes))
  11. Check which VMs on are on HV1:
    Get-VM -ComputerName HV1
  12. Check the VMs on HV2:
    Get-VM -ComputerName HV2
  13. Look at the details of the moved VM:
    ((Get-VM -Name PSDirect -Computer HV2).ConfigurationLocation)
    Get-VMHardDiskDrive -VMName PSDirect -Computer HV2  |
      Format-Table -Property VMName, Path 

How it works...

In step 1, you ensure that the PSDirect VM is stopped, which looks like this:

How it works...

In step 2, you view the VM configuration location for the PSDirect VM, which looks like this:

How it works...

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:

How it works...

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:

How it works...

Before you migrate the PSDirect VM, in step 6, you view the VMs currently residing on HV2, which looks like this:

How it works...

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:

How it works...

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 PSDirect VM is now running on this server (in addition to the five VMs you saw in step 6), as follows:

How it works...

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:

How it works...

There's more...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.18.220.243