Getting started with Raspberry Pi B+

Raspberry Pi B+ Kit

The complete guide to setting up the Raspberry Pi B+ model with Raspbian and Wireless network.

Raspberry Pi, purchasing the kit

  • Raspberry Pi Model B+
  • SanDisk Extreme Pro microSDHC UHS-I, Class 10
  • Edimax nano USB Wifi Adapter, EW-7811Un
  • Raspberry Pi B+ Case
  • (Network cable)
  • (Micro USB charger)

Preparing the MicroSDHC card with Raspbian

Download image from http://downloads.raspberrypi.org/raspbian_latest
Follow instructions from http://www.raspberrypi.org/documentation/installation/installing-images/mac.md

unzip *.zip
diskutil list # check what the microSDHC card is listed as: /dev/disk1)
diskutil unmountDisk /dev/disk1
sudo dd bs=1m if=*.img of=/dev/disk1

If “dd: invalid number”: “sudo dd bs=1M if=*.img of=/dev/disk1” (wasn’t needed for me).

You can use “ctrl-T” (SIGINFO) to check progress (knowing that the result should be a bit over 4 GB written)

Finally:

sudo diskutil eject /dev/disk1

First run and initial setup

Connect the Raspberry Pi to the network via cable.

Login via SSH (password “raspberry”):

ssh pi@<ip>

Perform initial setup:

sudo raspi-config
  • 1 Expand Filesystem
  • 2 Change User Password
  • 4 Internationalisation Options (added Swedish keyboard layout, changed to correct time zone)
sudo reboot

Fixing vi/vim

Raspbian comes with vim.tiny out of the box and if started via “vi” it will be set to vi-compatible, which I don’t like (no normal arrows keys et.al.). So this had to be fixed promptly. I didn’t want to settle with vim.tiny (which is what is given in the default installation) and given the following quote from the Raspberry Pi forums I decided to install vim and make it the default editor (instead of nano).

If you install vim then it will update the alternatives link so running vi will actually call vim (in the same way that it calls vim.tiny by default).

sudo apt-get install vim
sudo update-alternatives --config editor /usr/bin/vim.basic

This turned out to be a blessing, now things are back to working as they should (even “vi” now starts “vim.basic”).

Adding a new user

Before I started changing too much, I wanted to create a new user account so I could start messing with personal preferences without messing with the default user (+ for easier log in from other computers).

sudo adduser foo

I also want easy access to root privileges, i.e. allow sudo:

sudo visudo

At the bottom, enter the following and save & quit:

foo ALL=(ALL) NOPASSWD: ALL

Setting up wireless network

I followed the guide in this article and calculated the hexadecimal WPA key (given my passphrase) via this site, but once I had edited “/etc/wpa_supplicant/wpa_supplicant.conf” and tried to start the interface (wlan0), it didn’t work:

foo@raspberrypi $ sudo ifup wlan0
ifup: interface wlan0 already configured
foo@raspberrypi $ ifconfig
..lines removed…
(wlan0, RX/TX bytes = 0.0)

I took a look at the logs and noticed “failed to parse ssid ‘MY_SSID'”

sudo tail -n30 /var/log/daemon.log

It turned out the ssid must have quotes around it (and passkey must not), the resulting wpa_supplicant.conf became:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="MY_SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk=9e9988bde2cba74390c0289ffda07bc41ffa889a3309237a2240c934bcdc7ddb
}

Once that was corrected  I restarted the wlan interface and checked ifconfig to ensure that wlan0 was transferring data:

pi@raspberrypi $ /etc/wpa_supplicant $ sudo ifdown wlan0
pi@raspberry $ sudo ifup wlan0
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
pi@raspberrypi $ ifconfig
...(wlan0 RX bytes:385 TX Bytes:872)...

I still had an issue with wlan0 not receiving any IP-address. To solve this I followed the guide in http://omarriott.com/aux/raspberry-pi-wifi/. I had to change face “manual” to “dhcp” for wlan0, resulting in the following content of /etc/network/interfaces:

# loopback
auto lo
iface lo inet loopback

# ethernet
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

# wifi (dhcp)
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

# default
iface default inet dhcp

Enabling SSH (to Raspberry Pi) over Wifi

In order to be able to connect (from another computer) to the Raspberry Pi’s Wifi IP address, change “wpa-roam” to “wpa-conf” for wlan0 in /etc/network/interfaces and reboot:

sudo reboot

Updating the firmware and software

sudo rpi-update
sudo apt-get dost-upgrade
sudo reboot

Further reading:

http://unix.stackexchange.com/questions/128439/good-detailed-explanation-of-etc-network-interfaces-syntax

http://raspberrypi.stackexchange.com/questions/9257/whats-the-difference-between-wpa-roam-and-wpa-conf-in-the-etc-network-inte

Work around for DHCP client bug, bug #1125066

Hrm, looks like I never needed this workaround but I’m keeping it just in case I’ll stumble upon this issue later.

https://bugs.launchpad.net/raspbian/+bug/1125066

A workaround is to create a wrapper script by renaming /sbin/dhclient to /sbin/dhclient-bin and but the text below in /sbin/dhclient and afterwards chmod it to 777:

#!/bin/sh
/sbin/dhclient-bin -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0

Leave a Reply