带有 qemu-system-aarch64

问题描述

从这个 manual 编译 qemu

尝试使用 qemu-system-aarch64 在 Apple Silicon 上运行 this,但出现错误

错误:内部错误:无法启动 QEMU 二进制文件 /usr/local/bin/qemu-system-aarch64 进行探测:qemu-system-aarch64:无效加速器 kvm 无法分配动态转换器缓冲区

这是 XML:

<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    <name>ubuntu</name>
    <uuid>2005CB24-522A-4485-9B9A-E60A61D9F8CF</uuid>
    <memory unit='GB'>2</memory>
    <cpu mode='custom'>
        <model>Westmere</model>
    </cpu>
    <vcpu>2</vcpu>
    <features>
        <acpi/>
        <apic/>
    </features>
    <os>
        <type arch='aarch64' machine='cortex-a57'>hvf</type>
        <bootmenu enable='yes'/>
    </os>
    <clock offset='localtime'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <pm>
        <suspend-to-mem enabled='no'/>
        <suspend-to-disk enabled='no'/>
    </pm>
    <devices>
        <emulator>/usr/local/bin/qemu-system-aarch64</emulator>
        <controller type='usb' model='ehci'/>
        <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source file='/Users/matthias/VM/Ubuntu_20.04-LTS/disk.qcow2'/>
            <target dev='vda' bus='virtio'/>
        </disk>
        <!--disk type='file' device='cdrom'>
            <source file='/Users/matthias/VM/Ubuntu_20.04-LTS/ubuntu-20.04.2-live-server-arm64.iso'/>
            <target dev='sdb' bus='sata'/>
        </disk-->
        <console type='pty'>
            <target type='serial'/>
        </console>
        <input type='tablet' bus='usb'/>
        <input type='keyboard' bus='usb'/>
        <graphics type='vnc' port='5900' listen='127.0.0.1'/>
        <video>
            <model type='virtio' vram='16384'/>
        </video>
    </devices>
    <seclabel type='none'/>
    <qemu:commandline>
        <!--qemu:arg value='-machine'/>
        <qemu:arg value='type=q35,accel=hvf'/>
        <qemu:arg value='-netdev'/>
        <qemu:arg value='user,id=n1,hostfwd=tcp::2222-:22'/>
        <qemu:arg value='-device'/>
        <qemu:arg value='virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19'/-->
    <qemu:arg value='-accel hvf -m 2048 -cpu cortex-a57 -M virt,highmem=off'/>
    <qemu:arg value='-drive file=/usr/local/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on'/>
    <qemu:arg value='-drive file=ovmf_vars.fd,format=raw'/>
    <qemu:arg value='-serial telnet::4444,server,Nowait'/>
    <qemu:arg value='-device virtio-blk-device,drive=hd0,serial="dummyserial"'/>
    <qemu:arg value='-device virtio-net-device,netdev=net0'/>
    <qemu:arg value='-netdev user,id=net0,hostfwd=tcp:127.0.0.1:2222-0.0.0.0:22'/>
    <qemu:arg value='-vga none -device ramfb'/>
    <qemu:arg value='-device usb-ehci -device usb-kbd -device usb-mouse -usb'/>
    <qemu:arg value='-nographic -serial mon:stdio'/>
    </qemu:commandline>
</domain>

感谢任何反馈!

解决方法

您需要将 -machine accel=hvf,highmem=off 作为 QEMU 参数传递。我在 https://github.com/ihsakashi/VM 中有一个完全可用的 Libvirt + QEMU 解决方案。 Libvirt 无法使用 uname 识别 aarch64 架构,因为 macOS 给出了一些不同的东西。已修补。

,

QEMU 似乎在尝试使用 KVM 加速器,这显然在 macos 主机上不起作用,因此 QEMU 报告“无效的加速器 kvm”。然后它尝试回退到 TCG(纯仿真),这也失败了,因为涉及 mprotect() 的 macos 错误,因此“无法分配动态转换器缓冲区”。 (最新的上游 QEMU 在提交 c118881ee607dcac 中有一个解决方法,但您不需要它,因为您只是遇到它,因为实际上没有使用 hvf。)

我认为这是因为您的 XML 语法不正确,所以 QEMU 没有看到您试图告诉它使用 hvf。具体来说,XML中的每个“qemu:arg”标签必须指定一个命令行参数词,所以如果你想说“-accel hvf”你必须写

 <qemu:arg value='-accel'>
 <qemu:arg value='hvf'>

等用于您要指定的所有其他选项和参数。 (您可以看到您注释掉的 q35 选项都是以这种方式指定的,这与您为虚拟机添加的选项不同:例如,查看 -netdev 在那里处理的内容与您拥有的内容之间的区别。 )

如果您尝试在 XML 中传递更长的字符串,那么 QEMU 会将其视为带有嵌入空格的单个长命令行参数,然后它可能会将其视为非常奇怪的磁盘映像文件名或抱怨无效。

,

感谢您的回答!更改了 XML。使用 this 自行编译 libvirt-7.1.0,但没有影响。同样的错误:

错误:无法从 ubuntu.xml 定义域 错误:内部错误:无法启动 QEMU 二进制文件 /usr/local/bin/qemu-system-aarch64 进行探测:qemu-system-aarch64:无效加速器 kvm 无法分配动态转换器缓冲区

    <name>ubuntu</name>
    <uuid>2005CB24-522A-4485-9B9A-E60A61D9F8CF</uuid>
    <memory unit='GB'>2</memory>
    <cpu mode='custom'>
        <model>Westmere</model>
    </cpu>
    <vcpu>2</vcpu>
    <features>
        <acpi/>
        <apic/>
    </features>
    <os>
        <type arch='aarch64' machine='virt'>hvm</type>
        <bootmenu enable='yes'/>
    </os>
    <clock offset='localtime'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <pm>
        <suspend-to-mem enabled='no'/>
        <suspend-to-disk enabled='no'/>
    </pm>
    <devices>
        <emulator>/usr/local/bin/qemu-system-aarch64</emulator>
        <controller type='usb' model='ehci'/>
        <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source file='/Users/user/VM/Ubuntu_20.04-LTS/disk.qcow2'/>
            <target dev='vda' bus='virtio'/>
        </disk>
        <!--disk type='file' device='cdrom'>
            <source file='/Users/user/VM/Ubuntu_20.04-LTS/ubuntu-20.04.2-live-server-arm64.iso'/>
            <target dev='sdb' bus='sata'/>
        </disk-->
        <console type='pty'>
            <target type='serial'/>
        </console>
        <input type='tablet' bus='usb'/>
        <input type='keyboard' bus='usb'/>
        <graphics type='vnc' port='5900' listen='127.0.0.1'/>
        <video>
            <model type='virtio' vram='16384'/>
        </video>
    </devices>
    <seclabel type='none'/>
    <qemu:commandline>
        <qemu:arg value='-accel'/>
        <qemu:arg value='hvf'/>
        <qemu:arg value='-netdev'/>
        <qemu:arg value='user,id=n1,hostfwd=tcp::2222-:22'/>
        <qemu:arg value='-device'/>
        <qemu:arg value='virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19'/>
    </qemu:commandline>
</domain>
,

您必须应用此补丁: https://bugs.launchpad.net/qemu/+bug/1914849/comments/3

然后重新编译。这似乎阻止了这个错误的发生。但是,我正在使用与您相同的教程,并且还需要进行一些其他更改。

到目前为止,我只知道我需要参考这个 EFI 固件: https://www.sevarg.net/images/2021-qemu-m1/QEMU_EFI.fd (参考本教程 - https://www.sevarg.net/2021/01/09/arm-mac-mini-and-boinc/

我已经在 OS XML Block 中尝试过,但似乎找不到:

    <os firmware='efi'>
        <type>hvm</type>
        <loader readonly='yes' secure='no' type='pflash'>/Users/darren/Documents/VMs/QEMU_EFI.fd</loader>
        <boot dev='hd'/>
        <bootmenu enable='yes'/>
        <smbios mode='sysinfo'/>
        <bios useserial='yes' rebootTimeout='0'/>
    </os>

因此,我将 UEFI BIOS 引用为命令行参数。

无论如何,这是我的完整 XML:

<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    <name>ubuntu1</name>
    <uuid>2005CB24-522A-4485-9B9A-E60A61D9F8CF</uuid>
    <memory unit='GB'>2</memory>
    <cpu mode='custom'>
        <model>cortex-a72</model>
    </cpu>
    <vcpu>1</vcpu>
    <features>
        <apic/>
    </features>
    <os>
        <type arch='aarch64' machine='virt'>hvm</type>
        <bootmenu enable='yes'/>
    </os>
    <clock offset='localtime'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <devices>
        <emulator>/usr/local/bin/qemu-system-aarch64</emulator>
        <controller type='usb' model='ehci'/>
        <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source file='/Users/darren/Documents/VMs/ubuntu1.qcow2'/>
            <target dev='vda' bus='virtio'/>
        </disk>
        <console type='pty'>
            <target type='serial'/>
        </console>
        <input type='tablet' bus='usb'/>
        <input type='keyboard' bus='usb'/>
        <graphics type='vnc' port='5900' listen='127.0.0.1'/>
        <video>
            <model type='virtio' vram='16384'/>
        </video>
    </devices>
    <seclabel type='none'/>
    <qemu:commandline>
        <qemu:arg value='-accel'/>
        <qemu:arg value='hvf'/>
        <qemu:arg value='-netdev'/>
        <qemu:arg value='user,hostfwd=tcp::2222-:22'/>
        <qemu:arg value='-device'/>
        <qemu:arg value='virtio-gpu-pci,addr=0x19'/>
        <qemu:arg value='-bios'/>
        <qemu:arg value='/Users/darren/Documents/VMs/QEMU_EFI.fd'/>
    </qemu:commandline>
</domain>

现在我收到此错误: 错误:无法启动域“ubuntu1” 错误:内部错误:未定义的硬件架构