Setup PI to work without monitor (debian image)


25 posts
by piways_and_highways » Sun Jun 03, 2012 5:04 pm
Hi

I thought I would keep my notes on my PI configurations, in case it helps anyone else.

Using the PI without a monitor
You can plug your Pi into the Network and your laptop USB for low power usage and use VNC and SSH, also this method frees up the USB ports from mouse and keyboard.

I am assuming you have already used the boot.rc file to enable SSH and managed to login to the PI over SSH, or are using the HDMI for initial interfacing with the PI.

Static IP Address
If your running your PI on the local LAN. Chances are the PI will be getting the same IP Address everytime you boot. However if you want to be sure that this is the case you can edit the following config file /etc/network/interfaces. You can use whatever text editor you wish to do this, but you must run it as sudo. Once you have opened the file complete the network information that relates to your network. Use the sample below for reference, but use your IP range, gateway etc. This will give your PI the same IP each time it boots. Note: make sure nothing else on the network has the same IP.
Code: Select all
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1

Once you have done this restart networking or reboot
Code: Select all
sudo /etc/init.d/network stop
sudo /etc/init.d/network start

or
Code: Select all
sudo reboot

Next install the vncserver
Code: Select all
sudo apt-get install tightvncserver


Now complete the initial vncserver setup as detailed below. Set this up as the pi user When you see the output below vncserver is good to go.

Code: Select all
pi@raspberrypi:~$ vncserver

You will require a password to access your desktops.

Password:
Warning: password truncated to the length of 8.
Verify:   
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is raspberrypi:1

Creating default startup script /home/pi/.vnc/xstartup
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:1.log

Now we want vncserver desktop to run at boot time. This is done by putting a startup script in /etc/init.d. Create the file tightvncserver in here. This must be done as superuser.
Code: Select all
pi@raspberrypi:~$ cd /etc/init.d
pi@raspberrypi:/etc/init.d$ sudo vim tightvncserver

Add the following to the script:
Code: Select all
#! /bin/sh
# /etc/init.d/tightvncserver
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    su pi -c '/usr/bin/vncserver'
    echo "Starting VNC server "
    ;;
  stop)
    pkill vncserver
    echo "VNC Server has been stopped (didn't double check though)"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0

Make the script executable:
Code: Select all
sudo chmod +x tightvncserver

Now kill the previous instance which started on hte initial setup
Code: Select all
sudo pkill Xtightvncserver

check VNC server is not running:
Code: Select all
ps aux | grep vnc

Now start the vncserver via the startup script
Code: Select all
pi@raspberrypi:/etc/init.d$ sudo /etc/init.d/tightvncserver start

You should see the output as below:
Code: Select all
New 'X' desktop is raspberrypi:1
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:1.log

Now each time you boot the raspberry PI the VNC server will be started on the IP Address at desktop :1
e.g.
192.168.1.5:1
Posts: 4
Joined: Tue May 29, 2012 7:46 pm
by piways_and_highways » Sun Jun 03, 2012 5:27 pm
Erratum:
Code: Select all
sudo pkill Xtightvncserver

should be:
Code: Select all
sudo pkill Xtightvnc
Posts: 4
Joined: Tue May 29, 2012 7:46 pm
by piways_and_highways » Sun Jun 03, 2012 6:10 pm
Erratum 2 [missed a step off the end]

To make sure the script runs at boot and shutdown:
Code: Select all
cd /etc/init.d
pi@raspberrypi:/etc/init.d$ sudo update-rc.d tightvncserver defaults

This will add the correct symbolic links for the script at reboot and shutdown.
[* http://www.debian-administration.org/articles/28 ]
Posts: 4
Joined: Tue May 29, 2012 7:46 pm
by alexreyland » Fri Jun 08, 2012 11:59 pm
thanks for going to the effort of writing it all down step by step which is perfect for me as im trying to get my head around commands at the moment.
i am having troble at
Code: Select all
pi@raspberrypi:/etc/init.d$ sudo vim tightvncserver
it just comes back with
Code: Select all
-bash: vim: command not found
even though vim seems a legit command as it will happily bring the man up for it.

if you could tell me where im going wrong that would be great, and if you dont mind telling me what the uses for vim are.
thanks
Posts: 2
Joined: Fri Jun 08, 2012 11:52 pm
by bladerunner » Sat Jun 09, 2012 9:03 am
use vi not vim
Posts: 1
Joined: Sat Jun 09, 2012 9:00 am
by phrasz » Sat Jun 09, 2012 5:53 pm
Vnc is unencrypted FYI.

You also don't have to setup static IP's if you get a network scanner like nmap
Code: Select all
sudo apt-get install nmap #debian
pacman -S nmap #arch

Then scan:
Code: Select all
nmap 192.168.XXX.0/24 # where XXX is your class c; find it via ifconfig/ipconfig


At that point look for port 22 for ssh...
Code: Select all
Nmap scan report for 192.168.1.130
Host is up (0.0017s latency).
Not shown: 999 closed ports
PORT   STATE SERVICE
22/tcp open  ssh
Posts: 46
Joined: Fri Jun 01, 2012 4:13 am
by blurp » Sun Jun 10, 2012 3:04 am
alexreyland wrote:thanks for going to the effort of writing it all down step by step which is perfect for me as im trying to get my head around commands at the moment.
i am having troble at
Code: Select all
pi@raspberrypi:/etc/init.d$ sudo vim tightvncserver
it just comes back with
Code: Select all
-bash: vim: command not found
even though vim seems a legit command as it will happily bring the man up for it.

if you could tell me where im going wrong that would be great, and if you dont mind telling me what the uses for vim are.
thanks


There is no vim. Only vim.tiny.

Best Regards
Posts: 11
Joined: Tue Jun 05, 2012 2:38 pm
by GravitySmacked » Sun Jun 10, 2012 2:44 pm
Add the following to the script:

I'm stuck at this step, how do I add the script? I've opened the file I've just created and pasted it in but then when I try the next step:

sudo chmod +x tightvncserver

It just tells me there is no such file or directory.

Sorry for the noob question but I'm stumped.
Posts: 2
Joined: Sat Jan 07, 2012 6:29 pm
by alexreyland » Sun Jun 10, 2012 2:56 pm
I think I managed all the steps but I'm not sure if its all done correctly i was completly guessing it when it came to creating script with vi.
I tried connecting from my windows pc with tight vnc but it just said it was refused.
Posts: 2
Joined: Fri Jun 08, 2012 11:52 pm
by GravitySmacked » Sun Jun 10, 2012 4:46 pm
When connecting try changing your VNC port number to 5901
Posts: 2
Joined: Sat Jan 07, 2012 6:29 pm
by Colossus86 » Sun Jun 17, 2012 10:43 pm
when i do
"sudo update-rc.d tightvncserver defaults"
i receive this error:

insserv: warning: script 'K01tightvncserver' missing LSB tags and overrides
insserv: warning: script 'tightvncserver' missing LSB tags and overrides

whats mean?


p.s. i apologize for my bad eng
p.p.s. in the script ".... echo "Usage: /etc/init.d/blah {start|stop}" ......" blah don't be replaced by tightvncserver?
Posts: 2
Joined: Sun Jun 17, 2012 12:11 am
by jtorresheredia » Fri Jun 29, 2012 12:56 am
Hi,
i solved this issue :
insserv: warning: script 'K01tightvncserver' missing LSB tags and overrides
insserv: warning: script 'tightvncserver' missing LSB tags and overrides


adding the following lines at the beginning of the script:

Code: Select all
#!/bin/bash
### BEGIN INIT INFO
# Provides:          tightvncserver
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: vnc server
# Description:
#
### END INIT INFO
Posts: 1
Joined: Fri Jun 29, 2012 12:53 am
by stewils » Thu Aug 02, 2012 7:28 pm
might i suggest that instead of using vim/ vi it might be easier for us mere mortals to use nano?

so after starting vnc for the first time and doing the password stuff the next bit would be:

Code: Select all
cd /etc/init.d
sudo nano tightvncserver
Posts: 1
Joined: Thu Aug 02, 2012 7:19 pm
by raven_squire » Tue Aug 07, 2012 12:34 pm
Hello,

Another noob here with a few questions.

When I "ps aux | grep vnc" what should I expect I get five lines of stuff that I don’t understand

When I try starting the server (sudo /etc/init.d/tightvncserver start) I get
/etc/init.d/tightvncserver: 7: /etc/init.d/tightvncserver start: Syntax error: word unexpected (expecting ")")

Also what client do I use to access this server and how. Can I use Real VNC Viewer on windows 7 and just leave the default settings?

Thanks in advance.
Posts: 22
Joined: Fri Jun 29, 2012 8:39 am
by iby » Wed Aug 08, 2012 1:11 am
ps - command lists running processes,
ps aux - lists ALL active processes
| is pipe to combine it with another command
grep is that another command used to filter output of ps and only show lines containing "vnc"
User avatar
Posts: 6
Joined: Mon Aug 06, 2012 6:14 pm
by areyal » Tue Sep 04, 2012 5:02 pm
thanks piways_and_highways for the info, and stewils for telling about nano (I was dying with vim) :lol:
Posts: 1
Joined: Tue Sep 04, 2012 5:00 pm
by craig_uk » Thu Oct 18, 2012 11:37 am
Hey Guys,

I am also getting the same error when trying to start the script, same as raven_squire above.

Syntax error: word unexpected (expecting ")")

I thought it may be a copy paste thing but i have also tried typing everything out.
Any Ideas?
Posts: 1
Joined: Thu Oct 18, 2012 11:30 am
by beave2111 » Wed Oct 31, 2012 4:16 am
craig_uk wrote:Hey Guys,

I am also getting the same error when trying to start the script, same as raven_squire above.

Syntax error: word unexpected (expecting ")")

I thought it may be a copy paste thing but i have also tried typing everything out.
Any Ideas?


I happened to get the same error while running through this and it was caused by a typo. The keyword was esac and I had typed esc. Perhaps you did the same thing?
Posts: 1
Joined: Wed Oct 31, 2012 4:13 am
by total_Linux_noob » Sun Dec 02, 2012 2:18 am
Hi all, using a combination of these instructions...

http://myraspberrypiexperience.blogspot ... cally.html

...and forum user jtorresheredia's header edit, I was able to get tightvncserver up and running at boot time!

Thanks everyone!
TLN
Posts: 4
Joined: Sat Dec 01, 2012 7:37 am
by mrcranky » Fri Dec 28, 2012 8:31 pm
Hi,

I followed the instructions, but when I get to:

sudo /etc/init.d/tightvncserver start

The response is:
/etc/init.d/tightvncserver: 7: /etc/init.d/tightvncserver: Syntax error: word unexpected (expecting ")")

Can anyone tell me what I'm doing wrong? I'm using the Raspbian wheezy image.

Thanks!
Posts: 9
Joined: Fri Dec 28, 2012 8:27 pm
by mrcranky » Fri Dec 28, 2012 9:03 pm
mrcranky wrote:Hi,

I followed the instructions, but when I get to:

sudo /etc/init.d/tightvncserver start

The response is:
/etc/init.d/tightvncserver: 7: /etc/init.d/tightvncserver: Syntax error: word unexpected (expecting ")")

Can anyone tell me what I'm doing wrong? I'm using the Raspbian wheezy image.

Thanks!


I'll add that this is what my tightvncserver file reads, which is the exact same as what the initial post says:

#! /bin/sh
# /etc/init.d/tightvncserver
#

# Carry out specific functions when asked to by the system
case "$1" in
start)
su pi -c '/usr/bin/vncserver'
echo "Starting VNC server"
;;
stop)
pkill vncserver
echo "VNC Server has been stopped (didn't double check though)"
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;
esac

exit 0
Posts: 9
Joined: Fri Dec 28, 2012 8:27 pm
by seven » Fri Jan 25, 2013 10:04 pm
After I type this:
pi@raspberrypi:/etc/init.d$ sudo /etc/init.d/tightvncserver start


I get this :

Syntax error: Unterminated quoted string


I typed this into the file

Code: Select all
#! /bin/sh
# /etc/init.d/tightvncserver
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    su pi -c '/usr/bin/vncserver'
    echo "Starting VNC server "
    ;;
  stop)
    pkill vncserver
    echo "VNC Server has been stopped (didn't double check though)"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac



Im rereading what I typed did I miss anything?

Thanks

UPDATE: I have a feeling that those parenthesis that are used are causing the issue... but thats how the script was written..
Posts: 2
Joined: Fri Jan 25, 2013 9:45 pm
by jordan314 » Thu Feb 21, 2013 12:39 am
Hi,
Thanks for this. I couldn't get init.d/vncserver to keep running on reboot. I had to run this:
sudo update-rc.d vncserver defaults 99
That sets it to run on reboot, but at a low boot order, per these threads:
http://www.debian-administration.org/articles/28
http://www.abdevelopment.ca/blog/start- ... omment-355
I found that your init.d script works better than the one I found in the other forum though.
Also, I have two tricks for connecting to the raspberry pi headless. The first is to run arp -a on your desktop and look for raspberrypi. You should see something like:
raspberrypi.yourISP.com (192.168.1.109)
You can connect either via the IP or the DNS name, raspberrypi.yourISP.com.
Also, I installed Avahi, which is the same as apple's bonjour, and now I can also access the pi with the domain raspberrypi.local. So I can use http://raspberrypi.local for HTTP, ssh:pi@raspberrypi.local for SSH, etc.
Thanks--
Posts: 6
Joined: Fri Feb 08, 2013 10:06 pm
by azrith » Sat Apr 06, 2013 9:42 pm
After following all of the instructions and other users posts, I got the script working so that the VNC server starts on boot.
Unfortunately, it seems to be in some sort of restricted mode. I get some misc errors when running my python scripts like it doesn't have access to specific files.
I also noticed that if I go to reboot I only have a logout option. If I start the VNC server when directly connected to the pi, I get all of the regular options from reboot to shutdown etc.

Anyone have any ideas why this would be and how I can go about fixing it?

Thank you!

(Update) - After doing some searching I found this guide to starting the server:
http://learn.adafruit.com/adafruit-rasp ... at-startup
This is much simpler and it also fixed my issue.
Posts: 3
Joined: Sat Apr 06, 2013 9:39 pm
by j8t » Thu Apr 11, 2013 10:11 pm
I'm at a loss at what to do. After playing around for several hours now, I just can't get vncserver to run on boot.

This is the script I'm using, but I've tried others, including those listed in the thread:

Code: Select all
#! /bin/sh

### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:   2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

set -e

# etc/init.d/vncserver: start and stop the vacserver daemon

. /lib/lsb/init-functions

case $1 in
   start)
      log_daemon_msg "Starting vncserver"
      /usr/bin/vncserver
      ;;
    stop)
      /usr/bin/vncserver -kill :1
      ;;
   restart|force-reload)
                $0 stop && sleep 2 && $0 start
                ;;
        try-restart)
                if $0 status >/dev/null; then
                        $0 restart
                else
                        exit 0
                fi
                ;;
        reload)
                exit 3
                ;;
        status)
                status_of_proc $DAEMON "vncserver"
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|try-restart|force-reload|st"$
                exit 2
                ;;
esac

:


Any ideas what I can try? The script is set to execute and I've used update-rc.local <...> defaults to make the symbolic links...

Would appreciate any help that can be offered.
Posts: 5
Joined: Thu Apr 19, 2012 8:10 pm