Update 2021 (November)
@MarkusLange, has updated his script (check the 2019 update bellow for the link and instructions) to take care of the KMS/fKMS problem with the Pi4 if you are using Kodi version >=19.1, as seen here: [HowTo] Install a vnc server on the Raspberry pi - #482 by MarkusLange
So just use his script to install vnc server on your pi…It is safer than doing it manually.
Update 2021 (September)
In order to make it work on the Pi4, after installation do the following:
Update 2019
@MarkusLange has created an easy installer to setup a vnc server on a raspberry pi.
You can use his guide here: [HowTo] Install a vnc server on the Raspberry pi - #394 by MarkusLange to install it using an installer. It’s pretty simple just follow the instructions and select “Install VNC Server and Service” or use the console command to also setup a port, framerate and password in one line like so:
sudo ./osmc_vnc_install_cli.bash --install-vnc 1234 30 osmc
Instructions for manual Installation
Step 1: Based on @patrikolausson 's instructions on github GitHub - patrikolausson/dispmanx_vnc: VNC Server for Raspberry PI using dispmanx you have to install all the necessary packages first in order to compile the vnc server.
sudo apt-get install build-essential rbp-userland-dev-osmc libvncserver-dev libconfig++-dev unzip
cd /home/osmc
sudo wget https://github.com/patrikolausson/dispmanx_vnc/archive/master.zip
unzip master.zip -d /home/osmc/
rm master.zip
cd dispmanx_vnc-master
make
Step 2: To add the vnc server as a service, (so it loads automatically when the pi reboots), do the following:
First of all lets create a basic config file (password, fps etc) and copy the server to the /bin folder for easy execution.
We’ll go inside the dispmanx_vncserver folder we just compiled using patrik’s method, and do
sudo cp dispmanx_vncserver /usr/bin
sudo chmod +x /usr/bin/dispmanx_vncserver
sudo cp dispmanx_vncserver.conf.sample /etc/dispmanx_vncserver.conf
sudo vi /etc/dispmanx_vncserver.conf
(You can use nano if you want instead of vi)…
Press i to activate write mode in vi and then copy paste this inside and change the password inside the quotes:
relative = false;
port = 0;
screen = 0;
unsafe = false;
fullscreen = false;
multi-threaded = false;
password = "mypassword";
frame-rate = 23;
downscale = false;
localhost = false;
vnc-params = "";
Press ESC, then type :wq to save the changes you made and quit vi.
Notes:
Some people might have a problem using port = 0; in the above config file.
If you also have problems connecting to your pi, then the only solution is to do port forwarding, so change that line to port = 5900;
Instructions on how to forward port 5900 to your pi can be found here: http://portforward.com/english/applications/port_forwarding/RealVNC/default.htm
If you enable port 5900 then make sure you have set a static ip on your pi’s network settings. Also please note that this will allow access to your pi from outside your LAN network…so don’t put 12345 or something easy for your vnc password…you might get hacked…
Also, notice the downscale and multi-threaded values ? These 2 values when set to true could help out to have a better feedback from the vncserver. The first one downscales the screen to a quarter in vnc and the other runs vnc in a separate thread. Try them out,
Now we’ll create the service file to be able to ‘autoload’ the server on boot:
sudo vi /etc/systemd/system/dispmanx_vncserver.service
then press i again to activate writing inside the editor, and paste this inside:
[Unit]
Description=VNC Server
After=network-online.target mediacenter.service
Requires=mediacenter.service
[Service]
Restart=on-failure
RestartSec=30
Nice=15
User=root
Group=root
Type=simple
ExecStartPre=/sbin/modprobe evdev
ExecStart=/usr/bin/dispmanx_vncserver
KillMode=process
[Install]
WantedBy=multi-user.target
Save and quit.
After that start the service and make it load or reboot
sudo systemctl start dispmanx_vncserver.service
sudo systemctl enable dispmanx_vncserver.service
sudo systemctl daemon-reload
That should do it You can now connect to your pi from your PC using your pi’s local ip address.
If you used port 5900 method, then also add :5900 at the end of the address.
For MacOS users:
-
If you want to use OSX tool “screen sharing”, start the vnc server with the password option:
Example
osmc@osmc:~/dispmanx_vnc$ ./dispmanx_vncserver --password=osmc
(Thanks to @chuenniger and @dosch for that) -
Instructions for installing a vnc server on a rpi3, can be found here: [HowTo] Install a vnc server on the Raspberry pi - #213 by paul34949 (thanks to @paul34949)
Final Note:
If you dont want the server to load on boot, you can make a shortcut on your remote control to start/stop the server. Further info here:
Additional note:
If for some reason you need to remove the service do this:
sudo systemctl stop dispmanx_vncserver.service
sudo systemctl disable dispmanx_vncserver.service
sudo systemctl daemon-reload
End of Guide
=========================================================================================
(This method was left here in case someone wants to do this the ‘hard way’ and not use patrik’s github method)
Old instructions on how to setup a vnc server…Deprecated method…(dont use it)
I’ve managed to run vncserver from here: GitHub - hanzelpeter/dispmanx_vnc: VNC Server for Raspberry PI using dispmanx
And this is how:
Install dependencies
sudo apt-get update
sudo apt-get install libvncserver-dev
sudo apt-get install rbp-userland-dev-osmc
sudo apt-get install gcc
Get the files needed and compile the server
Type in console:
wget https://github.com/hanzelpeter/dispmanx_vnc/archive/master.zip
unzip master.zip -d /home/osmc/
rm master.zip
–Optional–
If you want to make the vnc server a bit faster, then edit main.c inside the dispmanx_vnc-master folder and search for:
#define PICTURE_TIMEOUT (1.0/15.0)
change it to:
#define PICTURE_TIMEOUT (1.0/25.0)
-----------
Compile the file
cd /home/osmc/dispmanx_vnc-master/
sudo chmod +x makeit
./makeit
Start the server
sudo modprobe uinput
sudo chmod 666 /dev/uinput
./dispman_vncserver
(Ctrl + C to stop it)
Log in from your PC with vnc viewer
END
If you want to make the file executable from anywhere then:
sudo cp dispman_vncserver /usr/bin
chmod +x /usr/bin/dispman_vncserver