You can use the raspbian preferences via the GUI to cause the pi user to be auto logged in at boot up and the GUI automatically run. However if you need to run with root privileges due to needing IO pin control (yes yes its not advised to run as root, but for many uses its fine where the security issues aren’t a concern) then set the raspbian preferences to boot to the command line. Now open this file (the “sudo nano” assumes you are editing it from the command line):
sudo nano /etc/rc.local
Before the “exit 0” line in it add the following line:
#Auto run the GUI as root
sudo startx
Save it by pressing Ctrl+X, ” Y”, ENTER
Re-boot your RPi and it should automatically run the GUI as the root user.
“No session for pid 696”
We get this message when using this method, the number will be random based on system. It may well be because of using sudo startx.
You can use command “ps 696” to see the process there is no session for, for us it was:
PID TTY STAT TIME COMMAND
902 ? Sl 0:00 lxpolkit
lxpolkit is a “Policy authentication agent”. There’s lots of google resources on no session for PID with lxpolkit but after a few hours of trying we didn’t manage to resolve. Instead we started our application using a script with a delay before it runs so that it simply appears on top of the error message. Bodge, but it works for us…