How to enable nested virtualization on Google Cloud

I was recently looking for a way to build networking labs. My biggest pre-requisite was to not spend time and money on hardware. I’ve already used tools like GNS3, CML, Containerlab or EVE-NG in the past and they are great to simulates network. The problem is that emulated network boxes are often not compiled in ARM64, therefore it’s difficult to use previous tools on Macos. Finally, I don’t like to it on my laptop.

The main solution would be to use a big x86 server with a lot of RAM and CPU. Problem is that my wife would not agree on having such noisy hardware at home. I could use hardware from providers like OVH, Hertzner, or others but I’m going to use this lab only few hours straight every month.

Lacking solutions, I noticed that Google Cloud allows nested virtualization. This could be a great way to use a large server for my lab for only a few hours a month. Let’s explore this together in this post.

By the way, if you know some alternative to Google Cloud for that let me know in the comments. I’ve heard that Scaleway could do it too. Don’t hesitate to share.

Things to know

I won’t paraphrase Google, therefore I invite you to read this page : https://docs.cloud.google.com/compute/docs/instances/nested-virtualization/overview

What you can remember from the previous article is that nested virtualisation is not available on every kind of machine. They are not available for E2 instances or for some architecture.

For this tutorial I’ll be using an N1 Standard instance. It pretty small…

  • 1vCPU
  • 3.75 GB of RAM

…and therefore probably not adapted for nested virtualization. However this is just for testing purpose.

Build the VM

Let’s define a simple N1 Standard machine :

$ gcloud compute instances create test-1 --machine-type=n1-standard-1 --zone=europe-north1-a

By default my gcloud is creating a Debian 12 VM, which is fine for me. Don’t hesitate to tune the previous command.

After creation, we can check if the VM is KVM ready, which is a good way to know if you can use it for virtualisation. Do as follow, for a Debian 12:

$ sudo apt update
$ sudo apt install cpu-checker
$ sudo kvm-ok
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used

As you can see this VM is not virtualisation ready.

By the way, on Debian if you are looking for the APT package name holding a specific file. For example, you want the package name holding the file kvm-ok. Then, you can use this official page https://www.debian.org/distrib/packages. (Use the second search bar).

Make it virtualisation ready

There are two ways to do this, depending if the VM is already created or not. For simplicity here, I’ll delete an re-create the VM. If you are in the other case you can export the vm configuration, modify it and then update the vm with this new configuration.

Let’s delete the VM :

$ gcloud compute instances delete test-1

And now rebuilt it with nested virtualisation :

$ gcloud compute instances create test-1 --machine-type=n1-standard-1 --zone=europe-north1-a --enable-nested-virtualization

Let’s now check if kvm would work :

$ sudo apt update
$ sudo apt install cpu-checker
$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Perfect !

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top