First steps after you got your Raspberry Pi

Those are the very first steps that you should do right after you received your Raspberry Pi, downloaded the SD images, booted it and randomly played with it for one week. 😀

Change the password: most important step if the Raspberry Pi will be connected to the Internet.

$ passwd

Quick configuration: these are available in Raspbian‘s raspi-config script.

# dpkg-reconfigure keyboard-configuration
# dpkg-reconfigure locales
# dpkg-reconfigure tzdata

Test your SD card:

# dd if=/dev/mmcblk0 of=/dev/null bs=512k count=256 iflag=direct
256+0 records in
256+0 records out
134217728 bytes (134 MB) copied, 6.13969 s, 21.9 MB/s
# dd if=/dev/zero of=/root/test bs=512k count=64 oflag=direct
64+0 records in
64+0 records out
33554432 (34 MB) copied, 10.4764 s, 3.2 MB/s
# rm /root/test

SD card performance should match its class. My SD card is a class 4, so write speed must be around 4 MB/s. Also, slow read speeds could indicate problems.

Update your distro:

# apt-get update
# apt-get upgrade

Improve network configuration: this makes the Pi less dependent on having an external router by adding a permanent static IP address and activating NAT. Skip the network configuration if your Raspberry will always have a router around.

# echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
# cat << EOF >> /etc/network/interfaces
iface eth0:fixed inet static
 address 10.10.10.1
 netmask 255.255.255.0
 up iptables -t nat -A POSTROUTING -o eth0 -s 10.10.10.0/24 -j MASQUERADE
 down iptables -t nat -D POSTROUTING -o eth0 -s 10.10.10.0/24 -j MASQUERADE
EOF

This extra entry (together with the default dhcp interface rule) allows the following scenarios: rasp pi directly connected to your internet modem (using DHCP address); rasp pi connected to computer (using static address); rasp pi connected to a modem (using DHCP address) and computer (using static address and doing internet connection sharing); rasp pi connected to modem and computer, only the computer connected to the internet (the difference in this case is that the computer got the DHCP address from the modem first).

Now write the startup script:

# cat << EOF > /etc/ifplugd/action.d/ifupdown-more
#!/bin/sh
 set -e

if [ "$1" != "eth0" ]; then
 return
 fi

case "$2" in
 up)
 /sbin/ifup $1:fixed
 ;;
 down)
 /sbin/ifdown $1:fixed
 ;;
 esac
EOF
# chmod +x /etc/ifplugd/action.d/ifupdown-more

This is similar to the standard “ifupdown” script and allows automatic interface configuration.

Configure the static connection to Raspberry Pi on your main desktop machine:

# cat "/etc/NetworkManager/system-connections/Raspberry NAT"
(...)
[ipv4]
 method=manual
 dns=8.8.8.8;
 addresses1=10.10.10.2;24;10.10.10.1;
 ignore-auto-routes=false
 ignore-auto-dns=false
 never-default=false
(...)

The dns line above needs to have some random DNS server, for example, I used Google’s (alternatively install DNS proxy support in the Pi). Use the above connection profile in your main machine when using the Pi as a router.

Add a friendly name to Raspberry Pi:

# echo 10.10.10.1 prosraspberry >> /etc/hosts

This is also in the desktop machine, an easy name to find the Pi. Now connect both machines together and test ssh:

# ssh pi@prosrasperry
The authenticity of host 'prosraspberry (10.10.10.1)' can't be established.
 RSA key fingerprint is 33:95:41:c6:d4:06:8b:79:7e:e4:01:fb:17:39:ed:93.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added 'prosraspberry' (RSA) to the list of known hosts.
 pi@prosraspberry's password:
 Linux raspberrypi 3.2.27+ #160 PREEMPT Mon Sep 17 23:18:42 BST 2012 armv6l
(...)
pi@raspberrypi ~ $

Finally, copy the public key from your main machine to the Pi.

$ scp ~/.ssh/id_rsa.pub pi@prosraspberry:id_rsa.tmp
$ ssh pi@prosraspberry
$ cat id_rsa.tmp >> ~/.ssh/authorized_keys
$ rm id_rsa.tmp

And that’s it. The main point of this initial configuration is that now Raspberry Pi should be completely usable anywhere. You just need a power cable and an ethernet cable to connect to it ! 🙂

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s