Nested Virtualization Tips

Published Jul 21 2020 09:00 AM 1,999 Views
Microsoft

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

 

 

6 Comments
New Contributor

I have been working very hard to build a proper lab of nested VMs using Azure Lab Services, but the 128GB hard disk is just incredibly limiting. I have used a lot of tricks not discussed in this blog post to cut down on the size, so I truly wonder how people really do it without running out of disk space. The truly essential part was to disable all checkpoints (even though they are useful, they're a luxury we cannot afford here) and I created sysprepped images + used Hyper-V differencing disks. Without the differencing disks, there is no way I would have been able to create 5 VMs in the large instance (8 cores, 32GB RAM, nested virtualization). It all works well *except* for the suffocating storage space. It's a shame because this really is the only problem to which I cannot find a good solution, I like everything else about the product.

 

I'd be more than happy to have a discussion with someone from the Azure Lab Services team, I'd like to get the word out about this wonderful product that I didn't know existed until recently. I really wish I could just pay extra for VM instances that have a decent storage space included.

 

mamoreau_0-1613761804959.png

 

Microsoft

I ran into similar limitations, specifically when using nested virtualization. You may want to consider checking out Azure DevTest labs, as it has a lot more flexibility and you can use more storage, additional drives, upload your own, etc. 

 

I've heard that more flexibility may be coming to ALS, but in the meantime, DevTest Labs may work out well for you.

 

Hope this helps!

New Contributor

I haven't checked the Azure DevTest Labs yet, but I suspect it doesn't have the same ease and lab shareability as Azure Lab Services, does it? I really like the fact that you just edit a template then easily duplicate it to a large number of people in a cost-efficient way. The ability to invite people outside of my organization and control the number of hours they can use their own test VMs is really a killer feature of Azure Lab Services.

 

Do you know if expanded storage is coming soon? There's a feature request with a few other people running into the same issues I do, but it's unclear if this limitation is being prioritized or not. The fact that a blog post with tips to save on disk space at least shows that the need is understood, but at the same thing labs using nested VMs cannot realistically fit inside 128GB. I sacrificed one VM to go back down to 4 VMs, but a lot of features in a Windows domain require a lot more VMs to correctly demonstrate.

 

https://feedback.azure.com/forums/320373-lab-services/suggestions/36495472-be-able-to-add-additional...

Microsoft

I totally agree, the cost tracking and ease of inviting users is tough to beat, and I'm watching closely because my customers also want this capability. Unfortunately, I haven't heard anything definitive on it yet. 

 

For DevTest Labs, you might consider checking out shared image galleries. Set up a gallery, image, etc. and then you can share it out. You might find it easier to create the gallery in regular Azure first and then share it out to use in DevTest labs. Inviting other users is not as simple as with ALS, but it might fit your needs. I'm hoping the two will either merge or the capabilities will overlap eventually.

 

Check out this article on sharing out the galleries: 

Share VM images with Shared Galleries - Azure Virtual Machines | Microsoft Docs

New Contributor

You seem to have been following ALS for much longer than me, do you know where the key people involved hang out? You're actually the first person to respond so far, the feedback site and UserVoice only appear to have sporadic responses, and I couldn't find anybody on twitter. I would love to have a more direct way to talk to the team, as this product definitely fits the bill for me aside from the low storage space.

 

I was thinking of writing a blog post giving all the tips and tricks I learned along the way, but with the storage space issue, my final recommendation would be that is that it can only be used for a lab of 4 VMs maximum, if you used all the tricks in the book to save space.

 

As for the rest, you have probably gone through the same process I did, and figured out ways to transfer large files onto the template VM *other* than over RDP which is way too slow. Because I didn't know that you had to create the virtual network *before* the lab to attach a lab to a virtual network, I pretty much got to where I wanted after the 3rd lab created from scratch. You definitely need at last one "lab controller VM" to transfer files more easily to the template VM.

 

The thing is that even though the workflow ALS enforced appears relatively simple, I don't have the time to make a DIY equivalent, especially for cost control, easy duplication and sharing of the lab VMs. Have you found the equivalent Azure VM SKUs for the instances offered through ALS? I'm particularly interested in the 8 core, 32GB RAM + nested virtualization instance.

This being said, due to my strong background in RDP through the FreeRDP project and what I'm working on these days at Devolutions with Wayk Bastion, there are a few things I could offer to the ALS team to improve secure external RDP connectivity. We have an open source Remote Desktop Gateway replacement (Devolutions Gateway) that does relaying at the TCP-level and accepts a JWT instead of doing the heavyweight RD Gateway protocol, it would be a whole lot better than using the current RDP dynamic range of ports. We are also about to adapt it for SSH access, so it would be usable for that as well in the future.

 

Are you aware of anyone building their own Azure Lab Services replacement with a similar type of workflow, with a single template VM efficiently duplicated for a large number of students, with good enough cost control to reduce waste to a minimum? Azure VMs have an auto-shutdown feature, but that's once per day, for instances that cost 1$ per hour that's just too much waste if students forget it for a couple of hours. If you've got links to blog posts that cover parts of the puzzle, like how to deal with the disk duplication easily for Azure VMs, I'm all ears.

 

To conclude, I'd be curious to learn more about your use case, as we may be able to share tips.

Microsoft

hi @mamoreau thanks so much for your interest in AzLabs! The extra disk space is definitely a feedback we hear from other customers as well. We're currently working on a bunch of infrastructure improvements to improve performance and reliability and other features such as the ability to connect to VMs through the browser (via Azure Bastion) and expanded network configurability for the May/June timeframe, so we expect we'll be able to pick up investigating the work to increase disk size post-June. We'll post more updates here as we get closer to that timeframe. 

 The forum (https://aka.ms/azlabs-forum) would be the best place to hold discussions. We're trying to consolidate our channels a bit more, so we expect the forum to play a bigger role for conversations going forward! For reporting any product issues, please log a support ticket from the product. 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-1534323%22%20slang%3D%22en-US%22%3ENested%20Virtualization%20Tips%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1534323%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Lab%20Services%20provides%20the%20ability%20to%20create%20a%20template%20machines%20with%20nested%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows-server%2Fvirtualization%2Fhyper-v%2Fhyper-v-technology-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EHyper-V%3C%2FA%3E%20virtual%20machines.%26nbsp%3B%20See%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Flab-services%2Fhow-to-enable-nested-virtualization-template-vm%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EEnable%20nested%20virtualization%20on%20a%20template%20virtual%20machine%20in%20Azure%20Lab%20Services%3C%2FA%3E%20documentation%20for%20further%20details.%26nbsp%3B%20This%20is%20useful%20for%20classes%20where%20you%20need%20a%20couple%20machines%20to%20talk%20to%20one%20another%2C%20like%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Flab-services%2Fclass-type-ethical-hacking%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EEthical%20Hacking%20class%3C%2FA%3E%20described%20in%20the%20class%20type%20documentation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20talk%20about%20some%20tips%20when%20you%20need%20to%20create%20your%20own%20template%20machine%20with%20nested%20Hyper-V%20virtual%20machines.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.%20Consider%20which%20Hyper-V%20VMs%20are%20needed%20for%20the%20class%2C%20not%20the%20department.%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EThere%20is%20sometimes%20a%20tendency%20to%20want%20to%20create%20one%20template%20for%20all%20classes%20in%20a%20department.%26nbsp%3B%20Taking%20the%20time%20to%20consider%20what%20is%20needed%20for%20only%20a%20specific%20class%20can%20save%20money%20by%20allowing%20for%20a%20smaller%20template%20machine%20size%20to%20be%20used.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Flab-services%2Fhow-to-use-shared-image-gallery%23save-an-image-to-the-shared-image-gallery%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESave%20the%20image%3C%2FA%3E%20for%20reuse%20in%20the%20future.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.%20Use%20%3C%2FSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fprevious-versions%2Fwindows%2Fit-pro%2Fwindows-server-2012-R2-and-2012%2Fdn282286(v%3Dws.11)%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSTRONG%3EVHDX%20for%20virtual%20disks%3C%2FSTRONG%3E%3C%2FA%3E%3CSTRONG%3E.%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EThe%20OS%20disk%20size%20for%20Lab%20Services%20VMs%20depends%20on%20the%20selected%20image%20and%20for%20most%20of%20the%20images%20its%20128%20GB.%20The%20size%20of%20a%20VHD%20disk%20for%20a%20Hyper-V%20VM%20matches%20the%20maximum%20size%20you%20want%20that%20virtual%20disk%20to%20be.%26nbsp%3B%20The%20VHDX%20format%20allows%20for%20the%20actual%20size%20of%20the%20file%20to%20be%20reduced%20and%20to%20later%20be%20increased%20up%20to%20the%20maximum%20disk%20size.%26nbsp%3B%20Using%20the%20VHDX%20file%20format%20for%20your%20virtual%20disk%20could%20potentially%20allow%20for%20more%20Hyper-V%20VMs%20on%20a%20lab%20template%20machine.%26nbsp%3B%20This%20is%20dependent%20on%20the%20number%20and%20size%20of%20files%20stored%20on%20each%20virtual%20disk%2C%20though.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EThe%20ability%20to%20shrink%20virtual%20disks%20only%20works%20with%20the%20VHDX%20file%20format.%26nbsp%3B%20If%20you%20have%20an%20existing%20VHD%20file%2C%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fmodule%2Fhyper-v%2FConvert-VHD%3Fview%3Dwin10-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EConvert-VHD%3C%2FA%3E%20PowerShell%20cmdlet%20to%20convert%20to%20a%20VHD%20file%20to%20VHDX.%26nbsp%3B%20Use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fhyper-v%2Fresize-vhd%3Fview%3Dwin10-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EResize-VHD%3C%2FA%3E%20PowerShell%20cmdlet%20to%20shrink%20the%20virtual%20disk%20size%20and%20store%20more%20virtual%20disks%20on%20the%20template%20machine.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E3.%26nbsp%3BUse%3C%2FSTRONG%3E%20%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Flibrary%2Fhh831766.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSTRONG%3Edynamic%20memory%3C%2FSTRONG%3E%3C%2FA%3E%3CSTRONG%3E%20when%20creating%20the%20Hyper-V%20virtual%20machine%3C%2FSTRONG%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EUsers%20can%20set%20the%20minimum%20and%20maximum%20RAM%20for%20the%20Hyper-V%20virtual%20machine.%26nbsp%3B%20This%20allows%20other%20Hyper-V%20virtual%20machines%20or%20the%20host%20machine%20to%20use%20the%20memory%20when%20it%20is%20not%20needed.%26nbsp%3B%20This%20can%20be%20useful%20in%20cases%20where%20a%20Hyper-V%20VM%20only%20needs%20to%20be%20used%20in%20bursts%20rather%20than%20continuously.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20hope%20you%20find%20these%20tips%20useful.%26nbsp%3B%20Please%20comment%20below%20if%20you%20know%20of%20more%20tips%20or%20have%20a%20question.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%2C%3C%2FP%3E%0A%3CP%3EThe%20Lab%20Services%20Team%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1534323%22%20slang%3D%22en-US%22%3E%3CP%3ENeed%20to%20use%20nested%20virtualization%20in%20a%20lab%3F%26nbsp%3B%20Check%20out%20a%20few%20tips%20we've%20compiled.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1534323%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELab%20Services%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jul 20 2020 03:21 PM
Updated by: