错误创建libvirt kvm域:无效参数:无法获得/usr/libexec/qemu-kvm type = kvm的首选机器

发布于 2025-02-03 19:28:37 字数 2085 浏览 3 评论 0原文

我正在尝试在嵌套虚拟化中运行ovirt节点的主机上创建以下域(它不会永远嵌套,而只是现在):

<domain type="kvm">
    <name>clara</name>
    <memory unit="MiB">4096</memory>
    <vcpu>2</vcpu>
    <os>
        <type>hvm</type>
        <boot dev="hd"></boot>
    </os>
    <features>
        <pae></pae>
        <acpi></acpi>
        <apic></apic>
    </features>
    <cpu></cpu>
    <devices>
        <disk type="volume" device="disk">
            <driver name="qemu" type="qcow2"></driver>
            <source pool="default" volume="clara-rootfs"></source>
            <target dev="vda" bus="scsi"></target>
            <wwn>05abcd62857fe8f1</wwn>
        </disk>
        <disk type="file" device="cdrom">
            <driver name="qemu" type="raw"></driver>
            <source file="/var/lib/libvirt/images/cloudinit.clara.iso"></source>
            <target dev="hdd" bus="ide"></target>
        </disk>
        <controller type="scsi" model="virtio-scsi"></controller>
        <interface type="bridge">
            <mac address="E2:F5:2A:A9:4A:42"></mac>
            <source bridge="bridge0"></source>
            <model type="virtio"></model>
        </interface>
        <channel type="unix">
            <target type="virtio" name="org.qemu.guest_agent.0"></target>
        </channel>
        <graphics type="spice" autoport="yes"></graphics>
        <rng model="virtio">
            <backend model="random">/dev/urandom</backend>
        </rng>
    </devices>
</domain>

当我这样做时,我会遇到此错误:

# virsh define clara.xml 
error: Failed to define domain from clara.xml
error: invalid argument: could not get preferred machine for /usr/libexec/qemu-kvm type=kvm

此错误是什么意思,以及如何我修理了吗?

I'm trying to create the following domain on a host running oVirt Node in nested virtualization (it won't be nested forever, just for now):

<domain type="kvm">
    <name>clara</name>
    <memory unit="MiB">4096</memory>
    <vcpu>2</vcpu>
    <os>
        <type>hvm</type>
        <boot dev="hd"></boot>
    </os>
    <features>
        <pae></pae>
        <acpi></acpi>
        <apic></apic>
    </features>
    <cpu></cpu>
    <devices>
        <disk type="volume" device="disk">
            <driver name="qemu" type="qcow2"></driver>
            <source pool="default" volume="clara-rootfs"></source>
            <target dev="vda" bus="scsi"></target>
            <wwn>05abcd62857fe8f1</wwn>
        </disk>
        <disk type="file" device="cdrom">
            <driver name="qemu" type="raw"></driver>
            <source file="/var/lib/libvirt/images/cloudinit.clara.iso"></source>
            <target dev="hdd" bus="ide"></target>
        </disk>
        <controller type="scsi" model="virtio-scsi"></controller>
        <interface type="bridge">
            <mac address="E2:F5:2A:A9:4A:42"></mac>
            <source bridge="bridge0"></source>
            <model type="virtio"></model>
        </interface>
        <channel type="unix">
            <target type="virtio" name="org.qemu.guest_agent.0"></target>
        </channel>
        <graphics type="spice" autoport="yes"></graphics>
        <rng model="virtio">
            <backend model="random">/dev/urandom</backend>
        </rng>
    </devices>
</domain>

When I do, I get this error:

# virsh define clara.xml 
error: Failed to define domain from clara.xml
error: invalid argument: could not get preferred machine for /usr/libexec/qemu-kvm type=kvm

What does this error mean, and how do I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月夜 2025-02-10 19:28:37

弄清楚了。由于两个问题的组合而发生了此错误:

  1. &lt; type&gt; hvm&lt;/type&gt;中未指定机器类型,并且在尝试发现“首选”默认值时发生了错误。设置Arch机器字段显示 real 问题:
  2. kvm在我的设置中不可用,因为主机是在嵌套虚拟化中运行。更改&lt; domain type =“ kvm”&gt; to &lt; domain type =“ qemu”&gt;使其正常工作。

如果您在Terraform中进行此操作,则可以通过添加此配置来修改生成的XML文件:

resource "libvirt_domain" "vm" {
  # ...

  xml {
    xslt = <<-EOT
      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0"
                      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>

        <!-- Copy everything from the generated XML -->
        <xsl:template match="node()|@*">
          <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
          </xsl:copy>
        </xsl:template>

        <!-- Set domain#type to 'qemu' for nested virtualization -->
        <xsl:template match="/domain/@type">
          <xsl:attribute name="type">
              <xsl:value-of select="'qemu'"/>
          </xsl:attribute>
        </xsl:template>

      </xsl:stylesheet>
    EOT
  }
}

Figured it out. This error happened because of a combination of two problems:

  1. The machine type was not specified in <type>hvm</type>, and an error happened when trying to discover the "preferred" default value. Setting the arch and machine fields revealed the real problem:
  2. kvm is not available in my setup because the host is running in nested virtualization. Changing <domain type="kvm"> to <domain type="qemu"> made it work.

If you are doing this in Terraform, you can modify the generated XML file by adding this configuration:

resource "libvirt_domain" "vm" {
  # ...

  xml {
    xslt = <<-EOT
      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0"
                      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>

        <!-- Copy everything from the generated XML -->
        <xsl:template match="node()|@*">
          <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
          </xsl:copy>
        </xsl:template>

        <!-- Set domain#type to 'qemu' for nested virtualization -->
        <xsl:template match="/domain/@type">
          <xsl:attribute name="type">
              <xsl:value-of select="'qemu'"/>
          </xsl:attribute>
        </xsl:template>

      </xsl:stylesheet>
    EOT
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文