How to enable two displays in Ubuntu VM?



I’m trying to create a VM running Ubuntu 22.04 that would use two virtual displays. I’ve tried adding -device qxl to raw.qemu but that results only in lspci outputing:

00:03.0 Display controller: Red Hat, Inc. QXL paravirtual graphic card (rev 05)
04:00.0 VGA compatible controller: Red Hat, Inc. Virtio GPU (rev 01)

When clicking View->Displays->Display 2 in Spice, a window saying “Waiting for display 2” appears. I’ve tried appending max_outputs=2 to the initial raw.qemu, but that didn’t help.
xrandr output in all cases contains only one virtual display. I do not need qxl specifically, but I didn’t know how to increase the heads integer for the default virtio VGA.

Any help or hint would be greatly appreciated!

I came across the same problem and found, that lxd is not using the spice QXL spice video adaptor. I found in my Windows 10 VM the virtio VGA adapter used as graphics card stub.

So, if you are trying to increase the count of graphics cards, you shoud add another

raw.qemu : -device virtio-vga

to your VM config section, to provide you a second display in windows. Not sure if this works for linux based systems, as at least spice states here under dual display, that linux would require rather a dual headed config.

I’m not into this, but maybe for linux dual screen VM setup you have to alter the qemu config, your VM is using. The running config could be seen while VM is running in on the host

/var/log/lxd/<your vm>/qemu.conf

As the post here states, adapting the lxd/incus qemu config is a bit opinionated. But meanwhile there are ways to update or change your qemu config if really required:
look here

Here is a small update for people, that want to have multiple displays on their linux guest vms.
This works well with the virtio-vga driver. While for Windows guests, you need to add a second
adapter to the config raw.qemu key as described in the previous post, linux does not work with
two adapters. Here the solution is, to increase the heads count of your VM adapter by adding
this update to the raw.qemu.conf config key:

   raw.qemu.conf: |-
       [device "qemu_gpu"]
       max_outputs = "3"

This will extend the qemu config section for your lxd “qemu_gpu” device with the key max_outputs and will allow for three monitors int this case. Default is 1.
You could verify this update happen, while your vm is running in your /var/log/lxd//qemu.conf.

Note, the monitors need to be activated in the lxd client virt-viewer frontend panel and this was first possible for me, when the VM had started up the desktop completely.

Finally also managed to replace the virtio-vga adpater to a qlx-vga adapter for my vms with lxd.
It seems faster over slower bandwidth networks. But for my linux vm s the multi head setup seems not to work stable. It is to say, that spice is a bit older and more complex, may be not so save, as the virtio adapter. But it has some nice features.

If you want to test it in your linux / windows vm, add this config update to your vm:

  raw.qemu.conf: |-
    [device "qemu_gpu"]
    driver = "qxl-vga"
    id = "video0"
    max_outputs = "3"
    ram_size = "67108864"
    vram_size = "67108864"
    vram64_size_mb = "0"
    vgamem_mb = "16"
    bus = "pcie.0"
    addr = "4.0"

Please note : I could not reuse any of the pcie devices, that lxd defined already in my qemu.conf. First I tried to reuse the “qemu_pcie3” bus, that lxd defined earlier for my virtio-vga

[device "qemu_pcie3"]
driver = "pcie-root-port"
bus = "pcie.0"
addr = "1.3"
chassis = "3"

but without an error, the vga console did not startup the bios/uefi to boot the VM.
So I defined a new, yet free pci root port 4.0. You have to check, where the next free slot is, maybe 3.0 works or 5.0, depending on your config amd qemu.raw additional devices, like sound cards, etc.

I found, that the qxl adapter works not that well with multihead setup in the linux guest, at least for me.
In debian I have to install the xserver-xspice and spice-vdagent. The additional displays were first
available, when my kde environment was fully loaded.