Thursday, January 18, 2018

How to enable Nested Virtualization in KVM on CentOS 7 / RHEL 7

Nested virtualization means to configure
virtualization environment inside a virtual machine. In other words we
can say nested virtualization is a feature in the hypervisor which
allows us to install & run a virtual machine inside a virtual server
via hardware acceleration from the hypervisor (host).
In this article, we will discuss how to enable nested virtualization
in KVM on CentOS 7 / RHEL 7. I am assuming you have already configured
KVM hypervisor. In case you have not familiar on how to install and
configure KVM hypervisor, then refer the following article

In the above command output ‘N’ indicates that Nested virtualization
is disabled. If we get the output as ‘Y’ then it indicates that nested
virtualization is enabled on your host.
Now to enable nested virtualization, create a file with the name “/etc/modprobe.d/kvm-nested.conf” with the following content.

Save & exit the file
Now remove ‘kvm_intel‘ module and then add the same
module with modprobe command. Before removing the module, make sure VMs
are shutdown otherwise we will get error message like “modprobe: FATAL: Module kvm_intel is in use”

Test Nested Virtualization

Let’s suppose we have a VM with name “director” on KVM hypervisor on
which I have enabled nested virtualization. Before testing, make sure
CPU mode for the VM is either as “host-model” or “host-passthrough” , to check cpu mode of a virtual machine use either Virt-Manager GUI or virsh edit command
Now login to the director VM and run lscpu and lsmod command

This confirms that nested virtualization has been enabled
successfully as we are able to create virtual machine inside a virtual
machine.
This Concludes the article, please do share your feedback and comments.