I know that most of you want to learn virtualization, and since you have Hyper-V in your company this is a very important task. A common problem is that you can’t test on production systems and a lab is out of the question for a company of your size. If this sounds all too familiar but you’re still eager to learn, nested virtualization will help you out tremendously. Now I’m not going to give you a nice and long definition of what nested virtualization is because Andy already has an article about it where he explains it very well; but long story short, nested virtualization lets us create Hyper-V virtual machines inside a Hyper-V virtual machine or Hyper-V host. Think about it, we can have a Hyper-V farm inside a single box. Off course, this will be only for testing purposes, because production environment won’t support this configuration largely due to the performance impact of running such a setup.
In order to be able to create a nested Hyper-V machine with Windows Server 2016, Hyper-V requires hardware virtualization support (such as Intel VT-x) to run virtual machines. In previous Windows Server versions, such as 2012 and 2012 R2, this capability was hidden from the guest VMs which prevents them from running the Hyper-V server role among other hypervisors. In Windows Server 2016 however, Microsoft has given us the choice to enable this processor capability inside a VM using PowerShell.
Before moving forward I presume you have already installed Windows Server 2016 on your host (the bare metal server), as well as the Hyper-V role. Also, make sure in the BIOS of the hardware you have the virtualization support available and enabled.
Now you’ve got that ready, let’s move into creating our first Hyper-V virtual machine.
Creating a Hyper-V nested virtual machine
Open the Hyper-V console and from the Actions pane click New > Virtual Machine; or right-click the host and follow the same steps.
On the first page of the New Virtual Machine Wizard, name the new VM and provide a location for the virtual disk(s) and configuration files.
In the Specify Generation page choose the second option to create a generation 2 virtual machine. This one has better performance and supports the newest features.
Since this will be a Hyper-V host, as far as the virtual machines that will run on it know, we will have to allocate a fair chunk of memory. Based on how much RAM you have on your physical server and how many VMs you want to run on this Hyper-V virtual machine, assign the right amount. Ensure that Use Dynamic Memory for this virtual machine is not selected then click Next.
Select the virtual switch you want this virtual machine to be connected to then continue the wizard.
Provide the path for the virtual disk then the size of it. If you intend to keep and run the virtual machines on this disk, make it big, if not use the appropriate size just for the OS.
Choose how you want to install the OS then click Next. This settings can be also configured alter on.
Click Finish to create our first virtual machine soon to be a Hyper-V virtual machine.
Once created, power on the VM and install Windows Server 2016. I’m not going to put the installation steps here which consist simply of just booting from the network and doing a few clicks on the installation wizard.
Once you get it up and running and try to install Hyper-V on the virtual machine an error will be presented:
Hyper-V cannot be installed: the processor does not have required virtualization capabilities.
The message pops-up because, by default, the hypervisor hides the hardware virtualization support capability from guest VMs. The next steps are to use some PowerShell command lines to enable virtualization support capability for guest VMs. Shut down the virtual machine then execute the commands shown below. The first one lets you see if virtualization support is enabled for the VM, and the second one enables virtualization support. The problem about running the second command line is that no message is displayed if it succeeds.
Get-VMProcessor -VMName <Target VM's name> | fl * Set-VMProcessor -VMName <Target VM's Name> -ExposeVirtualizationExtensions $true
In case you want to speed things up and try to enable virtualization support while the virtual machine is still running, you will get an ugly error message in PowerShell; so make sure the VM is off.
Set-VMProcessor : Failed to modify device ‘Processor’. Cannot change the processor functionality of a virtual machine now.
“…” Cannot change the processor functionality of virtual machine ‘Server-HV01’ while it is running.
Now power on the virtual machine and try installing Hyper-V. The wizard should let us install the role this time with no problems whatsoever.
I’ve seen people perform a second layer of virtualization, meaning inside this Hyper-V virtual machine they deployed another Hyper-V VM and only then they will start creating the required test machines. You can do that, but I don’t recommend it, because the performance rapidly declines and if you think about it, you don’t even need to. If the test you are doing requires another Hyper-V VM, all you need to do is follow the above steps and create another Hyper-V virtual machine on the bare metal hypervisor.
Creating virtual machines inside the nested hypervisor
Once you’re done creating your nested Hyper-V machines, open the console for one of them and start creating virtual machines like you would normally do except now your virtual machines will run inside a virtualized Hyper-V server. Pretty neat, huh??
As you can see they are running smoothly and if you can afford an SSD drive they will run great.
Now I’ve told you how to create Hyper-V nested virtualization here comes the disclaimer because you’ll quickly find out there are a few features that won’t work. To be honest, I don’t know if it’s such a problem missing these because you are probably not going to make use of them in a test lab anyway. Here they are:
- Checkpoints are not going to work
- Live migration is not going to work
- Live memory resize is not possible. You will have shut down the Hyper-V VM.
- Does not currently run with AMD processors. <This is the biggest drawback I can find>
Nested virtualization in Windows Server 2016 brings a new level to virtualization with Hyper-V that is perfect for creating lab environments and learning all there is about Microsoft technologies. I have to say, the feature was implemented very late compared to the competition, and the restriction on AMD processors can be a severe issue for some. However, if the drawbacks don’t affect you it’s a really useful tool, and we should expect some improvements from Microsoft in future updates. Until then, use it as it is and comment below with your own experiences!
Is Your Office 365 Data Secure?
Did you know Microsoft does not back up Office 365 data? Most people assume their emails, contacts and calendar events are saved somewhere but they're not. Secure your Office 365 data today using Altaro Office 365 Backup - the reliable and cost-effective mailbox backup, recovery and backup storage solution for companies and MSPs
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!