Home Nested Virtualisation in GCP… for your Android Emulator!
Post
Cancel

Nested Virtualisation in GCP… for your Android Emulator!

There might arise scenarios when you will require some virtualized environment or an instance setup inside a virtual machine that you are already using on Google Cloud Platform.

Nested Virtualisation is what you are looking for!

In my case, I wanted to run an Android emulator inside of a VM. As expected AVD manager started complaining that VT-X/AMD-v is not supported.

Fret not! Google supports this without looking at your wallet. 😄

Here’s how to enable it.

Restrictions

L1 VMs have the following restrictions:

  • You must run Linux-based OSes; you can’t use Windows Server images.
  • You cannot use E2 and N2D machine types.
  • You must use Intel Haswell or later processors; AMD processors are not supported. If the default processor for a zone is Sandy Bridge or Ivy Bridge, change the minimum CPU selection for the VMs in that zone to Intel Haswell or later. For information about the processors supported in each zone, see Available regions and zones.

L2 VMs have the following restrictions:

How to…

If you are creating an image using the gcloud, provide the following license URL using the --licenses flag: https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx

In my case, for example, I already had a disk running so I just needed to create an image dev-disk-image from an example disk named dev:

1
$ gcloud compute images create dev-disk-image — source-disk dev — source-disk-zone asia-south2-a — licenses “https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx”

If you want to do it on an already existing image:

1
$ gcloud compute images create dev-disk-image --source-image=debian-10-buster-v51235 --source-image-project=preject-id --licenses="https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"

Create a VM from using the image

1
$ gcloud compute instances create dev-virt — zone asia-south2-a — image dev-disk-image

Confirm that nested virtualization is enabled. A nonzero response on the following command confirms that nested virtualization is enabled:

1
$ grep -cw vmx /proc/cpuinfo

That’s it, Thank you!

This post is licensed under CC BY 4.0 by the author.