Let’s look into the steps to enable nested virtualization on CentOS. Bobcares, as a part of our Server Management Services, offers solutions to every query that comes our way.
How to enable nested virtualization on CentOS?
Nested virtualization refers to setting up a VM’s environment. In other words, we can say that it is a hypervisor feature that helps us to install & run a VM inside a virtual server.
On CentOS, it is disabled by default. To check whether it is active on the host OS, we can use the below code:
hostOS# cat /sys/module/kvm_intel/parameters/nested
If the result is “Y”, then it is active on the host OS. And if the result is “N”, it is not active on the host OS.
Steps to enable:
- Firstly, create a file with the name
“/etc/modprobe.d/kvm-nested.conf”
with the below content.[root@kvm-hypervisor ~]# vi /etc/modprobe.d/kvm-nested.conf options kvm-intel nested=1 options kvm-intel enable_shadow_vmcs=1 options kvm-intel enable_apicv=1 options kvm-intel ept=1
- Now save the file and exit.
- Remove the
‘kvm_intel
module now. Then add it again using themodprobe
code. Confirm all VMs are shut down before removing the module so that we can avoid an error.[root@kvm-hypervisor ~]# modprobe -r kvm_intel [root@kvm-hypervisor ~]# modprobe -a kvm_intel [root@kvm-hypervisor ~]#
- Then we can check whether the feature is active or not by using the below code:
[root@kvm-hypervisor ~]# cat /sys/module/kvm_intel/parameters/nested Y [root@kvm-hypervisor ~]#
Testing
Consider we have a VM with the name “director” on the KVM hypervisor. We have enabled the nested virtualization on it. For the testing, we have to run the below steps:
1. To verify this, we have to make a VM inside a VM. In order to do so, we must make sure the mode of the CPU in the VM is either “host-model”
or “host-passthrough”
.
2. Run lscpu
and lsmod
codes after logging into the VM.
[root@kvm-hypervisor ~]# ssh 192.168.126.1 -l root root@192.168.126.1's password: Last login: Sun Dec 10 07:05:59 2017 from 192.168.126.254 [root@director ~]# lsmod | grep kvm kvm_intel 170200 0 kvm 566604 1 kvm_intel irqbypass 13503 1 kvm [root@director ~]# [root@director ~]# lscpu
3. Now build a VM. We can use the GUI or the virt-install code inside the VM. Here, we are using virt-install code.
[root@director ~]# virt-install -n Nested-VM --description "Test Nested VM" \ --os-type=Linux --os-variant=rhel7 --ram=2048 --vcpus=2 --disk \ path=/var/lib/libvirt/images/nestedvm.img,bus=virtio,size=10 --graphics \ none --location /var/lib/libvirt/images/CentOS-7-x86_64-DVD-1511.iso\ --extra-args console=ttyS0 Starting install... Retrieving file .treeinfo... | 1.1 kB 00:00:00 Retrieving file vmlinuz... | 4.9 MB 00:00:00 Retrieving file initrd.img... | 37 MB 00:00:00 Allocating 'nestedvm.img' | 10 GB 00:00:00 Connected to domain Nested-VM Escape character is ^] [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.10.0-327.el7.x86_64 ………………………………………………
We can now create a VM inside another VM. This shows that nested virtualization is all active now.
[Searching for an answer to another question? We are happy to assist you.]
Conclusion
Nested Virtualization is not active on CentOS systems by default. In this article, we provide the steps from our Support team to enable it on CentOS.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments