Introduction: Ultimate Raspberry Pi Configuration Guide
However it runs on Linux, which I have a love-hate relationship with. I love the idea of Linux, but when I start messing around the command line and downloading packages and installing things, I often get lost.
I've assembled bits and pieces from various online posts and guides into this Instructable, which is what I call the "Ultimate Raspberry Pi Configuration Guide".
What this Instructable does is to set up a wireless Raspberry Pi that allows you to:
- ssh into from the Terminal window on the Mac (or equivalent on another machine).
- run wirelessly with a static IP for each SD card.
- automatically startup, no log in
- set your the time zone
- skip the GUI of the Raspberry Pi, which bogs things down and is unnecessary for most tasks
- minimize any external monitor use, specifically never having to lug a monitor over to where the ethernet router lives
- clone a "basic settings" SD card so that we can have as many base-level installations as we want.
Right now, I have 3 Raspberry Pis running in my closet, each with a different purpose: one runs 7 Twitterbots, one is a Git server and one is an experimentation device for electronics. I plan to add more.
I wrote this Instructable for someone who has a secure home newtwork. You should have a router that can accept a direct ethernet cable. If you are working at an office, the network configuration settings I've outlined here might have to be adapted for your specific company's network/firewall.
Step 1: Gather Materials
- The Raspberry Pi itself
- A power supply with a micro USB cable to power the Pi. Get a 2A one if at all possible
- An 4gb SD card. For most cases, there isn't a need for anything larger.
- A USB wifi dongle. There are many of these that are Pi-compatible on the market
- An ethernet cable to go into your home router
Step 2: Download Raspbian Wheezy
Unless you need special Linux capabilities, Raspbian/Wheezy is the recommended installation.
Download the package here: http://www.raspberrypi.org/downloads
Make sure you double-click the downloaded .zip so that you have a .dmg file. For the purposes of this Instructable, I leave the .img in my downloads folder.
Note: I'm using a Mac as my host computer, but most of these instructions can be adapted for other operating systems.
Step 3: Initialize SD Card Using Disk Utility
Use Disk Utility to initialize your SD card. It doesn't matter what the name of the card is.
What does matter is that the format is MS-DOS (FAT). Format the SD card. It will only take a few seconds.
Quit Disk Utility when you are done.
Step 4: Copy the Wheezy Image Onto Your SD Card
For those of you unfamiliar with using this app, Terminal provides a command-line for controlling the underlying Unix operating system on Max OS X.
Type in (then press enter):
diskutil listThis will list all your mounted drives. You will see something like the image above: a list of drives with different partitions on them. You want to find the information pertaining to your newly-formatted SD card. In my case it is /dev/disk1s1. This may be different on your computer.
Now, unmount the disk using the Terminal command:
sudo diskutil unmount /dev/disk1s1The device /dev/disk1s1 is from my setup — yours may be different. Important: use the right device name on your system.
The preceding sudo command stands for superuser do. These are commands that can wreak havoc if misused, so will require your Admin password.
You'll be shown a message that your SD card has been unmounted. Its disk image will disappear from the desktop.
Here's where you want to pay close attention. We want to type in a command such as:
sudo dd bs=1m if=~/Downloads/2014-01-07-wheezy-raspbian.img of=/dev/rdisk1Note that we are using the "raw device", which means that the name /dev/disk1s1 maps to /dev/rdisk1. Make sure you specify the appropriate raw device, i.e. if your SD device info from diskutil list is /dev/disk3s1, use /dev/rdisk3 for the dd command.
Also, the filename or path for your wheezy-raspbian.img might be different that the one listed here, so please change it accordingly.
Terminal will ask you for your admin password since this was a sudo command. Then you will have to wait long awhile. There is no feedback that any copying is actually happening. This takes something like 30 or 45 minutes. Go have lunch.
Behind the scenes: what the dd command does is copy the disk image and do any necessary conversions.
Once the dd process is done, Terminal will show you how many bytes were transferred to the SD card (about 2.9 gb). Eject the new SD card, which will be now mounted on your computer and be titled something like boot.
Congratulations, you have a bootable SD card for your Raspberry Pi!
Step 5: Basic Pi Configuration
You'll see a black screen with a bunch of text, which shows all sorts of configuration details that you don't need to worry about.
This will take you to a Raspberry Pi configuration screen. You'll see this only the first time. The options are:
1. Expand Filesystem: no need to do this — some may disagree on this point
2. Change User Password: up to you
3. Enable Boot to Desktop/Scratch: by default, this is set to console, which is what we want to keep
4. Internationalisation Options: set your timezone (if in the US, choose America, then find the correct city with your timezone)
5. Enable Camera: no (you can always change this later)
6. Add to Rastrack: no
7. Overclock: this is up to you, I usually choose Medium, which makes the Pi run a little bit faster at the expense of power and potential component damange
8. Advanced options: choose A4 SSH -- this will enable secure shell access, which means that you can control your Raspberry Pi from a remote computer (extremely useful)
Choose Finish and reboot
When you get to a prompt, enter:
sudo nano /etc/default/keyboardchange XKBLAYOUT to ="us" — assuming you are in the U.S., but you can set this to whatever the keyboard code is for your country. Here is a list of country codes from Wikipedia, use two-letter lowercase ones.
nano is a simple built-in editor. Type in ctrl-X and Y and overwrite to save the file.
Make these keyboard changes take effect by rebooting:
Step 6: Setting Up Auto-login
After the reboot, at the command line, enter:
sudo nano /etc/inittabnow, scroll down to the line:
1:2345:respawn:/sbin/getty 115200 tty1
and comment it out by putting a '#' in front of it, such as:
#1:2345:respawn:/sbin/getty 115200 tty1
don't worry if the 115200 reads as 38400 or anything like that, we're just looking for the 1:2345 line
now add the line, beneath it:
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Be super-careful to get the spaces exactly right.
sudo rebootand the pi should automatically login.
Step 7: Download an IP Scanner Package
If you're like me, there is no computer monitor near the ethernet jack. There's ways to get your Raspberry Pi ethernet address through using commands like ipconfig and hook the Pi directly to a monitor. This technique bypasses the lugging the monitor around the room.
My preference is to use IP scanning software on my laptop to identify the local IP address of my Raspberry Pi.
My weapon of choice is Angry IP Scanner which is a cross-platform, donation-ware tool. It has been working great on my Mac.
A note about IP addresses — and this is a broad topic — but the Raspberry Pi will be assigned a local IP address, or one on your private network. It will be IP-addressable, just like a networked printer, but not able to be directly accessed outside of your network.
For most of us, these are a 24-bit block of IP addresses in the: 10.0.0.0 - 10.255.255.255 range.
Step 8: Determine the IP Address and Ssh Into It
In this case, the pi has been assigned to 10.0.1.25, as we can see by the scanner (you'll get an error if you try to ssh into the other ip addresses). With the scanner packages, make sure to scan in the range of 10.0.1.0 - 10.0.1.255.
What we want to do is to log into it via ssh and finish configuring it for a static and wireless IP address.
Open Terminal and type in.
ssh email@example.comYou may have to say "yes" to an authentication screen, but eventually should be able to get in with your password (hint: the default password is raspberry).
Congratulations, now you can ssh into your Raspberry Pi from any laptop on your network.
Step 9: Run Package Updates
sudo apt-get updatethen type in
sudo apt-get upgradeBoth of these commands will give you a lot of gobbledygook. You will wait awhile. Be patient. These update package lists from the various repositories and updates them to get information on the newest versions of packages and their dependencies.
sudo rebootYou'll have to relogin via ssh. Hopefully, the same ethernet address will work, but possibly not, in which case you'll want to use the IP scanner again.
Step 10: Clone the SD Card
What we do have is a fully-working Raspberry Pi setup, with auto-login, custom passwords, correct time zone and keyboard settings. We want to clone this setup so that we can bypass the hassle of going through the set up for each SD card: auto-login, time zone, updates, etc.
Since the static IP addresses wired & wifi are unique for each card, we will just add these individually.
Remove the SD card from your Pi and put it back into your Mac.
Launch Terminal and type in:
diskutil listYou've seen this before but now we have some slight differences in the partition name for the SD card. We don't convert to the raw device name this time, just use /dev/disk1
Type in the dd command, like this:
sudo dd if=/dev/disk1 of=~/Desktop/pibootable.imgThis will copy the SD card image onto your desktop. For making new RPI SD cards, you would copy this Image onto your a new SD Card instead of the Wheezy image. You would then be able to proceed directly to the IP configuration steps.
Step 11: Assigning a Static IP
In theory, you could have a two Raspberry Pis and 10 SD cards. The IP settings will be stored on the SD card itself.
Put the SD card back in your Raspberry Pi.
Connect it with the ethernet cable to your router. Leave the wi-fi dongle disconnected.
Use ssh to get back to logging into your Raspberry Pi, i.e.
ssh firstname.lastname@example.org(or whatever address your IP scanner shows)
sudo nano /etc/network/interfacesYou'll see some various settings that look like the image here.
We want to replace the line: iface eth0 inet dhcp
with: iface eth0 inet static
and then specify the address, netmask, network, broadcast and gateway, like this:
iface eth0 inet static
What this is doing is instead of using DHCP, which dynamically assigns IP addresses, it assigns a static one: in this case it is 10.0.1.64
I picked this one because it is well out-of range of the lower IP addresses, which my network will assign for laptops, printers, etc. You can use a different IP address, if you want. This is just one that I've chosen that is out of collision range.
Before you save these changes, keep a copy of the text of the original /etc/network/interfaces file. You can copy-and-paste this in a text file on your local computer.
note: this is the technique that works on my home network. It may not work on yours, though it has worked for others.
Cntl-X, Y and Return to save and overwrite the file.
sudo rebootFingers crossed. Wait for a few minutes and see if can ssh into this new IP:
ssh email@example.comIf asked for the RSA fingerprint, say yes.
If you have troubles, you can use the IP scanner. Real trouble and you might have to do go back to the monitor.
Step 12: Adding Wi-fi Support
Time to specify the same static IP number for wireless.
sudo nano /etc/network/interfacesYou'll see your edited file, like the image here.
find the line:
above it, add:
then below it add:
iface wlan0 inet static
for wpa-ssid, add your network name
for wpa-psk, add your network password
** Unplug the power from the Raspberry Pi. Plug in your wi-fi dongle. Unplug the cable. Now log in via ssh.
Once again, this work on my network, which uses standard WPA security. If you have a hidden network or additional security, then you'll have to do a bit more research to get these settings right.
Step 13: Done + Troubleshooting Tips
For multiple SD cards, you'll want to use different IP addresses. I use a label-maker and adhere the IP addresses to the back of the SD cards, so I never get confused.
You're off to the races! Have fun.
RSA Key Troubleshooting
If you ever get this dialog in the Mac Terminal Window, it's super-confusing.
What this means is that you've used this IP address for another SD card and now you're trying to use it for another one. It won't let you in.
On the Mac, you'll want to delete a file called known_hosts, which is in a hidden .ssh directory on in your User folder.
The wi-fi configuration with the Raspberry Pi is definitely the trickiest portion of it. This technique works reliably for my home network, as well as several others that I coached through. I'm by no means an expert, so if you get stuck, you'll have to do some creative sleuthing.
I hope this was helpful!
For more on Raspberry Pi code and other projects, you can find me here:
@kildall or www.kildall.com/blog