MacOS M1/M2 上的 QEMU 和 LIBVIRT

问题描述 投票:0回答:1

我正在尝试让 VirtManager/virsh 查看 Vagrant 创建的虚拟机,但到目前为止还没有任何乐趣......

我已经通过brew安装了qemu和libvirt。

这是 Vagrant 文件:

Vagrant.configure("2") do |config|
  # Define the VM box and provider
  config.vm.box = "perk/ubuntu-2204-arm64"

  config.vm.define "ubuntu-arm64" do |node|
    config.vm.provider :qemu do |qemu|
      qemu.cpus = 4
      qemu.memory = 4096
    end
    node.vm.network :private_network, type: "dhcp"
    node.vm.network :forwarded_port, guest: 22, host: 2223, id: "ssh"
  end
end

运行 vagrant up 后,我可以看到 qemu 实例正在运行并且虚拟机可用:

$ ps -ef | awk '/qemu/ && !/awk/' | sed -e 's/[^/]*//' -e 's/ -/\n\t-/g'

/opt/homebrew/bin/qemu-system-aarch64
        -machine virt,accel=hvf,highmem=on
        -cpu host
        -smp 2
        -m 4096
        -device virtio-net-device,netdev=net0
        -netdev user,id=net0,hostfwd=tcp::50022-:22
        -drive if=virtio,format=qcow2,file=/.vagrant/machines/ubuntu-arm64/qemu/pBvXRX29gW8/linked-box.img
        -drive if=pflash,format=raw,file=/.vagrant/machines/ubuntu-arm64/qemu/pBvXRX29gW8/edk2-aarch64-code.fd,readonly=on
        -drive if=pflash,format=raw,file=/.vagrant/machines/ubuntu-arm64/qemu/pBvXRX29gW8/edk2-arm-vars.fd
        -chardev socket,id=mon0,path=/.vagrant.d/tmp/vagrant-qemu/pBvXRX29gW8/qemu_socket,server=on,wait=off
        -mon chardev=mon0,mode=readline
        -chardev socket,id=ser0,path=/.vagrant.d/tmp/vagrant-qemu/pBvXRX29gW8/qemu_socket_serial,server=on,wait=off
        -serial chardev:ser0
        -pidfile /.vagrant/machines/ubuntu-arm64/qemu/pBvXRX29gW8/qemu.pid
        -parallel null
        -monitor none
        -display none
        -vga none
        -daemonize
/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python /opt/homebrew/bin/virt-manager
        -c qemu:///session
        --no-fork

然后我运行 virsh list 但我仍然看不到任何虚拟机(当我 sudo virsh list 时也会发生同样的情况)。

我发现一个参考建议我需要指定连接套接字,所以我这样做了,这就是结果:

sudo virsh -c "qemu:///session" list
error: failed to connect to the hypervisor
error: Failed to connect socket to '/opt/homebrew/var/run/libvirt/virtqemud-sock': No such file or directory

所以我做了更多研究,发现我需要在查询字符串上指定 libvirt-sock:

sudo virsh -c "qemu:///session?socket=/Users/stefletcher/.cache/libvirt/libvirt-sock" list                      
 Id   Name   State
--------------------

它尝试列出但看不到 qemu VM。

我感觉我错过了一些基本的东西,但无法指出它。

apple-m1 qemu vagrantfile libvirt vagrant-libvirt
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.