Azure Lab Services provides the ability to create a template machines with nested Hyper-V virtual machines. See Enable nested virtualization on a template virtual machine in Azure Lab Services documentation for further details. This is useful for classes where you need a couple machines to talk to one another, like the Ethical Hacking class described in the class type documentation.
Let’s talk about some tips when you need to create your own template machine with nested Hyper-V virtual machines.
1. Consider which Hyper-V VMs are needed for the class, not the department.
There is sometimes a tendency to want to create one template for all classes in a department. Taking the time to consider what is needed for only a specific class can save money by allowing for a smaller template machine size to be used. Save the image for reuse in the future.
2. Use VHDX for virtual disks.
The OS disk size for Lab Services VMs depends on the selected image and for most of the images its 128 GB. The size of a VHD disk for a Hyper-V VM matches the maximum size you want that virtual disk to be. The VHDX format allows for the actual size of the file to be reduced and to later be increased up to the maximum disk size. Using the VHDX file format for your virtual disk could potentially allow for more Hyper-V VMs on a lab template machine. This is dependent on the number and size of files stored on each virtual disk, though.
The ability to shrink virtual disks only works with the VHDX file format. If you have an existing VHD file, use the Convert-VHD PowerShell cmdlet to convert to a VHD file to VHDX. Use Resize-VHD PowerShell cmdlet to shrink the virtual disk size and store more virtual disks on the template machine.
3. Use dynamic memory when creating the Hyper-V virtual machine.
Users can set the minimum and maximum RAM for the Hyper-V virtual machine. This allows other Hyper-V virtual machines or the host machine to use the memory when it is not needed. This can be useful in cases where a Hyper-V VM only needs to be used in bursts rather than continuously.
We hope you find these tips useful. Please comment below if you know of more tips or have a question.
Thanks,
The Lab Services Team