Jump to content

VNC

From postmarketOS Wiki

This guide explains how to setup a VNC server on your phone.

x11vnc

Using x11vnc, which is in the Alpine repos. You need a running X server (e.g. running Xfce), then you just run x11vnc on the device in a terminal/tty and connect to it. From there, you can manipulate the previously running X server. You might need to specify the X server if x11vnc does not detect it (e.g. by passing -display :0 to it or doing a export DISPLAY=:0 before running it, assuming the display is at :0)

If you want to launch x11vnc from ssh while you have already logged in from the display managers of your choice, you need to find the Xauthority file for the logged in user and use that in the command of x11vnc, for example, if your user id is 10000 and you're using gdm:

x11vnc -auth /run/user/10000/gdm/Xauthority  -display :0

Location of Xauthority file may differ with different display manager.

wayvnc

This works for wlroots-based Wayland compositors like Phosh or Sway[1]. By default wayvnc listens to 127.0.0.1:5900

Install wayvnc, and start a server listening to any network interface on the phone:

$ sudo apk add wayvnc
(1/3) Installing aml (0.2.1-r0)
(2/3) Installing neatvnc (0.4.0-r0)
(3/3) Installing wayvnc (0.4.1-r0)
Executing busybox-1.35.0-r13.trigger
OK: 971 MiB in 563 packages
$ wayvnc 0.0.0.0

Or listen to 172.16.42.1 on port 9999:

$ wayvnc 172.16.42.1 9999


After a server setup, use a client, for example, tigervnc-client to connect to the server 172.16.42.1:9999, and press Connect:

Have fun with it.

Troubleshooting

XDG_RUNTIME_DIR not set in the environment

This happens when XDG_RUNTIME_DIR is not set, usually in SSH sessions.

$ wayvnc 0.0.0.0
error: XDG_RUNTIME_DIR not set in the environment.
ERROR: Failed to initialise wayland

Just set it with:

$ export XDG_RUNTIME_DIR=/run/user/10000

And start the server again.

Connection refused/timed out

Check if your VNC server is started, and the port is open to the clients. By default, incoming packets from USB Networking are accepted by nftables on the phone [2].

But when connecting via Wi-Fi, you need to open the port. If using port 5900, it's as simple as installing postmarketos-config-nftables-vncserver and restarting nftables:

# apk add postmarketos-config-nftables-vncserver
(1/1) Installing postmarketos-config-nftables-vncserver (0.10-r0)
Executing postmarketos-base-20-r0.trigger
Configuring a getty on port ttyMSM0 with baud rate 115200
OK: 1006 MiB in 570 packages
# service nftables restart
 * Stopping firewall ...                                         [ ok ]
 * Loading nftables state and starting firewall ...

However, when connecting to a custom port like 9999, it requires to add a rule to accept the connection:

# nft add rule inet filter input iifname wlan0 tcp dport 9999 accept comment "Accept custom port over wifi"

No route to host

Check if the host even exists on the LAN.

Wireless Display Server with fbvnc

You can use fbvnc or any other VNC client to set up your device as second monitor. Benefit of fbvnc is it not need graphical environment and negociate with system framebuffer. By default it is /dev/fb0, and you can change it with FBDEV environment variable.

  1. Install Virtual-Display-Driver for Windows , set up resolution as native device's.
  2. Install VNC server like TightVNC to Windows.
    • In TightVNC Service Configuration, in Extra ports tab set Geometry to cast. (ex. 1024x600+-1024+0 - associate VNC screen cast area with area of secondary display on left of primary display).
    • Disable auth, fbvnc not support passwords.
  3. Run RNDIS USB connection with host, set PC ip address ex. 172.16.42.2, or prefer Wi-Fi.
  4. Disable fb blank on device console
    • TERM=linux setterm --blank 0 --msg on >/dev/tty1 </dev/tty1
  5. Switch to virtual console with CtrlAltF2 and run session:
    • fbvnc -e 16 172.16.42.2 5901

Related pages

DIAL

See also

References