How to enable nested virtualization in KVM

本文介绍如何在KVM环境下配置嵌套虚拟化,包括检查硬件支持、激活嵌套虚拟化特性以及在virt-manager中设置。适用于Intel及AMD处理器。

Learn how to run a virtual machine within a virtual machine.

Enabling nested virtualization in KVM

Nested virtualization allows you to run a virtual machine (VM) inside another VM while still using hardware acceleration from the host.

Checking if nested virtualization is supported

For Intel processors, check the /sys/module/kvm_intel/parameters/nested file. For AMD processors, check the /sys/module/kvm_amd/parameters/nested file. If you see 1 or Y, nested virtualization is supported; if you see 0 or N, nested virtualization is not supported.

For example:

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

Enabling nested virtualization

To enable nested virtualization for Intel processors:

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

    # modprobe -r kvm_intel
  2. Activate the nesting feature:

    # 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:

    # modprobe -r kvm_amd
  2. Activate the nesting feature:

    # 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

Configuring nested virtualization in virt-manager

Configure your VM to use 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.

Testing nested virtualization

  1. Start the virtual machine.

  2. On the virtual machine, run:

    # dnf group install virtualization
  3. Verify that the virtual machine has virtualization correctly set up:

    # virt-host-validate
      QEMU: Checking for hardware virtualization                                 : PASS
      QEMU: Checking for device /dev/kvm                                         : PASS
      QEMU: Checking for device /dev/vhost-net                                   : PASS
      QEMU: Checking for device /dev/net/tun                                     : PASS
      LXC: Checking for Linux >= 2.6.26                                          : PASS

Additional resources

转载于:https://my.oschina.net/u/1777508/blog/1943875

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值