「KVM」- 常见错误及注意事项 @20210306

启动错误

#1 vmport is not available with this QEMU binary

问题描述:

启动Guest时产生如下错误:

   error: unsupported configuration: vmport is not available with this QEMU binary

问题原因:

就是不支持嘛

解决办法:

修改域定义文件,去掉<vmport/>节点,通常在<features/>中。

#2 error: Unable to get index for interface enp0s25: No such device

问题描述:

启动Guest时产生如下错误:

   error: Unable to get index for interface enp0s25: No such device

问题原因:

桥接模式的设备是硬编码的,修改域定义文件。

解决办法:

修改域定义文件(virsh edit),将在<interface>下<source>的“dev”属性,设置对应的网卡设备。

#3 Unsupported machine type

问题描述:

启动虚拟机的时候产生如下错误:

   error: Failed to start domain dns
        error: internal error: process exited while connecting to monitor:
        (process:1757): GLib-WARNING **: gmem.c:483: custom memory allocation vtable not supported
        qemu-system-x86_64: -machine pc-i440fx-2.12,accel=kvm,usb=off,dump-guest-core=off: Unsupported machine type
        Use -machine help to list supported machines!

问题原因:

在域定义文件中设置的machine类型不被QEMU支持。

解决方法:

<!--
# 使用如下命令查看支持的机器:
qemu-system-x86_64 -machine help

# 修改域定义文件中<os>下<type>的“machine”属性,设置为上述命令输出之一
-->
<os>
        <type arch='x86_64' machine='pc-i440fx-2.0'>hvm</type>
        <boot dev='hd'/>
</os>

<!--
(04/14/2019)今天又遇到了这个问题,客户机是Window 7,从别的平台迁移过来的。
参照能够正常启动的Window 7客户机,修改<type machine='pc-i440fx-2.12'>hvm</type>
-->

#4 guest CPU doesn't match specification: extra features

问题描述:

启动虚拟机的时候产生如下错误:

   error: operation failed: guest CPU doesn't match specification: extra features: x2apic,hypervisor, missing features: ht,monitor,osxsave,arat,xsaveopt,svm,extapic,ibs,skinit,wdt,lwp,tce,nodeid_msr,perfctr_core,perfctr_nb,ibpb

问题原因:

虚拟机CPU型号的设置不对,导致「Host的CPU」并不支持「你所设置的CPU型号」,主要还是指令集不支持。

解决办法:

更换Guest的CPU型号设置:

<!-- # virsh edit centos7.0 -->
<cpu mode='custom' match='exact' check='partial'>
        <model fallback='allow'>cpu64-rhel6</model>
</cpu>

<!--
!!!你需要KVM中CPU设置相关的知识:设置CPU的三种模式!!!
或者把上面的这一段删除掉。删除后,默认使用custom模式,使得持久化的guest不管从哪个host启动,将看到相同的配置。
-->

网络错误

#1 Requested operation is not valid: network 'default' is not active

问题描述:

Starting install...
ERROR    Requested operation is not valid: network 'default' is not active
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
  virsh --connect qemu:///system start fedora
otherwise, please restart your installation.

问题原因:

网络问题喽。

解决方法:

参见#3中的描述,这个两个问题的原因是类似的。

#2 no 'default' network device found

问题描述:

如题。

问题原因:

配置NAT网络的时候,选择的“default”网络,但是该网络未激活。

在KVM安装之后就包含一个名为“defalut”的网络。默认情况下,该网络未激活(State:inactive),未自启动(Autostart:no)。对应的配置为/etc/libvirt/qemu/networks/defalut.xml。

解决办法:

执行如下命令来操作该网卡:

#!/bin/sh

# 查看所有的网络
virsh net-list --all

# 启动default网络
virsh net-start default

# 设置default网络自启动
virsh net-autostart default

# 关闭default网络(不需要执行,这是关闭default网络的命令)
virsh net-destroy default

迁移错误

#1 Cannot check QEMU binary /usr/bin/kvm: No such file or directory

问题描述:

源主机为「Kali Rolling」,「目的主机」为「CentOS 7.5」。执行virsh migrate --unsafe dns qemu+ssh://172.16.0.102/system进行虚拟机迁移,输入密码后返回该错误。

问题原因:

目的主机上没有kvm命令。看似如此,实际上这个问题和虚拟机定义有关系,在两台机器上分别执行virsh dumpxml --domain centos7.0 | grep emulator命令,你会发现,Kali上的输出是<emulator>/usr/bin/kvm</emulator>,而CentOS的输出是<emulator>/usr/libexec/qemu-kvm</emulator>。究其更本是这两台主机的设备模拟器的路径不一样。「Kali」上是/usr/bin/kvm,一个脚本,是对qemu-system-x86_64的包装;而「CentOS」上没有这个/usr/bin/kvm命令,但是它也有qemu-system-x86_64命令,而且qemu-kvm的手册与qemu-system-x86_64是一样的。

突然就猜测在安装虚拟机(virt-install)的时候能否指定这个参数,看了一下virt-install的手册,看到了--qemu-commandline选项,顺着指引看到「Pass-through of arbitrary qemu commands」手册。算是有了解决方案了。

解决方法:

修改Guest定义文件:virsh edit --domain centos7.0,添加两部分内容:

<!-- 1. 头部追加 xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' -->
<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <!-- 2. 指定命令行参数 -enable-kvm -->
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
  </devices>
  <!-- 2. 指定命令行参数 -enable-kvm -->
  <qemu:commandline>
    <qemu:arg value='-enable-kvm'/>
  </qemu:commandline>
</domain>

!!!如果你直接修改(没有使用virsh edit命令)了磁盘中的配置文件,则需要重启libvirtd服务,以重新加载磁盘的配置文件,否则你使用virsh edit命令看到的还还是旧的配置!!!

参考文献:

Cloubed hangs with error `/usr/bin/kvm: No such file or directory`

#2 hostname on destination resolved to localhost

问题描述:

error: internal error: hostname on destination resolved to localhost, but migration requires an FQDN

问题原因:

目的主机的主机名解析到了localhost上。

解决方法:

修改目的主机的主机名,不要用localhost作为主机名。

参考文献:

KVM online migration

#3 CPU model Haswell-noTSX is not supported by hypervisor

问题描述:

如题,这个问题转瞬即逝,没了…………

#4 unsupported configuration: unknown CPU feature: umip

问题描述:

虚拟机进行热迁移是产生了该错误,看样子是CPU不支持该指令。

问题原因:

推测是由于「源主机」和「目的主机」的CPU不兼容导致的,因此无法进行热迁移。

#5 cannot migrate domain with 1 snapshots

问题描述:

虚拟机迁移时产生如下错误

   error: Requested operation is not valid: cannot migrate domain with 1 snapshots

问题原因:

根据错误提示,错误的原因是Guest上有快照,因此无法迁移。

解决办法:

处理掉啊,不要了,我不要镜像了,没啥用。

#!/bin/sh

virsh snapshot-list centos7.0

virsh snapshot-delete "centos7.0" --snapshotname "ss-init"

如果在迁移中想要保留镜像,那你需要执行命令导出镜像定义,然后再导入。这个过程可能要手动处理,不能使用virsh migrate命令。

#6 Cannot check QEMU binary /usr/bin/qemu-system-x86_64

问题描述:

迁移虚拟机的时候产生如下错误:

error: Cannot check QEMU binary /usr/bin/qemu-system-x86_64: No such file or directory

问题原因:

迁移虚拟机的时候,需要在「目的主机」上重新定义「域」,然而「域」定义的时候,在XML文件中引用了「目的主机」上不存在的程序(实际上是设备模拟器)。

解决办法:

安装这个程序,因为远程主机是RHEL衍生版,遂:yum install -y qemu-system-x86.x86_64

其他错误

#1 CPU mode 'custom' for x86_64 kvm domain on x86_64 host is not supported by hypervisor

问题描述:

Starting install...
ERROR    unsupported configuration: CPU mode 'custom' for x86_64 kvm domain on x86_64 host is not supported by hypervisor
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
  virsh --connect qemu:///system start fedora
otherwise, please restart your installation.

问题原因:

未知。网上有人给出了原因,但是好像并不是我的情况,参考「Trying to settup VM will PCI passthrough - Could not access KVM kernel」一文。

解决方法:

重启之后,好了…………这个不是第一次“通过重启解决KVM的问题”了。

相关文章

「KVM」- Kimchi(Web管理工具)

「libvirt」- 离线迁移

「KVM」- 虚拟机迁移

「KVM」- 环境搭建

「KVM」- 管理工具

「QEMU, KVM and libvirt」- 杂记