Sunday, June 24, 2012

Running a Raspberry Pi in headless mode.

I have just bought a Raspberry Pi micro computer (and boy do they mean 'micro'). It's a neat little computer about the size of your credit card. However it is a bare-bones system with no keyboard, mouse, monitor or hard disk. So what do you need any of them for? Well, with the Pi, you can get away without any of them, except you do need an SD card to act as the hard disk.

My problem is that I don't have an HDMI monitor or a TV in my study, where I want to use my Pi. And I can't be bothered to wait for an adaptor to connect the Pi's HDMI socket to one of my VGA or DVI flat panels. So what am I going to do? Well, a mate of mine solved this problem by using VNC - a remote desktopping solution that I already use at work. The other problem is that I'd really rather like to reduce the cabling required for my Pi even further and do without the heavy-weight LAN cable ... I know, I have an Edimax EW-7711UN wireless dongle that I bought ages ago when my ethernet-over-power failed. I wonder if that will work with the Pi?

So, my aim is a full-screen Pi with no monitor, accessible from my desktop PC, via my domestic wireless network - so I can put the Pi anywhere with power and a wireless signal in the house, and use it as the company intended: X windows on a proper screen.

Here's how I did it.

(Creating the hard disk image on an 2GB SD card I'll leave to other people, because they've done just fine.)
The image of Debian for use with the Pi comes with a an option to enable SSH (secure shell) access to the machine via the LAN cable, so that's where I started:

  1. mount the SD card with a PC card reader, rename "boot_enable_ssh.rc" to "boot.rc" to enable SSH
  2. plug the card into the Pi, connect the LAN cable and power, and boot without a monitor connection
  3. login with pi/raspberry
  4. use "passwd" to change to a real password
  5. run "sudo apt-get install tightvncserver" to install VNC server
  6. run "tightvncserver" and set a password
  7. run "tightvncserver -kill :1" to stop VNC server
  8. run "sudo bash" to elevate to root
  9. create "/etc/init.d/vnc" as below to start VNC server at boot time
  10. run "chmod +x vnc" to make the script runnable
  11. run "update-rc.d vnc defaults" to install the above script for boot
  12. run "aptitude install firmware-ralink wireless-tools" to get the wireless networking tools for Debian
  13. run "aptitude install wpasupplicant" to get the wireless security support for Debian
  14. attach the Edimax 7711 dongle to a usb socket
  15. run "lsusb" to ensure it's powered up and listed
  16. edit "/etc/network/interfaces" as below to boot the wireless card at boot
  17. run "ifup wlan0" to test your configuration - you should get an IP address - write it down.
  18. remove the LAN cable, and reboot 
  19. now you can login via the new IP address via VNC or SSH.
This is my Pi in action: notice the lack of spaghetti cabling so common in other configurations ;-)

I have got a powered USB hub on the way, so that will add another cable to the above, but actually, I'm not sure it'll be needed afterall.


# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.

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

export USER HOME
case "$1" in
        echo "Starting VNC Server"
        #Insert your favoured settings for a VNC session
        su - $USER -c "/usr/bin/vncserver :1 -geometry 1280x1024 -depth 24 > /tmp/vncserver.log 2>&1 &" &
        echo "Stopping VNC Server"
        /usr/bin/vncserver -kill :1
        echo "Usage: /etc/init.d/vncboot {start|stop}"
        exit 1
exit 0


# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo wlan0

iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet dhcp
        wireless-essid YOUR SSID
        wpa-ssid YOUR SSID
        wpa-psk "YOUR NETWORK PASSWORD"
There are probably ways to encrypt the network password, but I've not figure them out yet.


  1. Thanks for the post, I'm similarly headless.
    If you have no screen, why not just locate your pi alongside your router (or even inside it if there's room..)? Many routers have a USB socket that can be used to power your pi, so one short usb lead for power and a short LAN cable does the job.

  2. a) my router doesn't have this functionality.
    b) the router is in the middle of the house, my study is on the second (US: third) floor.

    I just wanted to prove that I could get the Pi to run off just one cable. Job done.