Headless Boot Of Raspberry Pi Using DHCP

I’ve been meaning to do something with this amazing little machine for a long time. It really appeals to me because you can use it just like an embedded target device – in other words, you can do embedded programming at home for very little cost.

This tutorial walks you through the set-up of your Pi without all those pesky peripherals, like a keyboard and monitor.

This is known as a headless boot, and it’s a basic embedded technique for dealing with target devices.

There are two ways that we can approach a headless boot over the network:

  1. using DHCP
  2. by creating a statically allocated ip address.

I’ll cover number 1 here, and number 2 in a separate post.

Let’s get started. You will need:

  1. A computer running Linux (mine is Fedora 20).
  2. A Raspberry Pi and compatible power adapter.
  3. An ethernet cable.
  4. An SD card for the Pi OS

Step 1 – Create a bootable SD card

This was actually the step that I had the most trouble with. For some reason, some SD cards don’t seem to get on very well with the Pi. In the end, after trying several that were knocking around the house, I got a bootable card using this particular SD card:

raspbian

I put Raspbian on the card as the Operating System. The downloads page for Raspbian (and other OSs) is on the Raspberry Pi website.

To get the OS onto your SD card, follow the official instructions here – they are listed under Linux, Mac and Windows at the foot of the page.

Step 2 – Boot up the Pi and Check the LEDs

Make sure you put the SD card in first 😉

Before you power on, you should also connect the ethernet cable from your Pi to your router. Most home networks will use DHCP to allocate an ip address to a new device. If you know that yours doesn’t do this, or you want to specify the ip address of your Pi, I’ll be posting about that next week.

When you power the Pi, you should see all the lights flashing away. There are five LEDs on the board:

  • OK (ACT on revision 2 boards)
  • PWR
  • FDX
  • LNK
  • 10M (100 on revision 2 boards)

The first LED to come on will be PWR, which you can guess is the indicator for power received. This should always be on.

The bottom three lights are all related to the network connection – full duplex, link light and connection speed. The maximum connection speed of the Pi is 100mbps – don’t be fooled by the 10M label (this was corrected to 100 on the revision 2 board).

The top LED will only light up when the SD card is being accessed. It was renamed to ACT (activity) on the revision 2 board. When I first started using the Pi I thought that if OK wasn’t lit up then something had gone wrong (and this is possibly the reason for the name change), but this is not the case.

If your Pi boots up correctly from the SD card, and connects to the network, you should see the bottom four lights on as in this photo:

pi_leds

If your Pi looks like this, you’re ready for the next step!

Troubleshooting

If you only get the power LED and nothing else, it is probably an issue with the SD card. I tried three cards before I found one that worked.

However, sometimes you really will need to connect up a keyboard and monitor to see what’s happening – there is only so much you can try before you need some output from the device to tell you what is going on.

Step 3 – Find Your Pi On The Network

OK, so your Pi is ready and waiting. Head back to your computer and install nmap:

sudo yum install nmap

Type

ifconfig

to identify the ip address of the machine you are using.

Then scan the entire subnet by replacing the last set of numbers with 0/24:

nmap 192.168.1.0/24

This will output information on all the hosts on your home network. Somewhere in here you should see the Raspberry Pi listed with its ip address:

nmap_pi

You can also see that the ssh is enabled. So, onto the next step…

Step 4 – Access Your Pi

In a terminal window, type:

ssh pi@192.168.1.89

This is telling ssh you want to log in as user ‘pi’ to the ip address listed above.

Type ‘yes’ at the prompt and then enter the default password: raspberry.

You’re in!

Step 5 – Expand Your Filesystem

Once you’re logged into the Pi, the first thing you should do is run

raspi-config

This will bring up a config utility like this:

raspi-config

If you don’t do this, you’ll run out of space pretty quick (i.e. as soon as you run an OS update).

Select option 1, and make any other changes you might want. They are all optional and you can always come back to this later – I left everything as it was for now.

Finally, exit and reboot.

The last thing you should do before playing with the Pi is a system update:

sudo apt-get update

followed by

sudo apt-get upgrade

If you want to remove the downloaded packages (they can take up a lot of space), you can do this with

sudo apt-get clean

And then you should be good to go.

Next week: headless boot with a static ip.

Note: all Pi tutorials are created using a revision 1 board.