wiki/gofurther/display.md

179 lines
4.3 KiB
Markdown
Raw Normal View History

2022-07-31 09:22:08 +00:00
---
title: Display
description: How to access a virtual machine's display
published: true
2023-10-15 15:11:02 +00:00
date: 2023-10-15T15:11:00.161Z
2022-07-31 09:22:08 +00:00
tags:
editor: markdown
dateCreated: 2022-07-31T09:22:05.854Z
---
# Display
2023-05-20 20:48:36 +00:00
A virtual display can be attached to a virtual machine. It is a must-have for non-headless scenarios.
2022-07-31 09:22:08 +00:00
2023-05-20 20:52:14 +00:00
## Display types
2022-07-31 09:22:08 +00:00
### SDL display
2022-07-31 09:22:08 +00:00
The [Simple DirectMedia Layer](https://www.libsdl.org/) (SDL)-powered display is a local-only low-latency display.
2022-07-31 09:22:08 +00:00
> The SDL display is only avalable with virtual machines created using the QEMU/KVM **User Session**
{.is-info}
2022-07-31 09:22:08 +00:00
> Mouse grab does not currently work with the SDL display
{.is-warning}
2022-08-12 23:55:28 +00:00
> The display resolution of your guest display should not exceed that of your physical screen
2023-05-20 21:25:13 +00:00
{.is-info}
#### SELinux-related configuration
2022-08-12 23:47:43 +00:00
2022-08-12 23:55:28 +00:00
By default, SELinux will block access to X Windows Server for the virtualization stack. An exception has to be set.
2022-08-12 23:47:43 +00:00
* Set new rule
```
sudo setsebool -P virt_use_xserver 1
```
* Do some magic trick
```
sudo ausearch -c 'qemu-system-x86' --raw | audit2allow -M my-qemusystemx86
k
```
* And another one
```
sudo semodule -X 300 -i my-qemusystemx86.pp
```
#### SDL XML configuration
2022-08-12 23:47:43 +00:00
* The default display can be identified using `echo $DISPLAY`.
2023-05-20 20:59:56 +00:00
```
$ echo $DISPLAY
:0
```
The same applies to `xauth`. On Wayland, it would look like that.
2023-05-20 20:59:56 +00:00
```
$ echo $XAUTHORITY
/run/user/1000/.mutter-Xwaylandauth.ARIY51
```
* Example of an XML SDL configuration, with OpenGL enabled. This example requires a 3D-capable graphic card to be attached to the guest computer, such as `virtio-gpu`.
2022-07-31 09:22:08 +00:00
```
<graphics type="sdl" display=":0" xauth="/run/user/1000/.mutter-Xwaylandauth.ARIY51" fullscreen="yes">
2022-07-31 09:22:08 +00:00
<gl enable="yes"/>
</graphics>
```
2022-08-12 23:55:28 +00:00
> The fullscreen attribute is not honored at the moment
{.is-warning}
2022-08-12 23:55:28 +00:00
2023-05-20 20:59:56 +00:00
### D-Bus display
2022-08-24 23:13:52 +00:00
2023-05-20 20:59:56 +00:00
[D-Bus](https://www.freedesktop.org/wiki/Software/dbus/) is a desktop-oriented middleware that can be used to create a display for a virtual machine.
2022-08-24 23:13:52 +00:00
2023-10-15 14:58:56 +00:00
#### Libvirt
* Add a D-Bus video backend and add enable for OpenGL:
2022-08-24 23:18:25 +00:00
2022-08-24 23:13:52 +00:00
```
2023-05-20 20:45:39 +00:00
<graphics type="dbus">
<gl enable="yes"/>
2022-08-24 23:13:52 +00:00
</graphics>
```
2022-08-24 23:18:25 +00:00
2023-10-15 14:58:56 +00:00
> This equates to `-display dbus,gl=on` in QEMU
>
{.is-info}
When the virtual machine is launched, a specific D-Bus address will be choosen, as well as a rendering device:
2022-08-24 23:36:37 +00:00
```
<graphics type="dbus" address="unix:path=/run/user/1000/libvirt/qemu/run/dbus/8-user-d-bus-dbus.sock">
<gl enable="yes" rendernode="/dev/dri/renderD128"/>
</graphics>
```
2023-10-15 14:58:56 +00:00
* Add a D-Bus audio backend:
2022-08-24 23:13:52 +00:00
2022-08-24 23:19:48 +00:00
```
<graphics type="dbus">
<audio id="1">
2022-08-24 23:13:52 +00:00
</graphics>
2023-10-15 14:58:56 +00:00
```
#### Connect to the D-Bus display
A third-party tool is required to interact to the D-Bus display.
[Libmks](https://gitlab.gnome.org/GNOME/libmks), which is under development, is such a tool.
> Due to [a bug](https://gitlab.gnome.org/GNOME/libmks/-/issues/16), it is currenlty only possible to connect a D-Bus display with plain QEMU
{.is-warning}
Libmks has to be built from source.
- Clone the repository
2022-08-24 23:19:48 +00:00
```
2023-10-15 14:58:56 +00:00
git clone https://gitlab.gnome.org/GNOME/libmks
```
- Change directory
```
cd libmks
```
- Build it
```
meson setup build
cd build
ninja
```
- Launch a diskless virtual machine
```
qemu-system-x86_64 \
-enable-kvm \
-machine q35 \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
-cpu host \
-device virtio-vga-gl \
-m 4G \
-smp 2,sockets=1,dies=1,cores=2,threads=1 \
-display dbus,gl=on \
-device virtio-tablet-pci \
-device virtio-keyboard-pci \
```
- From another terminal tab or window, launch the previously built MKS using the following command
```
./build/tools/mks
```
2022-07-31 09:22:08 +00:00
2023-10-15 15:02:12 +00:00
As there is no Live ISO or disk attached to the virtual machine, you will eventually land in the UEFI shell.
2023-05-20 20:59:56 +00:00
## Resources
2022-07-31 09:22:08 +00:00
2023-05-20 20:59:56 +00:00
* [Detailed presentation](https://bootlin.com/pub/conferences/2016/meetup/dbus/josserand-dbus-meetup.pdf) on D-Bus
* [Official resource](https://libvirt.org/formatdomain.html#graphical-framebuffers) for libvirt-compatible displays, including various XML examples
2023-05-20 21:19:38 +00:00
* [Libmks](https://gitlab.gnome.org/chergert/libmks) provides a "Mouse, Keyboard, and Screen" to QEMU using the D-Bus device support in QEMU and GTK 4.
* [QEMU D-Bus display experiment](https://gitlab.com/marcandre.lureau/qemu-display/) is a WIP Rust crates to interact with a -display dbus QEMU
* [SDL graphics](https://fedoraproject.org/wiki/How_to_debug_Virtualization_problems#SDL_Graphics)
---
*[**Go to parent page**](https://wiki.phyllo.me/)*