Hyper-V Home Lab Setup and Configuration

Hyper-V Home Lab Setup – A How To

If you prefer video over written format the corresponding video for this write-up can be viewed below:

Here is all the PowerShell code required for the Hyper-V Home Lab Setup if you just require a quick reference.  The code below can be used to fully setup and configure a Hyper-V server with only minor adjustments needing to be made for your specific hardware.  This is not a full script, just code examples of how to accomplish the setup and configuration via PowerShell.   A full write-up with examples can be found below.

#------------------------------------------------------
#check currently installed roles
Get-WindowsFeature | where {$_.installed -eq "True"}
#------------------------------------------------------

#------------------------------------------------------
#install the Hyper-V Role
Install-WindowsFeature Hyper-V -IncludeManagementTools -Restart -Verbose
#------------------------------------------------------

#----------------NIC TEAMING----------------------------
# This will loop through and get all available NICs and add them to the team
$NICname = Get-NetAdapter | %{$_.name}
# New Network Team
New-NetLbfoTeam -Name PublicNetTeam –TeamMembers $NICname -TeamingMode SwitchIndependent -LoadBalancingAlgorithm HyperVPort -Confirm:$false
Start-Sleep -s 15
$netadapter = Get-NetAdapter -Name PublicNetTeam;
$netadapter | Set-NetIPInterface -DHCP Disabled;
#we will now set the IP, gateway, and DNS of the new PublicNetTeam
$Script:primaryIP = "10.0.3.50"
$Script:pNetMask = "24"
$Script:pgateway = "10.0.3.1"
$Script:dns1 = "10.0.3.189"
$Script:dns2 = "10.0.3.1"
$netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress $Script:primaryIP -PrefixLength $Script:pNetMask -Type Unicast -DefaultGateway $Script:pgateway | Out-Null;
Set-DnsClientServerAddress -InterfaceAlias PublicNetTeam -ServerAddresses $Script:dns1,$Script:dns2 | Out-Null
#---------------END NIC TEAMING-------------------------

#------------------------------------------------------
#create new virtual switch
New-VMSwitch -NetAdapterName PublicNetTeam -Name "PublicVSwitch" -AllowManagementOS $true -Confirm:$false
#------------------------------------------------------

#------------------------------------------------------
#Set Default HYPER-V locations
SET-VMHost -virtualharddiskpath V:\VHDs
Set-VMHost -virtualmachinepath V:\VMs
#------------------------------------------------------

Hyper-V Home Lab Setup – Step by Step

1. Install Server OS and add the Hyper-V Role

PowerShell method:

#------------------------------------------------------
#check currently installed roles
Get-WindowsFeature | where {$_.installed -eq "True"}
#------------------------------------------------------

#------------------------------------------------------
#install the Hyper-V Role
Install-WindowsFeature Hyper-V -IncludeManagementTools -Restart -Verbose
#------------------------------------------------------

GUI Method:

If you have access to an MSDN Subscription a Datacenter edition will be an ideal choice.  VMs will auto activate against this version so you don’t have to worry about any licensing issues for any of your guests.  If you don’t have access to a Datacenter license you may want to explore setting up the free edition of Hyper-V, Hyper-V Core.  I have a write-up on Hyper-V Core Cluster Home Lab Setup if you prefer to go that route.

 

2012 R2 Datacenter System Info

2012 R2 Datacenter System Info

With the OS of your choice loaded, open Server Manager – Add Roles and Features – and add the Hyper-V Role.

2012R2 Add Roles and Features - Hyper-V

2012R2 Add Roles and Features – Hyper-V

The wizard that follows will allow you to set several Hyper-V options during the Add Role process. On this screen you can configure a virtual switch and associate your NICs with that virtual switch.

2012R2 Add Roles and Features - Hyper-V - Virtual Switches

2012R2 Add Roles and Features – Hyper-V – Virtual Switches

Live migration is a fantastic Hyper-V feature which allows you to move running VMs from one Hyp node to another. However, the Live Migration requirements aren’t always suitable for a home lab setting so we will be leaving this at default settings for now.

2012R2 Add Roles and Features - Hyper-V - Migration

2012R2 Add Roles and Features – Hyper-V – Migration

This will permit you to set the default settings for your VM configuration files and VM VHDs/VHDXs. When you go to create a new VM these are the default locations that will populate in the VM creation wizard.

2012R2 Add Roles and Features - Hyper-V - Default Stores

2012R2 Add Roles and Features – Hyper-V – Default Stores

When ready select the restart button and click finish – yes. The Hyper-V role will be added and your server will automatically reboot.

2012R2 Add Roles and Features - Hyper-V - Confirmation

2012R2 Add Roles and Features – Hyper-V – Confirmation

2. Configure NIC teaming (as required)

PowerShell method:

#----------------NIC TEAMING----------------------------
# This will loop through and get all available NICs and add them to the team
$NICname = Get-NetAdapter | %{$_.name}
# New Network Team
New-NetLbfoTeam -Name PublicNetTeam –TeamMembers $NICname -TeamingMode SwitchIndependent -LoadBalancingAlgorithm HyperVPort -Confirm:$false
Start-Sleep -s 15
$netadapter = Get-NetAdapter -Name PublicNetTeam;
$netadapter | Set-NetIPInterface -DHCP Disabled;
#we will now set the IP, gateway, and DNS of the new PublicNetTeam
$Script:primaryIP = "10.0.3.50"
$Script:pNetMask = "24"
$Script:pgateway = "10.0.3.1"
$Script:dns1 = "10.0.3.189"
$Script:dns2 = "10.0.3.1"
$netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress $Script:primaryIP -PrefixLength $Script:pNetMask -Type Unicast -DefaultGateway $Script:pgateway | Out-Null;
Set-DnsClientServerAddress -InterfaceAlias PublicNetTeam -ServerAddresses $Script:dns1,$Script:dns2 | Out-Null
#---------------END NIC TEAMING-------------------------

GUI Method:

If you have more than one NIC I recommend that you team them.  The decision to do this will be largely influenced by your home lab switch equipment, but if you have a half-way decent managed switch it’s a good idea to team them.  I highly recommend that you take a few moments to watch John Savill’s discussion on teaming: Using NIC Teaming and a virtual switch for Windows Server 2012 host networking

Open Server Manager – browse to Local Server and locate NIC Teaming and click Disabled.

2012R2 Server Manager - Local Server - NIC Teaming

2012R2 Server Manager – Local Server – NIC Teaming

Create a new NIC Team.

2012R2 Server Manager - Local Server - New Team

2012R2 Server Manager – Local Server – New Team

Associate your NIC adapters with the new team.  I advise you include all adapters. If you watched John’s video referenced above you can see why this method might prove beneficial.  The settings you choose for the Teaming Mode and Load Balancing Mode will likely be influenced by your switch hardware so I suggest you consult the switch’s documentation for the most appropriate setting.  In most cases this will be Switch Independent with Hyper-V port.  As I am using John’s method above there will be no standby NICs, all NICs will be active.

2012R2 Server Manager - Local Server - New Team - NIC Teaming

2012R2 Server Manager – Local Server – New Team – NIC Teaming

3. Create a virtual switch

PowerShell method:

#------------------------------------------------------
#create new virtual switch
New-VMSwitch -NetAdapterName PublicNetTeam -Name "PublicVSwitch" -AllowManagementOS $true -Confirm:$false
#------------------------------------------------------

GUI Method:

Open up your Hyper-V Manager and click Virtual Switch Manager…

2012R2 Server Manager - Hyper-V Manager - Virtual Switch Manager

2012R2 Server Manager – Hyper-V Manager – Virtual Switch Manager

Create a new External virtual switch

2012R2 Server Manager - Hyper-V Manager - Virtual Switch Manager - New Virtual Network Switch

2012R2 Server Manager – Hyper-V Manager – Virtual Switch Manager – New Virtual Network Switch

Associate the virtual switch with your PublicNetTeam interface.  In my example I teamed two NICs (Ethernet, Ethernet 2) to PublicNetTeam. So, when creating the Virtual Switch I selected: Microsoft Network Adapter Multiplexor Driver

You can get this information by opening PowerShell and running the Get-NetAdapter command

name                      InterfaceDescription
----                      --------------------
Ethernet 2                Intel(R) 82574L Gigabit Network Connection #2
Ethernet                  Intel(R) 82574L Gigabit Network Connection
PublicNetTeam             Microsoft Network Adapter Multiplexor Driver

2012R2 Server Manager - Hyper-V Manager - Virtual Switch Manager - Virtual Switch Properties

2012R2 Server Manager – Hyper-V Manager – Virtual Switch Manager – Virtual Switch Properties

4. Format storage

Format your storage to accomadate your guest VMs.  Your Hyper-V host may have various forms of storage including SSDs or traditional spindle drives and various RAID configurations.  Format disks dependent on your use case and performance requirements.  I typically run the VMs boot disks and config files off of SSDs and any secondary VHDs/VHDXs the VMs have are stored on traditional spindle drives.  Microsoft recommends you format the drives as 64KB for Hyper-V VM use.

2012R2 - Disk Management

2012R2 – Disk Management

5. Set default VM storage locations

PowerShell method:

#------------------------------------------------------
#Set Default HYPER-V locations
SET-VMHost -virtualharddiskpath V:\VHDs
Set-VMHost -virtualmachinepath V:\VMs
#------------------------------------------------------

GUI Method:

A VM has a variety of configuration files as well as at least one (and possible several secondary) VHDs/VHDXs.  Set the defaults for where you would like these to be stored:

VM
State                 : Running
Path                  : V:\VMs\PracticeVM
ConfigurationLocation : V:\VMs\PracticeVM
SnapshotFileLocation  : V:\VMs\PracticeVM
SmartPagingFilePath   : V:\VMs\PractiveVM
VHDs
Path         : V:\VHDs\PracticeVM\PracticeVM.vhdx
VMName       : PracticeVM
Path         : D:\VMDataDrives\PracticeVM\SecondaryDrive.vhdx
VMName       : PracticeVM

2012R2 - Hyper-V Manager - New Virtual Machine Wizard - VM Store Defaults

2012R2 – Hyper-V Manager – New Virtual Machine Wizard – VM Store Defaults

After you change the setting in Hyper-V Manager – Hyper-V Settings – Virtual Hard Disks \ Virtual Machines you will see the change reflected the next time you go to create a new VM:

2012R2 - Hyper-V Manager - New Virtual Machine Wizard - VM Store Defaults Changed

2012R2 – Hyper-V Manager – New Virtual Machine Wizard – VM Store Defaults Changed

 

Your server should now be ready to create new VMs.  Questions/Comments?  Feel free to leave them below and check out the associated video above for additional information.

1 Response

  1. Justin says:

    Hi there,

    May I ask if you used physical hardware to perform this setup, or used a type 2 hypervisor like VMware Workstation or Oracle’s VirtualBox?

    As you may probably be aware there is a known issue using Nic Team’s on a virtual switch when using a type 2 hypervisor.

    I was just seeing if you maybe had a workaround for this?

    Kind Regards,

    Justin

Leave a Reply

Your email address will not be published. Required fields are marked *