如何啟用巢狀虛擬化以便在 KVM 虛擬機器內使用 VirtualBox?

如何啟用巢狀虛擬化以便在 KVM 虛擬機器內使用 VirtualBox?

我們有一個 KVM 管理程式(L0AMD、核心:)Linux level0kvmhypervisor 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux,它運行一個虛擬機,我想將其用作嵌套 VirtualBox 管理程式(L1)。所以我想做的是在 KVM 中運行 VirtualBox。有關 KVM 管理程序的一些詳細資訊 ( L0):

# cat /proc/cpuinfo
processor       : 0 ... 23
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 113
model name      : AMD Ryzen 9 3900 12-Core Processor
stepping        : 0
microcode       : 0x8701021
cpu MHz         : 2193.155
cache size      : 512 KB
physical id     : 0
siblings        : 24
core id         : 0
cpu cores       : 12
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 16
wp              : yes
flags           : ... svm ...
bugs            : sysret_ss_attrs spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 6188.58
TLB size        : 3072 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14]
# dpkg --list | egrep -- "(kvm|libvirt)" | sed 's/amd64.*//g'
ii  libsys-virt-perl                     5.0.0-1                             
ii  libvirt-clients                      5.0.0-4+deb10u1                     
ii  libvirt-daemon                       5.0.0-4+deb10u1                     
ii  libvirt-daemon-system                5.0.0-4+deb10u1                     
ii  libvirt-glib-1.0-0:
ii  libvirt0:
ii  python3-libvirt                      5.0.0-1                             
ii  qemu-kvm                             1:3.1+dfsg-8+deb10u8

嵌套選項也被啟用:

# cat /sys/module/kvm_amd/parameters/nested 
1

在安裝 VirtualBox 的 KVM 虛擬機器內(L1):我嘗試啟動由 Vagrant 建立的虛擬機器並收到以下錯誤訊息:

...
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "357a07b4-7d81-4336-9ea6-0dbf0ab49d18", "--type", "headless"]                                                                 
Stderr: VBoxManage: error: AMD-V is not available (VERR_SVM_NO_SVM)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

這些是 VirtualBox 虛擬機器管理程式的 KVM XML CPU 設定L1

<vcpu placement='static'>1</vcpu>
<cpu mode='host-model' check='partial'>
  <model fallback='allow'/>
</cpu>

我相信這裡必須做出一些改變,但我不太確定是什麼。我找不到有關該主題的任何資源,這就是我在這裡詢問的原因。如何讓 VirtualBox 管理程式 ( L1) 在 KVM 虛擬機器內運作以啟動 VM?

任何幫助將不勝感激。

答案1

<cpu mode='host-passthrough'>
    <feature policy='require' name='svm'/>
</cpu>

在虛擬機器設定檔中使用 AMD cpu 的這些設定。

相關內容