Como habilitar la virtualización anidada en KVM

Fedora Documentation Team Version F36 onwards Last review: 2023-02-21
La virtualización anidada permite correr una máquina virtual (VM) dentro de otra VM mientras sigue usando la aceleración hardware del host.

Comprobar si se soporta la virtualización anidada

Para los procesadores Intel, compruebe el archivo /sys/module/kvm_intel/parameters/nested. Para procesadores AMD, compruebe el archivo /sys/module/kvm_amd/parameters/nested. Si ve 1 o Y la virtualización anidada está soportada; si ve 0 o N no se soporta la virtualización anidada.

Por ejemplo:

cat /sys/module/kvm_intel/parameters/nested
Y

Habilitar la virtualización anidada

To enable nested virtualization for Intel processors:

  1. Shut down all running VMs and unload the kvm_probe module:

    ---- sudo modprobe -r kvm_intel

. Activate the nesting feature:
+

sudo modprobe kvm_intel nested=1

+
. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the `/etc/modprobe.d/kvm.conf` file:
+

options kvm_intel nested=1

To enable nested virtualization for AMD processors:

. Shut down all running VMs and unload the `kvm_amd` module:
+

sudo modprobe -r kvm_amd

. Activate the nesting feature:
+

sudo modprobe kvm_amd nested=1

. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the `/etc/modprobe.d/kvm.conf` file:
+

options kvm_amd nested=1

// ===========================================
// include::{partialsdir}/proc_configuring-nested-virtualization-in-virt-manager.adoc[leveloffset=+1]
// ===========================================
// [[proc_configuring-nested-virtualization-in-virt-manager]]
== Configurar virtualización anidada en virt-manager

Configurar su VM para usar virtualización anidada:

. Open virt-manager, double-click the VM in which you wish to enable nested virtualization, and click the *Show virtual hardware details* icon.

. Click *CPUs* in the side menu. In the *Configuration* section, there are two options - either type `host-passthrough` in the *Model:* field, or select the *Copy host CPU configuration* check box (that fills the `host-model` value in the *Model* field). + NOTE: Using host-passthrough is not recommended for general usage. It should only be used for nested virtualization purposes. + . Click *Apply*.


// =========================================== // include::{partialsdir}/proc_testing-nested-virtualization.adoc[leveloffset=+1] // =========================================== // [[proc_testing-nested-virtualization]]
== Probar la virtualización anidada

. Start the virtual machine. . On the virtual machine, run: +

sudo dnf group install virtualization

+
. Verify that the virtual machine has virtualization correctly set up:
+

sudo virt-host-validate QEMU: Checking for hardware virtualization : PASS QEMU: Checking if device /dev/kvm exists : PASS QEMU: Checking if device /dev/kvm is accessible : PASS QEMU: Checking if device /dev/vhost-net exists : PASS QEMU: Checking if device /dev/net/tun exists : PASS …​

== Recursos Adicionales

* https://bugzilla.redhat.com/show_bug.cgi?id=1055002
* https://kashyapc.wordpress.com/2012/01/14/nested-virtualization-with-kvm-intel/
* https://kashyapc.wordpress.com/2012/01/18/nested-virtualization-with-kvm-and-amd/