Saturday, February 10, 2018

enable nested virtualization on kvm/qemu

1- enable the nested visualization feature, /etc/modprobe.d/qemu-system-x86.conf
options kvm_intel nested=1

2- check whether our system support the nested vm
$  cat /sys/module/kvm_intel/parameters/nested
should be Y or 1

$ 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





3- our main vm xml file
<domain type="kvm">
  <name>bionic-nested</name>
  <memory>2048576</memory>
  <clock offset="utc"/>
<cpu mode='host-passthrough'>
</cpu>
  <vcpu>4</vcpu>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <os>
    <type>hvm</type>
    <boot dev="hd"/>
  </os>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <graphics type="vnc" port="-1"/>
    <interface type="bridge">
      <source bridge="virbr0"/>
      <model type="virtio"/>
    </interface>
    <input bus="ps2" type="mouse"/>
    <serial type="pty">
      <target port="0"/>
    </serial>
    <serial type="tcp">
      <source host="127.0.0.1" mode="bind" service="39180"/>
      <protocol type="raw"/>
      <target port="1"/>
    </serial>
    <disk device="disk" type="file">
      <target bus="virtio" dev="vda"/>
      <source file="/home/tun/iso/kvmqemu/bionic-nested.qcow2"/>
      <driver type="qcow2" name="qemu"/>
    </disk>
  </devices>
</domain>



- run it
$ virtsh create main.xml


4-  our nested inside vm xml file
<domain type="kvm">
  <name>bionic</name>
  <memory>448576</memory>
  <clock offset="utc"/>
  <vcpu>1</vcpu>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <os>
    <type>hvm</type>
    <boot dev="hd"/>
  </os>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <graphics type="vnc" port="-1"/>
    <interface type="bridge">
      <source bridge="virbr0"/>
      <model type="virtio"/>
    </interface>
    <serial type="tcp">
      <source host="127.0.0.1" mode="bind" service="39180"/>
      <protocol type="raw"/>
      <target port="1"/>
    </serial>
    <disk device="disk" type="file">
      <target bus="virtio" dev="vda"/>
      <source file="/home/vtun/bionic.qcow2"/>
      <driver type="qcow2" name="qemu"/>
    </disk>
  </devices>
</domain>


- to run it
$ virsh create nested.xml




No comments:

Post a Comment