ວິທີເປີດໃຊ້ງານ nested virtualization ໃນ KVM

ທີມງານເອກະສານ Fedora ເວີຊັນ F36 onwards Last review: 2023-02-21
Nested virtualization ຊ່ວຍໃຫ້ທ່ານສາມາດຮັນເຄື່ອງສະເໝືອນ (VM) ຊ້ອນຢູ່ໃນ VM ອື່ນໄດ້ ໃນຂະນະທີ່ຍັງສາມາດໃຊ້ງານການເລັ່ງຄວາມໄວດ້ວຍຮາດແວຈາກເຄື່ອງແມ່ຂ່າຍ (host) ໄດ້.

ການກວດສອບວ່າລະບົບຮອງຮັບ nested virtualization ຫຼື ບໍ່

ສຳລັບໂປຣເຊດເຊີ Intel, ໃຫ້ກວດສອບໄຟລ໌ /sys/module/kvm_intel/parameters/nested. ສຳລັບໂປຣເຊດເຊີ AMD, ໃຫ້ກວດສອບໄຟລ໌ /sys/module/kvm_amd/parameters/nested. ຖ້າທ່ານເຫັນເລກ 1 ຫຼື Y, ສະແດງວ່າຮອງຮັບ nested virtualization; ຖ້າເຫັນເລກ 0 ຫຼື N, ສະແດງວ່າບໍ່ຮອງຮັບ.

ຕົວຢ່າງ:

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

ການເປີດໃຊ້ງານ nested virtualization

ເພື່ອເປີດໃຊ້ງານ nested virtualization ສຳລັບໂປຣເຊດເຊີ Intel:

  1. ປິດ VM ທັງໝົດທີ່ກຳລັງເຮັດວຽກຢູ່ ແລະ ຖອນ (unload) ໂມດູນ kvm_intel:

    $ sudo modprobe -r kvm_intel
  2. ເປີດໃຊ້ງານຄຸນສົມບັດ nesting:

    $ sudo modprobe kvm_intel nested=1
  3. 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:

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

    $ sudo modprobe -r kvm_amd
  2. ເປີດໃຊ້ງານຄຸນສົມບັດ nesting:

    $ sudo modprobe kvm_amd nested=1
  3. 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

ການກຳນົດຄ່າ nested virtualization ໃນ virt-manager

ກຳນົດຄ່າ VM ຂອງທ່ານເພື່ອໃຊ້ງານ nested virtualization:

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

  2. 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).

    Using host-passthrough is not recommended for general usage. It should only be used for nested virtualization purposes.
  3. Click Apply.

ການທົດສອບ nested virtualization

  1. Start the virtual machine.

  2. On the virtual machine, run:

    $ sudo dnf group install virtualization
  3. 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
      ...