HOWTO: Configure nested virtualization on CentOS 6
In some situations you would like to test or prove a Virtualization set-up before rolling it out on bare metal. In these cases the ideal scenario would be to set up your Hypervisor hosts as Virtual Machines and then run Virtual Machines on them. This scenario where you run VM's inside a VM is called nested virtualization.
Nested virtualization is a feature that can be enabled using a kernel parameter. Unfortunately, the current CentOS kernel does not support this parameter.
2. Before you begin
You may verify if your system supports the nested parameter by checking for the file: /sys/module/kvm_intel/parameters/nested
On a default CentOS 6 system this file will not exist. Fortunately, we have the xen-c6 project (http://dev.centos.org/centos/6/xen-c6/) that features a kernel that supports the nested parameter!
3. Step 1: add the xen-c6 repo to your system
- su -
- cd /etc/yum.repos.d
- yum repolist
- [optional] vi xen-c6.repo : change to "enabled=0" to not take the repo enabled by default
4. Step 2: install the new kernel
- su -
- yum --enablerepo xen-c6 install kernel kernel-firmware
- vi /boot/grub/grub.conf : add "kvm-intel.nested=1" to the end of the kernel line
- verify proper operation: "cat /sys/module/kvm_intel/parameters/nested" will output "Y"
5. Step 3: Configure the Hypervisor Virtual Machine
For the setup to work, we need the "vmx" flag in the virtual cpu inside the VM.
I will use virt-manager for this HOWTO. Obviously, one can use XML files and virsh to get the same result.
open the hypervisor virtual machine, go to Details > Processor
- unfold the "Configuration"
- press the "Copy host CPU configuration" button
- unfold the "CPU Features"
- verify the "vmx" feature is set to "require"
- press Apply
Boot the hypervisor virtual machine, and lo and behold! libvirtd is up and running inside the VM!