Quick Note: Running VMs within Google Compute Engine

2 min readJan 10, 2024

Recently I had the need to run VirtualBox VMs within a Google Compute Engine instance. I was being lazy and did not want to tweak a script that creatse a lab environment by spinning up VMs locally. I was surprised to learn that this feature is not enabled by default, and that there were some unexpected pitfalls that I encountered along the way. No, Duet AI was of no help either, in fact it led me down the wrong path.

To enable nested virtualization when creating the VM, see Google’s comprehensive documentation here.

Basically, when using gcloud compute instance create, supply the -- enable-nested-virtualization option. If you are enabling this feature for an existing compute engine, update the machine’s yaml configuration with the following lines:

enableNestedVirtualization: true

And you should be good to go! Or are you…

Compute engine defaults to recommending E2 machines, and I was stuck here for quite a bit. After following the instructions listed in Google’s documentation, nested virtualization was still not working. Turns out, that document was missing an important piece of information. E2 machines DO NOT support nested virtualization (See Google’s machine series comparison). In short, only C3, N2, N1, H3, C2, A2 and G2 machines allow for nested virtualization.

For fun, here’s DuetAI’s response. Almost there but not quite. As per Google’s documentation, you’ll have to edit the advancedMachineFeatures section instead of the metadata section of the Compute Engine’s configuration.