ppggff / vagrant-qemu

Use Vagrant to manage machines using QEMU. Test with Apple Silicon / M1 and CentOS aarch64 image
MIT License
408 stars 32 forks source link

How to show the VM display/GUI? #48

Closed rgl closed 11 months ago

rgl commented 11 months ago

How can we show the default qemu VM display/GUI?

On a Intel macOS Monterey, with Homebrew installed qemu and vagrant, trying the qe.extra_qemu_args = %w(-vga virtio -display cocoa,show-cursor=on) vagrant configuration as in (the full configuration is at https://github.com/rgl/debian-vagrant/tree/wip-macos-qemu/debian.json):

  config.vm.provider 'qemu' do |qe, config|
    qe.qemu_dir = '/usr/local/bin'
    qe.arch = 'x86_64'
    qe.machine = 'q35,accel=hvf'
    qe.cpu = 'host'
    qe.smp = 'cpus=2,sockets=1,cores=2,threads=1'
    qe.memory = 2048
    qe.net_device = 'virtio-net-pci'
    qe.extra_qemu_args = %w(-vga virtio -display cocoa,show-cursor=on)
    config.ssh.username = 'vagrant'
    config.ssh.password = 'vagrant'
    config.vm.synced_folder '.', '/vagrant',
      type: 'smb',
      smb_username: ENV['VAGRANT_SMB_USERNAME'] || ENV['USER'],
      smb_password: ENV['VAGRANT_SMB_PASSWORD']
  end

Fails with:

==> default: Starting the instance...
A command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.

Command: ["qemu-system-x86_64", "-machine", "q35,accel=hvf", "-cpu", "host", "-smp", "cpus=2,sockets=1,cores=2,threads=1", "-m", "2048", "-device", "virtio-net-pci,netdev=net0", "-netdev", "user,id=net0,hostfwd=tcp::50022-:22", "-drive", "if=virtio,format=qcow2,file=/Users/*****/Projects/debian-vagrant/example/.vagrant/machines/default/qemu/81wnFeFrCvk/linked-box.img", "-chardev", "socket,id=mon0,path=/Users/*****/.vagrant.d/tmp/vagrant-qemu/81wnFeFrCvk/qemu_socket,server=on,wait=off", "-mon", "chardev=mon0,mode=readline", "-chardev", "socket,id=ser0,path=/Users/*****/.vagrant.d/tmp/vagrant-qemu/81wnFeFrCvk/qemu_socket_serial,server=on,wait=off", "-serial", "chardev:ser0", "-pidfile", "/Users/*****/Projects/debian-vagrant/example/.vagrant/machines/default/qemu/81wnFeFrCvk/qemu.pid", "-parallel", "null", "-monitor", "none", "-display", "none", "-vga", "none", "-daemonize", "-vga", "virtio", "-display", "cocoa,show-cursor=on", {:notify=>[:stdout, :stderr, :stdin]}]

Stderr: objc[2530]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called.
objc[2530]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

Stdout:

Please note that the equivalent in a packer template works as expected:

{
  "builders": [
    {
      "name": "debian-{{user `version`}}-amd64-libvirt",
      "type": "qemu",
      "accelerator": "hvf",
      "machine_type": "q35",
      "cpus": 2,
      "memory": 2048,
      "qemuargs": [
        ["-cpu", "host"],
        ["-display", "cocoa,show-cursor=on"],
        ["-vga", "virtio"]
      ],
      "headless": false,
      "use_default_display": true,
      ...
    }
  ]
  ...
}
ppggff commented 11 months ago

Try to set "no_daemonize" to true?

rgl commented 11 months ago

That did the trick! Thank You!