Home > System Tutorial > LINUX > Enable nested virtualization on KVM on Centos7

Enable nested virtualization on KVM on Centos7

WBOY
Release: 2024-03-30 17:21:36
forward
454 people have browsed it

Nested virtualization means configuring a virtualization environment within a virtual machine. In other words, we can say that nested virtualization is a feature of hypervisor that allows us to ) to install and run virtual machines within a virtual server using hardware acceleration. In this article, we will discuss how to enable nested virtualization on KVM on CentOS 7 / RHEL 7. I assume you have already configured the KVM hypervisor. If you are unfamiliar with how to install and configure the KVM hypervisor, please refer to the following article.

Install KVM hypervisor on CentOS 7.x and RHEL 7.x

Let’s go into the hypervisor and verify that your KVM host has nested virtualization enabled.
Intel-based processors run the following command:

[root@kvm-hypervisor ~]# cat /sys/module/kvm_intel/parameters/nested
N
Copy after login
For AMD-based processors run the following command:

[root@kvm-hypervisor ~]# cat /sys/module/kvm_amd/parameters/nested
N
Copy after login
The above command output

N

indicates that nested virtualization is disabled. If the output we get is

Y it means nested virtualization is enabled on your host. Now to enable nested virtualization, create a file named /etc/modprobe.d/kvm-nested.conf

with the following content:

[root@kvm-hypervisor ~]# vi /etc/modprobe.d/kvm-nested.conf
Copy after login
options kvm-intel nested=1
options kvm-intel enable_shadow_vmcs=1
options kvm-intel enable_apicv=1
options kvm-intel ept=1
Copy after login
Save and exit the file. Now remove the

kvm_intel

module and add the same module via the

modprobe command. Before removing the module, make sure the virtual machine is shut down, otherwise we will get error messages like “modprobe: FATAL: Module kvm_intel is in use”.

[root@kvm-hypervisor ~]# modprobe -r kvm_intel
[root@kvm-hypervisor ~]# modprobe -a kvm_intel
Copy after login
Now verify that the nested virtualization feature is enabled.
[root@kvm-hypervisor ~]# cat /sys/module/kvm_intel/parameters/nested
Y
Copy after login

Testing Nested Virtualization

Suppose we have a virtual machine named "director" on the KVM hypervisor that has nested virtualization enabled. Before testing, make sure the CPU mode is "host-modle" or "host-passthrough". Use Virt-Manager or the virtsh
edit command to check the CPU mode of the virtual machine.

在 Centos7 的KVM上启用嵌套虚拟化cpu_mode_vm_kvm

Now log in to the director virtual machine and run the lscpu

and

lsmod commands.

[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
Copy after login
[root@director ~]# lscpu
Copy after login

在 Centos7 的KVM上启用嵌套虚拟化lscpu_command_rhel7_centos7

Let's try to create a virtual machine in the director virtual machine's virtual manager GUI or virt-install

command, in my case I used

virt-install Order.

[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 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015
………………………………………………
Copy after login

在 Centos7 的KVM上启用嵌套虚拟化cli-installer-virt-install-command-kvm

This confirms that nested virtualization is successfully enabled, as we are able to create virtual machines within virtual machines.

The above is the detailed content of Enable nested virtualization on KVM on Centos7. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template