Setting up a Raspberry Pi

Posted on June 24, 2017
Tags: raspberrypi

This is mostly a set of notes to myself, detailing everything I need to do to set up a new SD card for a Raspberry Pi.

Download Raspbian Jessie Lite.

Unzip it:

unzip 2017-04-10-raspbian-jessie-lite.zip

Insert blank MicroSD card.

(I’m doing this on my Mac laptop, so I’m following the Mac instructions for writing the image to the SD card.)

Determine disk number:

diskutil list

(In my case, the disk number was 4, but change it to reflect the actual disk number in the commands below.)

Unmount disk:

diskutil unmountDisk /dev/disk4

Write image:

sudo dd bs=1m if=2017-04-10-raspbian-jessie-lite.img of=/dev/rdisk4

Enable ssh:

touch /Volumes/boot/ssh

Eject the disk:

sudo diskutil eject /dev/rdisk4

Remove the SD card from the Mac.

Insert the SD card into the Raspberry Pi.

Connect Pi to laptop with Ethernet cable.

Power on the Pi.

After a pause to give it time to come up, connect to the Pi:

ssh pi@raspberrypi.local

(Password is “raspberry”.)

Run raspi-config:

sudo raspi-config

Choose “7 Advanced Options,” and then “A1 Expand Filesystem.”

Choose “7 Advanced Options,” and then “A3 Memory Split.” Then change the “64” to “16.” (Since I’ll be using the Pi headlessly.)

Choose “2 Hostname” and then give the Pi a new name.

Choose “4 Localisation Options,” and then “I1 Change Locale.” Then select “en_US.UTF-8.” Then in the next screen, choose “en_US.UTF-8.”

Choose “4 Localisation Options,” and then “I2 Change Timezone.” Then select “US.” And then select “Pacific-New.”

Choose “4 Localisation Options,” and then “I4 Change Wi-fi Country.” Then select “US.”

Now from the raspi-config main menu, choose “Finish”. When asked if you want to reboot, say “Yes.”

After a pause to give it time to reboot, reconnect to the Pi. (You’ll need to use the new name you gave it. In this example, I named it “pi3.”)

ssh pi@pi3.local

Edit wpa_supplicant.conf:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

At the end of the file, add:

network={
    ssid="Name_of_your_network"
    psk="Your_wifi_password"
}

(But with your SSID and password.)

Reboot the Pi:

sudo shutdown -r now

While it is rebooting, remove the Ethernet cable.

After a suitable pause, reconnect to the Pi via Wi-Fi:

ssh pi@pi3.local

Update the installed software:

sudo apt-get update
sudo apt-get upgrade

Install some basics:

sudo apt-get install git ghc cabal-install emacs-nox

Increase swap space:

sudo emacs /etc/dphys-swapfile

Change “CONF_SWAPSIZE=100” to “CONF_SWAPSIZE=2048”.

Add ssh key:

mkdir ~/.ssh
emacs ~/.ssh/authorized_keys

And copy your public key into that file.

Make .ssh directory and authorized_keys file private:

chmod -R go-rwx ~/.ssh

Reboot:

sudo shutdown -r now

After a pause, reconnect:

ssh pi@pi3.local

(This time, no password should be required.)

Update cabal’s package list:

cabal update

Set up git:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global core.editor emacs

Done!

Adding a printer

ssh to the Pi, creating a tunnel for the CUPS web interface:

ssh pi@pi3.local -L 8631:localhost:631

Then on the Pi, do:

sudo apt-get install cups cups-bsd printer-driver-dymo
sudo usermod -a -G lpadmin pi

Go to http://localhost:8631/, and then more-or-less follow these instructions. (The gist, though, is to click “Administration” and then “Add Printer” and then it’s pretty obvious from there.) Keep an eye on the URL bar, though, because sometimes CUPS will throw you back to http://localhost:631/ instead of http://localhost:8631/.

After doing this, I found that there was still no default printer, and I didn’t see an obvious way to set it in the web interface, so I did:

lpoptions -d DYMO_LabelWriter_450_Turbo

Update: It looks like it’s also possible to skip the ssh tunnel, and just go to http://pi3.local:631/. However, it is not possible to go to http://pi3.lan:631/, even though it resolves to the same IP address!