Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xquangdang/b0537e5774c59ad319b90c00a869900c to your computer and use it in GitHub Desktop.
Save xquangdang/b0537e5774c59ad319b90c00a869900c to your computer and use it in GitHub Desktop.
Looking-glass kvmfr setup Arch

Looking-glass kvmfr setup Arch

More in-depth setup-guide for usage of kvmfr (see https://looking-glass.io/docs/B6/module/)

This setup was done on EndeavourOs (Arch) on Kernel 6.1.12-arch1-1.
QEMU-version 7.2 and libvirt version 9.0.0 .
Running cGroups Policy (if you have AppArmor, some things are different)

Check respective sections in looking-glass docs for other versions (specifcally QEMU <6.2 and libvirt <7.9)


1. Prerequisites

1.1. VM

You need a VM which is fully set-up with graphics-driver and the looking-glass host-program.

Documentation about that can be found here: https://looking-glass.io/docs/B6/install/


1.2. Packages

You need the following packages

  • sudo (or do things as root)
  • git
  • dkms
  • linux-headers (same version as kernel, probably already installed)

1.3. MEM-size

This guide uses the default 32MB size, which is fine for 1080p.

For 1440p or 2160p you need to use 64MB.

See this section to determine how much you need.


Formula

pixel size for SDR is 4
pixel size for HDR is 8

width x height x pixel size x 2 = frame bytes
frame bytes / 1024 / 1024 = frame megabytes
frame megabytes + 10 MiB = total megabytes

Round up to nearest power of 2. (32, 64, 128, ..)

2. Setup

2.1. kvmfr

Clone repository and enter module folder

git clone https://github.com/gnif/LookingGlass
cd LookingGlass/module

Compile and install module with dmks

sudo dkms install "."

Setup udev-rule for module to set permissions
Deviate from docs to make user-independent

sudo cat > /etc/udev/rules.d/99-kvmfr.rules <<EOF
SUBSYSTEM=="kvmfr", OWNER="libvirt-qemu", GROUP="kvm", MODE="0666"
EOF

Setup auto-load of module

sudo cat > /etc/modules-load.d/kvmfr.conf <<EOF
# 3. KVMFR Looking Glass module
kvmfr
EOF

sudo cat > /etc/modprobe.d/kvmfr.conf <<EOF
#KVMFR Looking Glass module
options kvmfr static_size_mb=32
EOF

3.1. libvirt-qemu

3.1.1. Setup cgroups-policy to allow qemu access to device

  1. Open /etc/libvirt/qemu.conf
  2. Find cgroup_device_acl
  3. Uncomment everything in that block and add "/dev/kvmfr0"

Looks something like this:

# 4. This is the basic set of devices allowed / required by
# 5. all virtual machines.
#
# 6. As well as this, any configured block backed disks,
# 7. all sound device, and all PTY devices are allowed.
#                                                                                                          
# 1. This will only need setting if newer QEMU suddenly
# 2. wants some device we don't already know about.
#
cgroup_device_acl = [
    "/dev/null", "/dev/full", "/dev/zero",
    "/dev/random", "/dev/urandom",
    "/dev/ptmx", "/dev/kvm",
    "/dev/kvmfr0"
]
  1. Save file and restart libvirtd
    sudo systemctl restart libvirtd

2.0.1. Setup VM to use MEM-device

  1. Open virtual machine manager

  2. Your VM -> Details -> XML

  3. First line has to be

<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
  1. Go to the bottom and add this block
<qemu:commandline>
  <qemu:arg value='-device'/>
  <qemu:arg value='{"driver":"ivshmem-plain","id":"shmem0","memdev":"looking-glass"}'/>
  <qemu:arg value='-object'/>
  <qemu:arg value='{"qom-type":"memory-backend-file","id":"looking-glass","mem-path":"/dev/kvmfr0","size":33554432,"share":true}'/>
</qemu:commandline>

size is your MEM-size in bytes (looking-glass docs)
Formula: MEM-size x 1024 x 1024


  1. Save and check if everything is still there
    libvirt might replace " with &quot;, thats fine

2.1. Looking-Glass Client

You might not have to specify the mem-device as it already detects the correct one

Feels free to add a config-file or manually add the -f Option if not


3. Testing

  1. Load module manually
sudo modprobe kvmfr static_size_mb=32
  1. Check kernel-log for output of module
sudo dmesg | grep kvmfr

Should return this:

kvmfr: creating 1 static devices


  1. Check created node and permissions
ls -la /dev/kvmfr*

Should return this:

crw-rw-rw- 1 libvirt-qemu kvm 510, 0 23. Feb 10:00 /dev/kvmfr0


  1. Now try to start the VM and then looking-glass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment