Running Mir servers over VNC

Remote desktop support

There’s a long standing request on the Mir github asking for “remote desktop support”. One possible solution is X-forwarding over ssh:

ssh -XC <login@remote> sh -lc 'egmde --shell-enable-autostart'

But there are performance (and other) issues with X forwarding.

VNC

One of the protocols mentioned in the request is VNC which has some potential for better performance. While using Xfvb for some testing, I realized that there was also a possibility of using this with x11vnc to set up a VNC server.

I’m going to describe how to do this while tunneling the VNC connection over ssh. There are obviously other options for those familiar with the technology.

The server

There are some pre-requisites: the server needs an ssh server, egmde, Xvfb, x11vnc, and inotifywait installed, but with these in place this script will start up a VNC server running a Mir desktop:

#!/bin/bash

DISPLAY_NO=66
DISPLAY=:${DISPLAY_NO}
x11_auth_file=$(mktemp --tmpdir="${XDG_RUNTIME_DIR}")

# If there's already a compositor for WAYLAND_DISPLAY choose another
if [ -O "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]; then
  port=0
  while [ -e "${XDG_RUNTIME_DIR}/wayland-${port}" ]; do
    let port+=1
  done
  WAYLAND_DISPLAY=wayland-${port}
fi

xvfb-run --auth-file=${x11_auth_file} --server-num=${DISPLAY_NO} egmde&
xvfb_pid=$!

trap "kill $xvfb_pid" INT TERM

until [ -O "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]
do
  inotifywait -qq --timeout 5 --event create $(dirname "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}")
done

env -u WAYLAND_DISPLAY x11vnc -display ${DISPLAY} -bg -nopw -listen localhost -xkb -auth ${x11_auth_file} -ncache 10

wait

Towards the end of the output, this will display:

The VNC desktop is:      localhost:0
PORT=5900

These numbers are needed when setting up the client.

The client

The client system needs ssh and gvncviewer installed.

To tunnel the VNC connection over SSH we use the following incantation:

ssh -N -T -L 5900:localhost:5900 <hostname>

Use the number from above and the name of the actual host computer.

And to connect:

gvncviewer localhost:0

This will bring up a VNC viewer with the egmde desktop running on the host system.