Installing and configuring Hyper-V

With Windows Server 2019, to add Hyper-V to your server, you install the Hyper-V feature. This recipe installs Hyper-V on two servers: HV1 and HV2, which are domain-joined Windows 2019 servers with no added features.

Getting ready

In this recipe, you do the set up remotely from a client machine, CL1, using the Hyper-V cmdlets and PowerShell's remoting capabilities. CL1 is a domain-joined Windows 10 system with the RSAT tools installed. You previously set up the CL1 client in the Installing RSAT tools on Windows 10 and Windows Server 2019 recipe.

How to do it...

  1. From CL1, install the Hyper-V feature on HV1 and HV2:
    $Sb = {
      Install-WindowsFeature -Name Hyper-V -IncludeManagementTools
    }
    Invoke-Command -ComputerName HV1, HV2 -ScriptBlock $Sb
  2. Reboot both servers to complete the installation:
    Restart-Computer -ComputerName HV1, HV2 -Force 
  3. Create a PSSession with both HV servers (after the restart has completed):
    $S = New-PSSession HV1, HV2
  4. Create and set the location for VMs and VHDs on HV1 and HV2, then view the results:
    $Sb = {
        New-Item -Path C:Vm -ItemType Directory -Force |
            Out-Null
        New-Item -Path C:VmVhds -ItemType Directory -Force |
            Out-Null
        New-Item -Path C:VmVMs -ItemType Directory -force |
            Out-Null
        Get-ChildItem -Path C:Vm }
    Invoke-Command -ScriptBlock $Sb -Session $S
  5. Set default paths for Hyper-V VM hard disks and VM configuration information:
    $SB = {
      $VMs  = 'C:VmVhds'
      $VHDs = 'C:VmVMsManaging Hyper-V'
      Set-VMHost -ComputerName Localhost -VirtualHardDiskPath $VMs
      Set-VMHost -ComputerName Localhost -VirtualMachinePath $VHDs
    }
    Invoke-Command -ScriptBlock $SB -Session $S
  6. Set up NUMA spanning:
    $SB = {
      Set-VMHost -NumaSpanningEnabled $true
    }
    Invoke-Command -ScriptBlock $SB -Session $S
  7. Set up EnhancedSessionMode:
    $SB = {
     Set-VMHost -EnableEnhancedSessionMode $true
    }
    Invoke-Command -ScriptBlock $SB -Session $S
  8. Set up host resource metering on HV1, HV2:
    $SB = {
     $RMInterval = New-TimeSpan -Hours 0 -Minutes 15
      Set-VMHost -ResourceMeteringSaveInterval $RMInterval
    }
    Invoke-Command -ScriptBlock $SB -Session $S
  9. Review key VMHost settings:
    $SB = {
      Get-VMHost 
     }
    $P = 'Name', 'V*Path','Numasp*', 'Ena*','RES*'
    Invoke-Command -ScriptBlock $SB -Session $S |
      Format-Table -Property $P 

How it works...

In step 1, you use the Install-WindowsFeature cmdlet to install Hyper-V on HV1 and HV2 remotely, which looks like this:

How it works...

In step 2, you reboot HV1 and HV2, which completes the process of installing Hyper-V on both servers. There is no output from this step.

After the reboot, in step 3, you create a remoting session on both HV1 and HV2. You use this in the following steps, but there is no output.

In step 4, you create new folders to hold virtual machines and virtual hard drives on both servers. The output of this step looks like this:

How it works...

In step 5, you configure Hyper-V to save VMs and VHDs in the newly created folder on both servers. In step 6, you configure Hyper-V to support NUMA. In step 7, you configure EnhancedSessionMode. In step 8, you configure host resource metering. These four steps produce no output.

In step 9, you look to see how HV1 and HV2 are configured, which looks like this:

How it works...

There's more...

In step 1, you install the Hyper-V feature on two servers. You can only do this successfully if the host you are using supports the necessary virtualization capabilities and you have enabled them in your system's BIOS. To ensure if your system is capable, see this link: http://mikefrobbins.com/2012/09/06/use-powershell-to-check-for-processor-cpu-second-level-address-translation-slat-support/. Additionally, ensure you double-check the BIOS to ensure virtualization is enabled prior to running this step.

In step 2, you restart both servers. You could have allowed Install-WindowsFeature (used in step 1) to restart the servers automatically by using the -Restart switch. In automation terms, this could have meant that the system started rebooting before the remote script had completed, which could cause Invoke-Command to error out. The recipe avoids this by not rebooting after the installation of the Hyper-V features, then rebooting in a controlled way. Once the restart has completed, your script can carry on managing the servers.

In step 5 through step 8, you set up one aspect of the VM hosts. You could have combined these steps and just called Set-VMHost once with all of the properties specified.

See also

You can find more information on some of the Hyper-V features used in this recipe (details of which are outside the scope of this book), as follows:

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

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