Windows Server 2016 is out and has been for a while now, and as a lot of people start to delve into it they will notice some new features lurking in the background. One of the not so obvious new features is Nested VM’s; what this means is that you can run a Hypervisor inside a virtual machine.
Some of you may think why would anyone want to run a Hypervisor inside another Hypervisor of which a couple scenarios spring to mind quite quickly:
- You may provide hosting services and a customer requests a Hyper-V (or ESXi) server but rather then use another physical server you could allocate the resources on one of your servers and provide them access to the virtual hypervisor, thus giving them a secluded space to make and delete VMs freely without any risk of them affecting your Virtual Infrastructure.
- Another as was the case for me I needed to test something on a Mac to confirm compatibility, not having one to hand I decided a VM would be a simple solution but I needed an ESXi and so I decided to spin up an ESXi server as a VM inside one of my Hyper-V servers. This enabled me to quickly confirm my query without needing to find some spare hardware to spin up a physical ESXi box.
As you can see there could be some uses for Nested VMs although I think it will take time to be adopted… even for non-production systems. When I went to set-up this ESXi server I struggled initially to find a guide that was readily available and simple to follow as such I have decided to share what i’ve learnt below:
- A Hyper-V Host:
- A Hyper-V host running Windows Server 2016 or Windows 10 Anniversary Update.
- A Hyper-V VM running Windows Server 2016 or Windows 10 Anniversary Update (Yes you can do Nested Virtualization inside Nested Virtualization…).
- A Hyper-V VM with configuration version 8.0 or greater.
- An Intel processor with VT-x and EPT technology.
- Enable-NestedVM.ps1 – A PowerShell script for enabling Nested Virtualization in a Hyper-V VM. Click here to get the file from the Microsoft team on GitHub.
- VMWare PowerShell CLI installed – I used 6.3 release 1 that I downloaded from here. (Note: you will need a VMWare account, if you don’t have one then you can sign up here.)
- ESXi-Customizer-PS.ps1 – A PowerShell script that will download the ESXi 6.0 iso and inject the required network drivers into it for you. I downloaded it from here.
To make matters simpler if you have all three items in the same working folder – mine is “C:\NestedESXi\” then it may be easier to follow my guide, (but of course that is totally up to you).
Phase 1 – Preparing ESXi ISO with Injected Drivers:
As a stock install the ESXi Kernel doesn’t support the “Microsoft Virtual Network Adapter” or indeed the “Legacy Network Adapter”, however as the Legacy Adapter emulates a DECchip 21140 (net-tulip) we can inject the drivers into the ISO thus giving ESXi the ability to use the Legacy Network Adapter.
- Install VMWare PowerCLI (simple Next, Next, Next).
- Open a PowerShell window
- Navigate to your working directory, in my case
- Once in the working directory we can execute the following
.\ESXi-Customizer-PS-v2.5.ps1 -v60 -vft -load net-tulip
(Note: the script version may have changed so double check the part as highlighted - ESXi-Customizer-PS-v2.5
- After a few minutes the ISO will have been downloaded and the net-tulip drivers inserted into it making it ready to use, that ISO is also put straight into the folder that you ran the script from (in my case C:\NestedESXi\).
Phase 2 – Creating the VM
- In Hyper-V Manager go to create a new Virtual Machine.
- Choose what you want to Name it and make sure the location is where you want the ESXi VM to be stored, then click Next
- Select Generation 1 and click Next.
- Set the Memory to at least 4096MB and Uncheck “Use Dynamic Memory for this Virtual Machine” then click Next.
- Don’t configure networking now, just click Next since we need to use the Legacy Adapter which can only be selected after the initial config wizard.
- Select Create a new virtual hard disk and set the Size to 10GB (this is just going to be the boot disk for the ESXi Hypervisor), click Next.
- Select “Install an Operating System from a bootable CD/DVD-ROM” and browse to the ESXi ISO that is in your working directory from Phase 1.
- Click Next and then Finish to create the VM.
- Right-Click the new Virtual Machine and select Settings.
- Navigate to the Processors tab and change the allocated number of Virtual Processors (it needs to be at least 2)
- Select the existing Network Adapter and click Remove
- Select the Add Hardware tab and select Legacy Network Adapter then Add
- Select the relevant Virtual Switch so that the ESXi has network access
- Click OK
The majority of the VM configuration is now complete, we just need to enable the Nested Virtualization Extensions for the VM and then we can move onto configuring the ESXi itself.
Phase 3 – Enabling Nested Virtualization
- Open a PowerShell console.
- Enter the following commands (adjusting the vmName to match the name of your Virtual Machine in my case the name is “NestedESXi”)
.\Enable-NestedVm.ps1 -vmName 'NestedESXi'
- Enter Y when asked to confirm any of the changes (Note : the Y is case sensitive).
- The Virtual Machine is now ready to have ESXi installed into it.
Phase 4 – Initial Boot of ESXi Virtual Machine
- Start up the ESXi Virtual Machine and make sure you’re connected to it so you can see the ESXi boot screen:
- Quickly press Tab.
- Add the ignoreHeadless=TRUE to the Boot Options
- Press Enter.
- The ESXi Installation process will now start.
- After a few minutes the VMWare ESXi 6 Installer will start up
- You can now go through the ESXi installation process.
- You may receive this warning during the installation process but you can ignore it
- The installation process will begin
- Once the ESXi installation has completed you will see this message
- Make sure the ESXi Installation ISO is ejected prior to rebooting the Virtual Machine
- Press Enter to reboot the VM.
Phase 5 – Configure the ESXi Boot Options to persistently use “ignoreHeadless=TRUE”
The last thing we need to do is to set the ESXi VM to persistently use the “ignoreHeadless=TRUE” so that you do not experience any boot issues.
- When the ESXi machine reboots, quickly press SHIFT-O to set the boot options.
- Add the ignoreHeadless=TRUE to the Boot Options
- Press Enter to boot up the ESXi host
- Once the ESXi has booted up, press F2.
- Enter the root login credentials that were set during the ESXi installation process.
- Select Troubleshooting Options and press Enter
- Select Enable ESXi Shell and press Enter
- Press ALT+F1 to bring up the console
- Enter your root credentials.
- Enter the following command:
esxcfg-advcfg --set-kernel "TRUE" ignoreHeadless
- Press ALT+F2 to return to the main ESXi screen.
The ignoreHeadless=TRUE setting is now persistent and will be applied at ever boot without manual intervention required.
There you have it a fully functional ESXi Host running inside a Hyper-V Server. Of course Microsoft do support running Hyper-V inside another Hyper-V but neither Microsoft or VMWare formally support running an ESXi server in a nested environment (at least at present) and as such this should not be used for any production purposes but hopefully this has opened some eyes to a hidden feature which hasn’t received much publicity. Hyper-V may finally be catching up to the VMWare party after joining exceptionally late who knows what features Microsoft are looking at for future releases.