Accelerated Dual Screen VM on Linux

It's pandemic season, and for all that it entails, it also means getting non-work computers to perform work-related tasks for longer periods than just through a browser.

In this case, I was asked for help to get a Debian 10 VM (Virtual Machine) to be Dual Screen or "Multi Head", "Multiple Monitor Support" for alternative terms.

The VM had been created in GNOME Boxes which is a rather smooth way to create and run virtual machines and remote connections, while hiding some of the insanity-inducing complexity of the Libvirt details. Libvirt in turn builds on the hardware acceleration capabilities of virtio, virgl and spice.

Sadly, to get dual screen Virtual Machines with Wayland and 3D-acceleration, we need to start digging into the gritty details below the smooth interface of Boxes. But fortunately, the worst thing you will have to do in this guide is click in a GUI.

At the end of this guide, we shall have re-configured a VM (Fedora 31, Debian 10, maybe others) to run with virgl based hardware acceleration with two virtual displays.

Setup and details

Host: Fedora 31 "Workstation", Linux 5.5.10, x86_64, Gnome/Wayland
Guest: Fedora 31 Workstation, x86_64, Gnome/Wayland
Guest: Debian 10 Desktop, amd64, Gnome/Wayland

On the host, we need to install some more software past the usual desktop fare, we need virt-manager and virt-viewer. On Fedora 31, we already have the underlying dependencies of spice, virgl and more prepared, so all that's needed is to install the packages:

sudo dnf install --refresh virt-manager virt-viewer

Configuring virt-manager

When you launch virt-manager, you may need to go to "File" and "Add Connection" and pick "QEMU/KVM user session" in order to see your existing VM's. You probably want to make it autoconnect so they show up by default.

If it lists your guest VM, that should be all right and you should be set to go.

Getting ready

  1. Start by shutting down the Guest VMs neatly.

I always suggest starting with a clean and freshly installed VM, especially since if you do mess up an existing and important VM, it would be rather sad. Do note that all the VM's I have tried this with were initially set up in Boxes, and that Boxes and virt-manager have different defaults when creating VM's.

Also note that this guide probably won't work on a Windows guest or with an older host OS.

Prepping the VM display for acceleration

  1. Open up virt-manager
  2. Double click your VM to open it
  3. "View => Details" and you should see a list of hardware on the left

Details screenshot

  1. Select "Display Spice"
  2. Set Listen Type to None
  3. Toggle OpenGL to enabled
  4. Press "Apply" to save settings

Display Spice screenshot

  1. Still inside virt-manager
  2. Select any "Video" device, eg. "Video VGA" or "Video QXL" or "Video Virtio"
  3. Remove all "Video" type devices.
  4. Below the list, press "Add Hardware"
  5. Add a new Video device of type Virtio
  6. Enable 3D acceleration
  7. Save settings

Video Virtio screenshot

I have received a report that some could not delete the last video device before adding a new one. If this also happens to you, add the new one before deleting the old one.

These same settings can be had by opening the "Properties" of the VM in Boxes, and toggling the slider 3D Acceleration However, that is only present on some kinds of VM's, and not for my Debian VM.

Note: After performing these changes, Boxes might have a hard time accessing the VM, while virt-manager shows it nicely. I did not bother debugging that further.

Boot your virtual machine

At this point, we want to test that things work. Press the Play button in virt-manager to launch it, and see that it boots.

Once the VM has started and before you log in, you should click the "Cogwheel" button beneath the login field and select GNOME. Do not select "System X11 Default", or "Gnome on Xorg" or similar.

When you have logged in, open the Gnome Settings app, and in the "Details" tab pick "About", and check that the "Graphics" section says virgl.

About screenshot

If you only wanted hardware acceleration, congratulations, you're done.

Test virt-viewer

Since neither Boxes or virt-manager supports dual screen configurations, we now need to try virt-viewer to attach to the VM. This is different than connect, and you need to do it in a terminal, as your normal user:

virt-viewer -a

Then pick your VM from the list, and press "Connect".

It may take a bit (15-30 seconds) and the screen may be black or a bit garbled.

If that happens, slightly resize the virtual window, give it focus, and press the super key (windows key) a few times to make something happen on the desktop.

Once you have that working, shut down your VM nicely.

Configuring dual screen

Open virt-manager again, and make sure your VM is shut off neatly. Then go to "Edit=>Preferences" for the whole virt-manager, and under the "General" tab, pick "Enable XML Editing" and then close the preferences again.

  1. In virt-manager
  2. Select your VM and Open the Details view
  3. Go down to your Video Virtio device
  4. Pick the "XML" tab
  5. Change the text that reads heads="1" to read heads="2"
  6. Make sure you do no other changes, and save.

Boot again

Once again, start your VM, then use virt-viewer -a to connect to it. Wait until it's started and log in normally.

In virt-viewer in the "View" menu, in the submenu "Displays", click to enable the checkbox for "Display 2". That should make the guest VM see a new display attached, and after a few seconds, it will configure and show things on it.

At this point, a Fedora 31 Guest behaves a lot smoother than a Debian 10 Guest. Where Fedora 31 has almost no graphical glitches and seems to work smoothly the whole way, Debian 10 takes some time, and sometimes corrupts the graphics on one or two of the displays. If they go dark, or corrupt, resize the window slightly, and press the "super" key when one of them is focused. This should make the UI inside the guest VM redraw, and will get graphics to show.

In the case of Debian 10, these are my special care instructions:

  1. Watch windows go black, garbled, and/or have some error message
  2. Wait approx 30s
  3. Resize both windows slightly
  4. Give each window focus and tap escape (to maybe turn off screen-saver)
  5. Give each window focus and tap the super key a few times (to make the menu animate)
  6. Watch displays turn on and resize themselves.

Success!

Dual Screen GLXGears

Host software versions:

Host, Fedora 31, Gnome / Wayland

  • qemu-system-x86-core-4.1.1-1.fc31
  • qemu-kvm-4.1.1-1.fc31
  • virglrenderer-0.7.0-4.20190424gitd1758cc09.fc31
  • spice-server-0.14.3-1.fc31
  • spice-gtk3-0.38-1.fc31
  • virt-viewer-8.0-3.fc31
  • gnome-boxes-3.34.4-1.fc31
  • virt-manager-2.2.1-2.fc31
  • mesa-libglapi-19.2.8-1.fc31

Happy hacking!

Release v3.30

Release v3.29

Release v3.28