Following topics are described in this how-to:
- How to start a Virtual Desktop Session using RealVNC Server on Raspian
- How to configure your Raspberry-PI in order to setup a Virtual Desktop Session on system boot
How to Start a Virtual Desktop Session using RealVNC Sever
Starting a Virtual Desktop Session is quite simple here’s an example:
vncserver -geometry 1920x1080 -randr=1920x1080,1600x1200,1280x1024,1024x768,800x600
The above starts a new Session in the VNC Server using the resolution specified with the parameter “-geometry”. The parameter “-randr” defines the available resolutions for the session.
Show available resolutions on client and switch resolutions
With xrandr you can display the available options on a session:
Let’s say we want to switch to 1280×1024 this would mean that we have to type:
xrandr -s 2
Note: This only works when you execute xrandr in a session with an active GUI. Executing “xrandr -s” i.e. via Putty console will run into an error as there’s no resolution to change in the terminal session.
Configuring Raspian to start RealVNC Desktop on System Boot
1. Create a systemd startup script:
sudo nano /etc/systemd/system/vncvirtualdesktop.service
Note: The above creates an empty script file in the folder /etc/systemd/system
2. Enter the following code into the newly created script:
[Unit] Description=Start VNC Server Virtual Desktop [Service] Type=oneshot ExecStart=/bin/su pi -c '/usr/bin/vncserver -geometry 1920x1080 -randr=1920x1080,1600x1200' ExecStop=/usr/bin/vncserver -kill :1 RemainAfterExit=yes [Install] WantedBy=multi-user.target
The value behind “-geometry” defines the standard resolution. You can change it per your needs.
The value behind “-randr” defines the available resolutions on the Virtual Desktop session. You can extend the list per your needs”
3. Enable the newly created service using:
systemctl enable vncvirtualdesktop.service
4. Connect to the Raspberry Pi over the networking using a :1 after the IP address or hostname:
Note: This is an example if you want to connect on your Virtual Desktop “1” on the VNC-Server at IP 192.168.0.100