2

从本手册编译的 qemu

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

错误:内部错误:无法启动 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,if=pflash,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>

感谢任何反馈!

4

4 回答 4

1

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

于 2021-05-24T05:46:58.963 回答
0

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 选项都是以这种方式指定的,这与您为 virt 机器添加的选项不同:例如,看看那里的 -netdev 处理与您拥有的选项之间的区别。 )

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

于 2021-03-28T14:13:14.003 回答
0

你必须应用这个补丁: 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,id=n1,hostfwd=tcp::2222-:22'/>
        <qemu:arg value='-device'/>
        <qemu:arg value='virtio-gpu-pci,netdev=n1,bus=pcie.0,addr=0x19'/>
        <qemu:arg value='-bios'/>
        <qemu:arg value='/Users/darren/Documents/VMs/QEMU_EFI.fd'/>
    </qemu:commandline>
</domain>

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

于 2021-03-31T10:51:45.840 回答
0

我发现使用 shell 直接调用 QEMU 比使用 XML 和 virsh 更容易。这是我正在使用的脚本:

qemu-system-aarch64 \
         -machine virt,accel=hvf,highmem=off \
         -cpu cortex-a72 -smp 2 -m 4G \
         -device intel-hda -device hda-output \
         -device qemu-xhci \
         -device virtio-gpu-gl-pci \
         -device usb-kbd \
         -device virtio-mouse-pci \
         -display cocoa,gl=es \
             -device e1000,netdev=net0 \
             -netdev user,id=net0 \
         -drive "if=pflash,format=raw,file=#{firmware_path}/edk2-aarch64-code.fd,readonly=on" \
         -drive "if=pflash,format=raw,file=#{firmware_path}/edk2-arm-vars.fd,discard=on" \
         -drive "if=virtio,format=qcow2,file=#{disk_file_location},discard=on" \
             -chardev qemu-vdagent,id=spice,name=vdagent,clipboard=on \
             -device virtio-serial-pci \
             -device virtserialport,chardev=spice,name=com.redhat.spice.0

如果您碰巧使用 vagrant,您可能会发现我的插件很有用: https ://github.com/billyan2018/vagrant-qemu

于 2021-09-30T23:03:59.940 回答