From Windows 10 build 10565, Microsoft added a long awaited feature called nested virtualization. This technology will allow you to run Hyper-V inside of a virtual machine (VM) running on a Windows 10 (Client Hyper-V) or Windows Server 2016 host. In other words, in the simplest configuration it enables you to install Hyper-V in a guest VM, whit the possibility to create and also run VMs on top of that Hyper-V host VM. Completely different than the previous situation with Windows Server 2012 R2 or Windows 8.1, were you could create the VMs, but weren’t able to actually start them. This new feature kind of creates a second virtualization layer, like shown in the detailed screenshot below.

This new technology is very useful when you are setting up a test/lab environment because there is no need to buy a lot of expensive hardware anymore, it simply can run on top of your notebooks OS. It also comes in handy whenever you want to train you’re failover clustering or even your System Center skills. But it’s main purpose and probably Microsoft’s main reason to finally created this feature, is to enable you to work with Hyper-V containers (operating system level virtualization). If you’re interested in reading more about this type of containers you can do so via following link: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/management/hyperv_container
Now before we start playing around with this new feature, I will first list up some things you should really keep in mind:
- The Hyper-V host must be running at least Windows 10 build 10565 or Windows Server 2016 Technical Preview (TP) 4
- An Intel processor with Intel VT-x (AMD-V is not supported yet) and EPT technology is needed to be able to use Hyper-V
- Currently only Hyper-V is supported, all other hypervisors like for example vSphere ESXi will fail to run
- Be aware that some VM features are not supported or will fail: Dynamic Memory, applying checkpoints, Live Migration and save/restore, hot memory resizing
- The VM should have more than 1 vCPU
- At least 4 GB RAM should be attached to the VM
- MAC address spoofing must be enabled on the NIC attached to the VM
- If you’re using Windows 10 Enterprise as the host, you should turnoff Virtualization Based Security (VBS) because it will prevent the use of nested virtualization
- Plenty of available RAM is needed (at least more than 4GB of RAM is preferred to get started)
After going through the theory it’s now time to get our fingers wet and get everything up and running. I will walk you through all the different steps needed to use this feature on a Windows 10 Enterprise computer. In my example I will setup a generation 1 VM (Windows 10) with a PowerShell script to test the nested virtualization scenario. So off we go.
1) First of all, you should check your windows version (should be build 10565). Click run and type winver


2) Create two internal virtual switches, one is to use your wireless card and the other one will be used in a later step as a Hyper-V vSwitch inside the VM
|
## Create vSwitches New-VMSwitch -Name InternalWifi -SwitchType Internal -Notes 'Share Parent Wifi' New-VMSwitch -Name InternalvSwitch -SwitchType Internal -Notes 'vSwitch nested virtualization' |

3) To install the VM, run the following PowerShell script (customize to your need).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
##---------------------------------------- ## Author Wim Matthyssen ## Date 04/07/16 ## Name Create_a_VM_nested_virtualization.ps1 ## Usage Built VMs on Client Hyper-V to test nested virtualization ## Note Change variables were needed to fit your needs ##---------------------------------------- ## Variables $VM1 = "W10-TST" # Name of Windows 10 VM $VMRAMSTATIC = 4GB # Static memory assigned to the VM $VHDSIZE = 90GB # Size of fixed VHDX $VMLOC = "D:\_VMs" # Location of the VM and VHDX files $NetworkSwitch1 = "InternalWifi" # Name of the Network Switch 1 $NetworkSwitch2 = "InternalvSwitch" # Name of the Network Switch 1 $vCPUCOUNT = 2 # Number of virtual CPUs $W10ISO = "D:\_ISO\OS_W10_ENT_x64.iso" # Windows 10 ISO ## Create Windows 10 VM - Add Networks - Mount ISO – Set static memory New-VHD –Path $VMLOC\$VM1\$VM1.vhdx –Fixed –SizeBytes $VHDSIZE New-VM –Name $VM1 –Path $VMLOC –MemoryStartupBytes $VMRAMSTATIC Add-VMHardDiskDrive -VMName $VM1 -Path $VMLOC\$VM1\$VM1.vhdx Set-VMProcessor $VM1 –Count $vCPUCOUNT Set-VMMemory $VM1 -DynamicMemoryEnabled $False Get-VMNetworkAdapter $VM1| Connect-VMNetworkAdapter –SwitchName $NetworkSwitch1 Add-VMNetworkAdapter -VMName $VM1 -SwitchName $NetworkSwitch2 Set-VMDvdDrive -VMName $VM1 -Path $W10ISO Start-VM $VM1 |


4) Go through the Windows Setup Installation Process on the newly created VM
5) When installation is completed shutdown the VMs and run following PowerShell commands on the Windows 10 computer (host) to set the Virtualization Extension for the vCPUs and to enable MAC spoofing on both VMs. Be aware a warning message will appear that Nested Virtualization is an unsupported preview feature. When both commands ran successfully start up the Windows 10 VM
|
## Set the Virtualization Extension for the vCPUs Set-VMProcessor -VMName "W10-TST" -ExposeVirtualizationExtensions $true ## Enable MAC spoofing Set-VMNetworkAdapter -VMName "W10-TST" -MacAddressSpoofing on |

6) To configure the W10-TST VM and to install the Client Hyper-V role with all tools, run the following PowerShell script (customize to your need). Connect to the VM with a Virtual Machine Connection with Enhanced session enabled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
##---------------------------------------- ## Author Wim Matthyssen ## Date 18/07/16 ## Name Configure_W10-TST.ps1 ## Usage Configure a Windows 10 VM ## Note Change variables were needed to fit your needs ##---------------------------------------- ## Rename Computer Rename-computer "W10-TST" ## Enable Remote Desktop set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0 ## Install Hyper-V Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All ## Set Time Zone tzutil.exe /s "Romance Standard Time" ## Allow incoming RDP on Windows Firewall Enable-NetFirewallRule -DisplayGroup "Remote Desktop" ## Restart Computer Restart-Computer |
7) To create an external virtual switch on W10-TST, logon to this sever with RDP and run the following PowerShell cmdlet as administrator (customize to your need)
|
Import-Module Hyper-V $ethernet = Get-NetAdapter -Name Ethernet2 New-VMSwitch -Name externalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true |

8) To create a nested VM named VM1-NESTED on W10-TST, logon to this VM with RDP and run the following PowerShell script as administrator (customize to your need)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
##---------------------------------------- ## Author Wim Matthyssen ## Date 17/07/16 ## Name Built_a_W2K16_TP5_VM.ps1 ## Usage Built a W2K16 TP 5 VM ## Note Change variables were needed to fit your needs ##---------------------------------------- ## Variables $VM = "VM1-NESTED" # Name of Windows Server 2016 TP5 VM $VMRAMSTATIC = 2GB # Static memory assigned to the VM $VHDSIZE = 40GB # Size of fixed VHDX $VMLOC = "C:\_VM" # Location of the VM and VHDX files $NetworkSwitch = "externalSwitch" # Name of the Network Switch $vCPUCOUNT = 1 # Number of virtual CPUs $W2K16ISO = "C:\Temp\OS_W2K16_TP5_x64.iso" # Windows Server 2016 TP5 ISO ## Create Windows Server 2016 TP VM - Add Networks - Mount ISO – Set static memory New-VHD –Path $VMLOC\$VM\$VM.vhdx –Fixed –SizeBytes $VHDSIZE New-VM –Name $VM –Path $VMLOC –MemoryStartupBytes $VMRAMSTATIC Add-VMHardDiskDrive -VMName $VM -Path $VMLOC\$VM\$VM.vhdx Set-VMProcessor $VM –Count $vCPUCOUNT Set-VMMemory $VM -DynamicMemoryEnabled $False Get-VMNetworkAdapter $VM| Connect-VMNetworkAdapter –SwitchName $NetworkSwitch Set-VMDvdDrive -VMName $VM -Path $W2K16ISO Start-VM $VM |

9) Go through the Windows Setup Installation Process on the newly created nested VM named VM1-NESTED on W10-TST
10) If the installation is successful, you should now have a nested VM running like in the screenshot below

This concludes this blog post. Keep tuned and I’ll be back soon.
Wim Matthyssen (@wmatthyssen)
Recent Comments