Mac OSX 与 Linux 上使用 qemu 的嵌套虚拟化(Intel VT-x)

Mac OSX 与 Linux 上使用 qemu 的嵌套虚拟化(Intel VT-x)

我知道 kvm-qemu 支持 Linux 上的 Intel (VT-x) 嵌套虚拟化,因为我有这个工作。不过,我在以 os x 为主机的 mac 上无法使用此功能。

我的配备双核 Intel i5 的 Macbook Air 支持 VT-x 虚拟化。我知道这一点是因为该命令显示“VMX”:

$ sysctl -a | grep machdep.cpu.features

我使用以下命令启动 qemu(qemu-system-x86_64,版本 4.2.0):

$ qemu-system-x86_64 -m 2048 -vga virtio -usb -device usb-tablet -show-cursor -enable-kvm -drive file=~/vms-qemu/lmde.qcow2 -accel hvf -cpu 主机,vmx

这给了我一个警告:“主机不支持请求的功能:CPUID.01H:ECX.vmx [位5]”。

在虚拟机中,运行 Linux Mint Debian 版的客户机,虚拟化不可用,正如警告所预期的那样。这由 libvirt-clients 包中的命令 virt-host-validate 显示。此外,命令 lscpu 也不是展示:

虚拟化:VT-x

虚拟机管理程序供应商:KVM

虚拟化类型:全虚拟化

为什么 Qemu 警告主机不支持 VMX?我问是因为主机/确实/支持此功能。多年来,Apple 一直默认启用此功能(https://support.apple.com/en-us/HT203296)。

我成功地在 Linux 主机上启用了嵌套虚拟化,并在 qemu (2.8.1) 中使用了 Linux guest 虚拟机。为此,我必须在 /etc/modprobe.d/kvm-intel.conf 中设置选项“options kvm-intel Nested=Y”。 Mac OSX 上是否需要类似的东西才能为来宾提供 VT-x 硬件辅助虚拟化?

答案1

#!/bin/bash

# Check if VT-x (VMX) is supported by the CPU
cpu_features=$(sysctl -a | grep machdep.cpu.features)
if [[ $cpu_features == *"VMX"* ]]; then
    echo "VT-x (VMX) is supported by the CPU"
else
    echo "VT-x (VMX) is not supported by the CPU"
fi

# Check if nested virtualization is enabled on the host
nested=$(sysctl -a | grep machdep.cpu.extfeatures)
if [[ $nested == *"VMX"* ]]; then
    echo "Nested virtualization is enabled on the host"
else
    echo "Nested virtualization is not enabled on the host"
fi

# Check if HVF (Apple Hypervisor Framework) is being used
hypervisor=$(sysctl -n kern.hv_support)
if [[ $hypervisor == "1" ]]; then
    echo "HVF (Apple Hypervisor Framework) is being used"
else
    echo "HVF (Apple Hypervisor Framework) is not being used"
fi

# Check if VT-x is exposed to the guest VM
qemu_capabilities=$(qemu-system-x86_64 -cpu help)
if [[ $qemu_capabilities == *"vmx"* ]]; then
    echo "VT-x (VMX) is exposed to the guest VM"
else
    echo "VT-x (VMX) is not exposed to the guest VM"
fi

# Check if nested virtualization is enabled inside the guest VM
guest_capabilities=$(qemu-system-x86_64 -cpu help | grep "vmxvmcs")
if [[ $guest_capabilities == *"vmxvmcs"* ]]; then
    echo "Nested virtualization is enabled inside the guest VM"
else
    echo "Nested virtualization is not enabled inside the guest VM"
fi

相关内容