How to run lightdm on Xvfb on a Raspberry Pi

raspberry pixvfb

I've got a Raspberry Pi and I'm using it as a headless server. But I want to run X on it. It comes with lightdm, and if you run it using the included HDMI or video out it works, and I can use that and x11vnc to that, but without a monitor attached, it defaults to 800×600 or something really small. I've tries setting the geometry, no effect.

So I thought I'd run Xvfb, then run lightdm on that, then x11vnc the whole shebang.

The problem is lightdm doesn't seem to want to connect to an already running X server, it wants to make its own. Fine, so I tell it to run Xvfb instead of X, and it fails because lightdm tries to pass 'vt7' as a param to the X server, but Xvfb doesn't accept the virtual terminal as a param because it's not using any terminal, it's a virtual frame buffer.

So help me out? How can I either get lightdm (I've checked the docs and options, nothing obvious) to start Xvfb correctly (without vt7 param), or get it to attach to an existing X server that's already running and not try and run its own.

Best Answer

Incidentally, I was facing the same problem at the same time. Also wanted to run a headless server with Xvfb and VNC, not on RPi though. I found a working solution doing the following steps...

apt-get install lubuntu-core xvfb x11vnc

I figured out that all configuration options of lightdm.conf are documented in /usr/share/doc/lightdm/lightdm.conf.gz. So have a look at them by issuing the following command.

zcat /usr/share/doc/lightdm/lightdm.conf.gz

Obviously, as you reported, lightdm tries to instantiate its own X server and passes some arguments that Xvfb can't handle. First step to work around this is adding a line 'xserver-command' to lightdm's configuration file /etc/lightdm/lightdm.conf (it defaults to xserver-command=X).

[SeatDefaults]
greeter-session=lightdm-gtk-greeter
user-session=Lubuntu
xserver-command=/etc/X11/xinit/xserverrc

After that, I modified /etc/X11/xinit/xserverrc so as to start Xvfb instead of a real X server (note that I commented out the original X exec line that passes the command line arguments on to X). Adding an exec line instead that runs Xvfb was enough to get lightdm working with Xvfb.

#!/bin/sh

#exec /usr/bin/X -nolisten tcp "$@"
exec Xvfb :0 -screen 0 1024x768x24

This seems to me like a convenient method of wrapping the lightdm X command in a suitable wrapper script that is already present on the (L)Ubuntu default installation.

Finally, I use VNC after ssh'ing into the system, forwarding the VNC port and connecting to the forwarded port on localhost with a VNC client (in my case Mac OS screen sharing).

ssh -L 5900:localhost:5900 user@machine 'x11vnc -localhost -display :0 -many'
Related Question