Headless Pi Mess: Installing Raspbian

Journey to the Clouds series.
1. Install Raspbian on a headless Raspberry Pi.

In this post we will install Raspbian, a Debian based distro, in the Raspberry PI. Usually I’d go for Arch Linux but for this project I will side with Debian because the lower frequency of updates and therefore less maintenance once it is up and running. As a downside we will have to install TrueCrypt, PHP, Nginx and ownCloud either from source either from their repositories to take advantage from the latest packages.

Journey to the Clouds index:

  1. Install Raspbian on a headless Raspberry Pi.
  2. Configuring Dynamic DNS using FreeDNS.
  3. Encrypting an external USB drive using TrueCrypt.
  4. Setting up Nginx web server.
  5. Setting up MySQL database.
  6. Setting up PHP.
  7. Installing ownCloud.

I will use my Linux box to flush the image onto the SD card and to connect to the Raspberry Pi through SSH, but you could use whatever OS that lets you sleep at night. Especially for the part of writing the Raspbian image onto the SD card, remember GIYF.

Grab the image from the Raspbian downloads site, at the time of writing this post the latest image is ‘2014-01-07-wheezy-raspbian’ and the direct links are the ones shown below:

Once you get the image, verify the image with the SHA1 signature:
$ sha1sum -c <(echo "9d0afbf932ec22e3c29d793693f58b0406bcab86 2014-01-07-wheezy-raspbian.zip")

If you would like to optimize the SD card read this previous entry otherwise flush the image as described below.

Plug the SD card into your computer and find out the device name. In my opinion the easiest way it to execute lsblk, plug the SD card, execute again lsblk and spot the differences. However feel free to use fdisk -l, inspect the journal (journalctl -f) or the messages file for non-systemd (tailf /var/log/messages) or even use a graphical application like GParted. Whichever method you choose just make sure it is the SD card, don’t come crying later on if you messed it up.

In my case the SD card is assigned to /dev/sdb. In the following commands notice I am using the whole device (/dev/sdb) and not the partition (/dev/sdb1). If you have enough free RAM unzip on the fly and flush it all at once:
$ gunzip -c 2014-01-07-wheezy-raspbian.zip | sudo dd of=/dev/sdb bs=64K

Otherwise do it in two steps or it will hog your computer:
$ gunzip -k -S .zip 2014-01-07-wheezy-raspbian.zip
$ sudo dd if=2014-01-07-wheezy-raspbian of=/dev/sdb bs=1M

If you want to monitor the progress you can open a new terminal, find out the PID of the dd command and send the USR1 signal to it. The output will show in the terminal where dd was launched.
$ sudo watch kill -USR1 $(pidof dd)

Next is to insert the SD into the Raspberry Pi but, since it is a headless installation, repress yourself from doing it just now and keep reading before proceeding. The way to find out the IP address of the Raspberry Pi is to list the IP addresses in your network before and after you connect it and compare the differences (the before-after-comparison again, it’s like the MAcGyver chewing gum). Of course you could always log into your router and see the connected devices if you prefer. If you, wisely, choose the path of the console, execute:

dirA=$(fping -i 10 -r 1 -aAgq | tee /dev/tty) && \
echo -e "\nPlug the Raspberry Pi, wait at least one minute and press enter"; read novar && \
dirB=$(fping -i 10 -r 1 -aAgq| tee /dev/tty) && \
echo -e "\nNew IP address found:"; \
diff <(echo "$dirA" | sort) <(echo "$dirB" | sort) && echo "  |-> None"

As the black terminal says, and your are bound to obey because it is the black terminal, plug the Pi when it says so and wait for a minute, then hit enter. If everything went alright you should see the new IP. This is the output of my network:

Plug the Raspberry Pi wait at least for a minute and press enter

New IP address found:

Log into the Pi and finish the installation. As it was shown earlier, the default login for the image we installed is username: pi and password: raspberry
$ ssh pi@
$ sudo raspi-config


Essential adjustments:
1 Expand Filesystem
3 Enable Boot to Desktop/Scratch
  |→ Console Text console, requiring login (default)
8 Advanced Options 
  |→ A3 Memory Split → 16

Recommended adjustments:
2 Change User Password
4 Internationalisation Options 
  |→ I2 Change Timezone
8 Advanced Options 
  |→ A2 Hostname

To my taste:
4 Internationalisation Options 
  |→ I1 Change Locale
      - deselect en_GB.UTF-8 UTF-8  
      + select en_US.UTF-8 UTF-8
       Default locale for the system environment: en_US.UTF-8

Before rebooting, one final thing is to assign a static IP to the Pi, for that edit /etc/network/interfaces, comment out the line 'iface eth0 inet dhcp' and add the static definition. Below you have an example assigning the IP to the Raspberry and declaring that the router IP is

Excerpt of /etc/network/interfaces
#iface eth0 inet dhcp
iface eth0 inet static

If you don’t know how to edit that file type:
$ sudo nano /etc/network/interfaces
Make the changes, save by pressing ctrl+o and exit by pressing ctrl+x (then be a man and learn how to use vi).

Now you can reboot your Pi
$ sudo reboot

It is recommended to update the system after a fresh installation:
$ sudo apt-get update && sudo apt-get upgrade

Sit back and triumphantly exhale, you’ve done it!!!!!!

But as a bonus, let’s ingest a SSH candy and configure the SSH connection to simplify future log ins from your Linux computer. The following is to be done in your Linux box, not in the Raspberry Pi. If you don’t have an authentication key pair yet, generate one:
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_raspbian
Copy the public key to the Pi
$ ssh-copy-id -i ~/.ssh/id_rsa_raspbian.pub pi@
Test that it works
$ ssh pi@

Finally add the new entry in your SSH configuration file.

Excerpt of ~/.ssh/config
# Entry for the Raspberry Pi
Host pi_root
  User root #by default root access is not permitted in Raspbian
Host pi 
  User pi
Host pi pi_root 
  IdentityFile ~/.ssh/id_rsa_raspbian

#Default values to all connections
Host *
  ForwardAgent yes
  ForwardX11 yes
  PubkeyAuthentication yes

From now on, we can simply log in by typing
$ ssh pi

In the next chapter we will configure Dynamic DNS to access the Raspberry Pi from everywhere.

This entry was posted in Journey to the Clouds, Linux, Raspberry Pi, Raspbian and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s