Headless Pis over VNC

After half term, I’ll be giving our Programming Club members access to their own Raspberry Pi. But because I don’t have the space for extra monitors in our IT Lab, I’ll need to have another workaround for letting the students have access to their Pis.

The best way to do this is to make the Pis ‘headless’. No need for anything other than power and an Ethernet cable.

I’ve done this by cobbling together instructions I found across other websites – my build notes are below. Each Pi has its own dedicated IP address that’s outside of our DHCP scope.

Image the SD card

Begin by using Mac to install image to SD card by opening Terminal and running the following command to get the SD card id:

df -h

Unmount it to prepare it for imaging

sudo diskutil unmount /dev/disk5s1

(disk5s1 is the value returned for my SD card. YMMV.)

Change your working directory to that of where you have your Raspberry Pi OS image. In this case, I have an image of raspberian-wheezy in my ~/Downloads folder. Copy image. Wait.

cd ~/Downloads
 sudo dd bs=1m if=2012-12-16-wheezy-raspbian.img of=/dev/rdisk5

Once that’s all complete, your SD card will mount itself in the Finder with a name of ‘Untitled’. Eject it, put it in your Pi and start it up.

Run raspi-config

raspi-config should launch once your Pi has completed the boot sequence. I chose the options to:

  • expand rootfs, which will partition the rest of your SD card to be available to be used upon the next reboot
  • enable ssh – essential if you want to remote in to your Pi
  • check for any updates

Then finish. There is no immediate need to reboot your Pi at this point, as re-partitioning the available SD card space takes about a minute per available gigabyte.

Configure the Network

Open up your *interfaces* file

sudo pico /etc/network/interfaces

Configure your network interface. Each one of our Pis has been given a static address.

iface eth0 inet static

address 192.168.1.x

netmask 255.255.255.0

gateway 192.168.1.1

You can verify your network changes after the next reboot.

Install and Configure tightvncserver

(more instructions here)

sudo apt-get update

sudo apt-get install tightvncserver

Start server and configure a password (password is restricted to 8 characters). A view-only password is really not needed.

/usr/bin/tightvncserver

Download this text file to add tightvnc to startup

wget http://www.penguintutor.com/otherfiles/tightvncserver-init.txt

Move it to the correct location

sudo mv tightvncserver-init.txt /etc/init.d/tightvncserver

Change the file so it is owned by root (not strictly neccessary, but is the standard ownership for init files

sudo chown root:root /etc/init.d/tightvncserver

Make the file executable

sudo chmod 755 /etc/init.d/tightvncserver

Add the script to the default runlevels with the command

sudo update-rc.d tightvncserver defaults

If all has gone correctly at this point, you can reboot your Pi. When it comes back up it will begin to reallocate free space on the SD card if you chose that option in *raspi-config*. Again, allow about 1 minute per Gb on the card.

sudo shutdown -r now

Check everything works

When your Pi comes back up, check that VNC works on port 5901. You can do this on a Mac by using Screen Sharing in the Finder by choosing Go > Connect to Server and then typing vnc://pi@192.168.1.x:5901, using your Pi’s IP address.

You can also check SSH from Terminal:

ssh pi@192.168.x.x

If it works, that’s it, you’re done! Shut down the Pi and relocate it somewhere else with just a power lead and network cable.

sudo halt

Author: Papa Makes

Papa Makes is run by Jim Christian. A keen edtech advocate and author, Jim has written “How to Code in Minecraft” for Dennis Publishing and “How to Think Like a Coder: Without Even Trying!” for Pavilion Books.

Share This Post On
%d bloggers like this: