首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即使qemu-kvm工作,Libvirt也没有KVM功能。

即使qemu-kvm工作,Libvirt也没有KVM功能。
EN

Server Fault用户
提问于 2020-02-06 13:20:46
回答 4查看 15.6K关注 0票数 5

我已经了解到,CirrusCI在他们的免费包中提供嵌套虚拟化,用于公共恢复,我正在尝试利用它来测试我的“Ansible”游戏手册。

不幸的是,libvirt坚持认为CI环境不支持完全虚拟化。所有的检查(我都知道)证明了相反的情况,当直接调用qemu时,qemu工作得很好。我几乎可以肯定,问题在于我的主机操作系统配置,而不是CI引擎。我见过其他人为了他们的目的而在CirrusCI上使用完全虚拟化(Android仿真、氧化还原测试)。

我使用Debian 10作为主机系统,使用DockerHub提供的瘦映像,并安装了以下额外的软件包(--不安装-建议):

代码语言:javascript
复制
bridge-utils  libguestfs-tools       python3-dev
coreutils     libosinfo-bin          python3-venv
cpu-checker   libssl-dev             qemu-kvm
curl          libvirt-clients        qemu-kvm
gcc           libvirt-daemon         qemu-utils
gpg           libvirt-daemon-system  systemd
gpg-agent     linux-image-amd64      vagrant
iproute2      make                   vagrant-libvirt
kmod          procps                 virt-goodies
libc-dev      python3                virtinst
libffi-dev

基像CirrusCI配置

我可能错过了什么?当qemu完美工作时,为什么libvirt会告诉我们没有KVM呢?

libvirt错误

代码语言:javascript
复制
Error while creating domain: Error saving the server: Call to virDomainDefineXML failed: invalid argument: could not find capabilities for domaintype=kvm

virsh capabilities只包含条目。

不一致行为的

演示

任何基于libvirt的工具都无法调用KVM:

代码语言:javascript
复制
$ virt-install --import --virt-type kvm --name debian10-vm --memory 512 --disk path=/debian.qcow2,format=qcow2 --os-variant debian10 --noautoconsole || echo "Exit code: $?"
ERROR    Host does not support domain type kvm for virtualization type 'hvm' arch 'x86_64'
Exit code: 1

但是,qemu在直接执行时工作:

代码语言:javascript
复制
$ kvm -nographic /debian.qcow2
cSeaBIOS (version 1.12.0-1)
iPXE (http://ipxe.org) 00:03.0 C980 PCI2.10 PnP PMM+07F900F0+07ED00F0 C980
Press Ctrl-B to configure iPXE (PCI 00:03.0)...

Booting from Hard Disk...
GNU GRUB  version 2.02+dfsg1-20
...

全CI日志

诊断学

  • lsmod显示kvm和kvm_intel被加载。
  • cat /proc/cpuinfo -包含vmx标志
  • lscpu -虚拟化类型:完全
  • kvm-ok -好的
  • ls -l /dev/kvm -存在,由root拥有:rdma
  • ls -l /var/run/libvirt -套接字存在,由root拥有:root
  • whoami -根
  • groups $(whoami) -根
  • systemctl status - systemd未启动,libvirtd通过CI规则启动。
  • virt-host-validate -所有的检查通行证,除了IOMMU -不应该对我的用例很重要。

完整的列表可以在CI测井的"kvm_before“部分找到。

EN

回答 4

Server Fault用户

回答已采纳

发布于 2020-02-06 15:50:05

大多数发行版libvirt包将被配置为以qemu:qemu用户的身份运行qemu。请参阅由UID+GID报告的virsh --connect qemu:///system capabilities | grep baselabel。如果发行版是这样的,那么qemu没有访问/dev/kvm的权限,因此libvirt没有宣传kvm支持。chmod 666 /dev/kvm应该修复它。这是Fedora FWIW中的缺省值。

票数 6
EN

Server Fault用户

发布于 2022-03-01 00:30:28

对于ubuntu,我也有过同样的经历。

我运行这个是为了确保没有任何东西被移除

代码语言:javascript
复制
sudo apt-get install qemu uml-utilities virt-manager git wget libguestfs-tools p7zip-full uml-utilities virt-viewer qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils -y

都安装好了这太奇怪了。

代码语言:javascript
复制
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'qemu-system-x86' instead of 'qemu-kvm'
bridge-utils is already the newest version (1.7-1ubuntu2).
git is already the newest version (1:2.32.0-1ubuntu1).
wget is already the newest version (1.21-1ubuntu3).
libguestfs-tools is already the newest version (1:1.44.1-1ubuntu6).
p7zip-full is already the newest version (16.02+dfsg-8).
uml-utilities is already the newest version (20070815.4-1).
virt-manager is already the newest version (1:3.2.0-3).
virt-viewer is already the newest version (7.0-2build1).
qemu-system-x86 is already the newest version (1:6.0+dfsg-2expubuntu1.2).
qemu is already the newest version (1:6.0+dfsg-2expubuntu1.2).
libvirt-clients is already the newest version (7.6.0-0ubuntu1.1).
libvirt-daemon-system is already the newest version (7.6.0-0ubuntu1.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我比重新运行用户组和bam的命令更开始工作。超级奇怪,但可能对他人有帮助

代码语言:javascript
复制
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
票数 1
EN

Server Fault用户

发布于 2020-09-23 12:02:33

这是对科尔罗宾逊的回答的延伸,这对我在Ubuntu上找出了一个类似的问题很有帮助。

我认为Debian的方式与Ubuntu相同,在Ubuntu中,您需要安装qemu-system-x86,/dev/kvm神奇地变成了kvm组的可写组和所有者(而不是0600根:root)。

Debian/Ubuntu上的libvirtd默认使用libvirt-qemu用户,该用户的主要组是kvm

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1002043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档