Tuesday, 21 May 2019

Installing Microsoft Hyper-V Server 2016

Intro


In case you are not aware...

Microsoft Hyper-V Server 2016
is NOT
Microsoft Windows Server 2016 with Hyper-V role enabled.

Microsoft Hyper-V Server 2016 by itself has no GUI. It looks like Server Core installations. But when properly configured, it can be managed by Hyper-V Manager, SCVMM, Windows Admin Center.

Microsoft Windows Server 2016 with Hyper-V requires Windows Server license.
Microsoft Hyper-V Server 2016 is free (to use as a hypervisor; we are not supposed to configure it as a web server, file server, etc).

In other words, in terms of licensing...
  • Microsoft Hyper-V Server 2016 running a CentOS 7 virtual machine: free.
  • Microsoft Windows Server 2016 with Hyper-V running a CentOS 7 virtual machine: need to license the host which is running Windows Server.
  • Microsoft Hyper-V Server 2016 running a Windows virtual machine: need to license the virtual machine which is running Windows.
  • Microsoft Windows Server 2016 with Hyper-V running a Windows Server 2016 virtual machine: need to license both the host and the virtual machine which are running Windows Server. But since a single license can be used on 2 OSEs, we need to buy only 1 license: 1 OSE for the host, 1 OSE for the VM.
This means a Microsoft Hyper-V Server 2016 running CentOS VMs is free, in terms of licensing.

Why do I want to run a Linux VM in Hyper-V? Because Hyper-V has a cool feature called "Hyper-V Replica" which allows us to replicate a VM to another Hyper-V, over a slow link.

Here's is my situation: I need to run a Linux server. The server does not need to be 100% highly available, but it would be good to be able to bring the services up quickly when the server goes down. Traditional highly-available solutions require a shared storage, and high speed connection (usually 10gbps types of speed) between storage nodes and compute nodes. Software-defined-Storage solutions (Microsoft's "Storage Spaces Direct", Storpool, etc) allows us to use commodity hardware instead of expensive SANs, but we still need the expensive 10gbps network. I'm not going to spend so much money on a 10gbps network, just to run my Linux server. So I run my Linux server as a VM in Microsoft Hyper-V Server, get another box and install Microsoft Hyper-V Server too, and use "Hyper-V Replica" to replicate my Linux VM to the second Microsoft Hyper-V Server, over the cheap, regular 1gbps network.

"Hyper-V Replica" does not have automatic failover. Failover has to be performed by a human, either using Hyper-V Manager or PowerShell. If using Hyper-V Manager, it looks something like this...
Failover options of a replicated VM

Installing Hyper-V Server 2016


Download the ISO from Microsoft (https://www.microsoft.com/en-us/evalcenter/evaluate-hyper-v-server-2016), boot server using ISO, and install. The following screenshots show the relatively straightforward process. (Not all steps are shown. It is similar to installing the Windows Server.)
Choose your Language and Region...
Click "Install now".
Agree with the EULA, click "Next".
Choose the installation location.
Installation in progress...
When the installation is done, you'll be asked to set the administrator's password.
Choose "OK" to set administrator's password.
Key in password twich, (use "Tab" to move the cursor) and "Enter".
Password is set. Choose "OK".
Immediately after setting the password, you will be presented with a text-based menu to help you with some simple configuration of the server.
Some simple configuration options.
Configuring the IP address.
Enabling Remote Desktop to this Hyper-V Server.
The GUI is basic. We start with 2 Windows: a command prompt and a PowerShell running the basic configuration options.
Notice that in the screenshot, we are connecting to the Hyper-V Server using Remote Desktop.

Creating a VM


First we need to create a virtual switch. The PowerShell command looks like this...

New-VMSwitch -name VirtualSwitchWan  -NetAdapterName Ethernet -AllowManagementOS $true
Creating a virtual switch.
Notice  that we use the command "start powershell" in the command prompt window to create a new PowerShell window.
In this example, we will be creating a Linux VM. We need to download the ISO. Use commands...
mkdir C:\ISO
... create the folder to store the ISO file, and download it using command....
Invoke-WebRequest -UseBasicParsing -Uri http://mirror.vodien.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso -OutFile "C:\ISO\CentOS-7-x86_64-Minimal-1810.iso"

We can create the VM using the commands...

New-VM -Name "LinuxVm" -MemoryStartupBytes 4294967296 -NewVHDPath "C:\VirtualMachines\LinuxVm\LinuxVm.vhdx" -NewVHDSizeBytes 107374182400 -Generation 1 -Path "C:\VirtualMachines\LinuxVm" -SwitchName "VirtualSwitchWan"

Attach the ISO to the VM, set a static MAC address (optional but useful when we need to failover Linux VMs from one Hyper-V server to another), and start the VM.

Set-VMDvdDrive -VMName "LinuxVm" -Path "C:\ISO\CentOS-7-x86_64-Minimal-1810.iso"

Set-VMNetworkAdapter -VMName "LinuxVm" -StaticMacAddress "4e38b009fbcf"

Start-VM -VMName "LinuxVm"

Creating a VM using PowerShell. (Nothing much to see...)

Connecting to the VM


In a server with a full GUI, i.e. Microsoft Windows Server 2016 (Full Desktop Experience) with Hyper-V role enabled, VMConnect.exe is used to connect to the VM, and display what's in the VM.

Hyper-V Server 2016 has no VMConnect.exe. 

We will be connecting to the VM using Remote Desktop. We will Remote Desktop to the Hyper-V Server with a specially crafted RDP file, which will make the Hyper-V Server show us what's in the VM.

First, get the VMId...
Get-VM -Name "LinuxVm" | select *
Getting the VMId.
In this example, the VMId is "cd63d737-6794-43bf-8d2a-059bfedd1080".
Create a RDP file (it is just a text file), with the contents...

full address:s:43.229.128.101
pcb:s:cd63d737-6794-43bf-8d2a-059bfedd1080
server port:i:2179
negotiate security layer:i:0

... where "43.229.128.101" is the IP address of the Hyper-V Server, "cd63d737-6794-43bf-8d2a-059bfedd1080" is the VMId of the VM we want to connect to.
Creating the RDP file using Notepad.
We use Remote Desktop client to open our specially crafted RDP file...
Launch "Remote Desktop". Click "Open".
Open our specially crafted RDP file.
Click "Connect".
Key in credentials in the Hyper-V Server.
Remote Desktop to the Hyper-V Server, but displaying what's in the VM.
We can now install our CentOS in the usual manner.

We have installed Hyper-V Server, which is free, and having only very basic GUI. We created a VM, connected to VM using Remote Desktop, and continued with the installation of the VM.