KVM中开启嵌套虚拟化

栏目: 服务器 · 发布时间: 5年前

内容简介:KVM 利用 CPU 虚拟化扩展的嵌套虚拟化可以先检查下宿主上是否启用了嵌套虚拟化,可以检查文件

起步

KVM 利用 CPU 虚拟化扩展的 Intel VT-xAMD-V ,因此具有出色的性能。KVM 不会模拟硬件,但会使用 QEMU。

启用嵌套虚拟化

嵌套虚拟化 nested 可通过内核参数来启用该功能,能够让虚拟机具有物理CPU特性,能够模拟 vmx 或者 svm 硬件虚拟化。此特性需要 linux 内核 3.x 版本,文档看 这里 ,contos6 需要升级内核,contos7 默认已支持该特性但未启用。

校验

可以先检查下宿主上是否启用了嵌套虚拟化,可以检查文件 /sys/module/kvm_intel/parameters/nested :

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

N 表示未开启。

启用

要启用这个特性需要先关闭所有的虚拟机。有两种启用方式,一种是通过载入kvm模块时设置,这种方式重启宿主后失效;另一种是设置模块的配置文件,得到永久支持。

载入kvm模块时设置

# modprobe -r kvm_intel             # 卸载KVM模块 如果是AMD: modprobe -r kvm_amd
# modprobe kvm_intel nested=1       # 重新加载KVM
# cat /sys/module/kvm_intel/parameters/nested  # 校验
Y

修改KVM模块的配置文件

# echo "options kvm-intel nested=1" >> /etc/modprobe.d/kvm-intel.conf
# rmmod kvm-intel
# modprobe  kvm-intel
# cat /sys/module/kvm_intel/parameters/nested
Y

在虚拟机中启用嵌套虚拟化

在虚拟机的配置中还要设置为主机模式才能实现嵌套。具体是把 CPU 那行改为 <cpu mode='host-model' check='partial'/> :

<features>
  <acpi/>
  <apic/>
  <pae/>
</features>
<cpu mode='host-model' check='partial'>
  <model fallback='allow'/>
</cpu>

启动虚拟机后可以用 dumpxml 看到cpu上的更新:

# virsh dumpxml vm_nested
<cpu mode='custom' match='exact' check='full'>
  <model fallback='forbid'>Haswell-IBRS</model>
  <vendor>Intel</vendor>
  <feature policy='require' name='vme'/>
  <feature policy='disable' name='ds'/>
  <feature policy='disable' name='acpi'/>
  <feature policy='require' name='ss'/>
  <feature policy='disable' name='ht'/>
  <feature policy='disable' name='tm'/>
  <feature policy='disable' name='pbe'/>
  <feature policy='disable' name='dtes64'/>
  <feature policy='disable' name='monitor'/>
  <feature policy='disable' name='ds_cpl'/>
  <feature policy='require' name='vmx'/>
  <feature policy='disable' name='smx'/>
  <feature policy='disable' name='est'/>
  <feature policy='disable' name='tm2'/>
  <feature policy='disable' name='xtpr'/>
  <feature policy='disable' name='pdcm'/>
  <feature policy='disable' name='dca'/>
  <feature policy='disable' name='osxsave'/>
  <feature policy='require' name='f16c'/>
  <feature policy='require' name='rdrand'/>
  <feature policy='disable' name='arat'/>
  <feature policy='disable' name='tsc_adjust'/>
  <feature policy='require' name='stibp'/>
  <feature policy='require' name='xsaveopt'/>
  <feature policy='require' name='pdpe1gb'/>
  <feature policy='require' name='abm'/>
  <feature policy='disable' name='hle'/>
  <feature policy='disable' name='rtm'/>
  <feature policy='require' name='hypervisor'/>
</cpu>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beginning PHP and MySQL 5

Beginning PHP and MySQL 5

W. Jason Gilmore / Apress / 2006-01-23 / USD 44.99

Beginning PHP and MySQL 5: From Novice to Professional, Second Edition offers comprehensive information about two of the most prominent open source technologies on the planet: the PHP scripting langua......一起来看看 《Beginning PHP and MySQL 5》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具