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:
- Install Raspbian on a headless Raspberry Pi.
- Configuring Dynamic DNS using FreeDNS.
- Encrypting an external USB drive using TrueCrypt.
- Setting up Nginx web server.
- Setting up MySQL database.
- Setting up PHP.
- 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:
- Image http://downloads.raspberrypi.org/raspbian_latest
- Torrent http://downloads.raspberrypi.org/raspbian_latest.torrent
- SHA-1 Checksum 9d0afbf932ec22e3c29d793693f58b0406bcab86
- Default login pi / raspberry
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 192.168.1.0/24 | 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 192.168.1.0/24| 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:
192.168.1.1 192.168.1.19 192.168.1.12 192.168.1.20 Plug the Raspberry Pi wait at least for a minute and press enter 192.168.1.1 192.168.1.11 192.168.1.19 192.168.1.20 192.168.1.12 New IP address found: 1a2 > 192.168.1.11
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 192.168.1.106 to the Raspberry and declaring that the router IP is 192.168.1.1
Excerpt of /etc/network/interfaces #iface eth0 inet dhcp iface eth0 inet static address 192.168.1.106 netmask 255.255.255.0 gateway 192.168.1.1
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
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 email@example.com
Test that it works
$ ssh firstname.lastname@example.org
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 HostName 192.168.1.106 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.