This blog contains whatever random tech stuff I'm thinking about recently. And a lot of conference reports.

Raspberry Pi Memoirs

Raspberry Pi Memoirs

Christmas Pi

My sister, ever organised, asked me in October what I wanted for Christmas. I’m completely rubbish at delayed gratification, so it was a tricky question: I didn’t want to suggest something I actually wanted and then have to wait two months for it. So I chose a potentially interesting toy instead. “A Raspberry Pi”, I said. She searched online. “The little board thingy?” “Yep!”. “O…kay.”

I know everyone else got on the Pi train four years ago, but Christmas day was my first time holding one. It’s a nifty little thing: four USB ports, HDMI. Ethernet and wireless card on the board. Micro SD for storage. Conveniently powered by Micro USB. (Full specs here). I’d expected it to come in a case, but it was neat that it didn’t. It forces users to confront the hardware itself, rather than treating it as a black box. There’s comfort and familiarity from holding the metal right in your hand. (Cases and a ton of other accessories are available.)

I admired it, said appropriate thank yous, then took it home and put it on a shelf where I occasionally moved it out of the way to get at the stuff behind it.

But not any more! This weekend I’ve had the sort of illness where you’re too sick to do anything that needs creativity or decisions – emails, code, human interactions all seem exhausting and high-stakes – but you’re not really sick enough to do nothing. In other words, it was the perfect time to follow a well-documented install process and do something that’s been praised for being low-drama and easy.

Would it be? Let’s see!

What you actually need

The instructions start with plugging in an external keyboard, mouse and monitor, but that seemed to me to defeat the purpose. If I wanted to have a bunch of hardware sitting around, I’d have used a real computer. Luckily, that’s all optional: it’s possible to install a Raspberry Pi in “headless” mode, where you control it over SSH. So what you actually need is…

  1. a Micro USB charger. It’s the same kind that a lot of Android phones use, as well as Kindles and Nexus tablets, so I had tons of them lying around. I needed to check the (tiny) writing on the charger though: it needs to output 5V and at least 700mA. I had a mix of 500mA and 1As, so used the latter.
  2. a Micro SD card. If you’re feeling fancy, you can buy one with a Raspberry Pi image already on it, but it’s not hard to make your own. If you’re doing that, you also need…
  3. …the ability to write to a micro SD card from your computer. My laptop has SD, but I didn’t have an adapter. If you’re using a monitor and keyboard for the Raspberry Pi, and have an Android phone with a Micro SD slot, you can image the card with RasPi Card Imager. It works great, but you can’t enable SSH that way, so if you’re setting it up as a headless device, you’ll still need to find a card reader eventually. I had one that came with my camera.
  4. An ethernet cable and a free slot on your router. (Though if you don’t have one, it looks like there’s a workaround.

Put an OS on the Micro SD Card

Well, if you bought one with it preinstalled, you’re sorted. If not…

Download the OS image from https://www.raspberrypi.org/downloads/. They recommend using NOOBS, their easy installer, but the various articles I read said that that’s only a good idea if you have a keyboard and mouse. I was tempted by the Ubuntu option, but in the end I reckoned I should start with the official OS. Raspbian it is.

I unzipped the image and it’s pretty big – the first one I downloaded, “Raspian Jessie with Pixel” was 4.1GB and my card’s only 4GB. So I went with the “Lite” version instead. I don’t need the X server or any bells and whistles, and it’ll be easy to add extra packages later as needed anyway.

Now to copy the image to the Micro SD card. I’m running Ubuntu on my laptop, so dd was easiest, but http://elinux.org/RPi_Easy_SD_Card_Setup has instructions for how to do it on various OSes.

After I inserted the card reader with the card inside, I used dmesg to see what its device name was.

$ dmesg
[ 5615.341391] sd 8:0:0:1: [sdb] Attached SCSI removable disk

Looks legit, but I’m nervous around the dd command, so I mounted the disk to take a look at it. Linux is not big on “Are you sure”s, and will happily blow away your operating system.

$ sudo mount /dev/sdb1 /mnt

$ ls /mnt

[... a bunch of files that look like they came from a card scavenged
from an old Android, as indeed mine was. ...]

# Unmount the disk so you can dd to it.
$ sudo umount /mnt

$ sudo dd bs=4M if=2017-01-11-raspbian-jessie-lite.img of=/dev/yourdiskid
331+1 records in
331+1 records out
1390411776 bytes (1.4 GB, 1.3 GiB) copied, 275.479 s, 5.0 MB/s

I wrote a made up disk name here so that if anyone ever reads this and copies and pastes the command line, it’ll do the safe thing by default. If you’re doing that, replace it with your raw device, not the partition, e.g., /dev/sdb, not /dev/sdb1. But be cautious because it will overwrite everything on the disk.

It takes a few minutes and gives no indication that it’s working, My SD card reader flashed a lot though, which was reassuring :-)

Enable SSH on the Micro SD Card

Raspberry Pis used to ship with SSH on and a default username and password. This changed in November 2016 when they got nervous about botnets, but they’ve made it easy to turn SSH back on again. You just need to create a file called ‘ssh’ in the boot partition. So mount the disk again. It now has the image you just copied onto it. Create the file and unmount the disk again.

$ sudo mount /dev/sdb1 /mnt

$ ls /mnt
bcm2708-rpi-b.dtb       bootcode.bin   fixup_db.dat      LICENSE.oracle
bcm2708-rpi-b-plus.dtb  cmdline.txt    fixup_x.dat       overlays
bcm2708-rpi-cm.dtb      config.txt     issue.txt         start_cd.elf
bcm2709-rpi-2-b.dtb     COPYING.linux  kernel7.img       start_db.elf
bcm2710-rpi-3-b.dtb     fixup_cd.dat   kernel.img        start.elf
bcm2710-rpi-cm3.dtb     fixup.dat      LICENCE.broadcom  start_x.elf

$ sudo touch /mnt/ssh

$ sudo umount /mnt

Remove the Micro SD Card and reinsert it into the Raspberry Pi.

Connect the Raspberry Pi to the network… and find it

I plugged my device into power and ethernet and promising looking lights came on. Next thing: figure out what IP address it’s been assigned. I couldn’t remember the router password and was too lazy to walk downstairs to check, so I installed nmap and asked it to find things listening for SSH, i.e., things that had port 22 open.

The output is helpfully annotated with the manufacturer, so the right device was easy to find.

$ sudo nmap -sS -p 22

Nmap scan report for hostname.lan (
Host is up (0.45s latency).
22/tcp open  ssh
MAC Address: B8:27:EB:93:B5:28 (Raspberry Pi Foundation)

The default username and password is pi and raspberry. Fingers crossed…

$ ssh pi@
pi@'s password: [raspberry]

pi@raspberrypi:~ $

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016 armv7l

Excellent! Before I do anything else, stop using the default password.

pi@raspberrypi:~ $ passwd
Changing password for pi.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Enable wifi

This is all good, but I don’t want this thing to be tethered under my desk, so I need to turn on its wifi. That means editing wpa_supplicant.conf to tell it which wireless network to connect to.

pi@raspberrypi:~ $ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

# Add to the end...


# Save and exit, then bounce the interface.

pi@raspberrypi:~ $ sudo ifdown wlan0
pi@raspberrypi:~ $ sudo ifup wlan0

Now ifconfig wlan0 should show an inet address. I was able to SSH to that address, and unplug from the router.

Use it for something

And that’s the hard part, of course. There are a ton of articles out there with names like “10 beginner raspberry pi projects”, and I have a few ideas, but I’m not sure when I’ll get around to that. It may well end up back on the shelf until next time I have a low-grade fever. I’m glad I got it though, and I’m pretty sure we’ll see each other again.

Overall, it was pretty much as easy as promised. For people who use a keyboard and monitor, I think it’ll basically work out of the box. Even going headless, the whole process was well documented, with tons of help online. For context, it’s taken me much longer to write this post than it took to get the device running.

So, a very handy device when you need a little toy server for something. And cheap as chips, of course. I can see why people like it.


Bazel is easier than Makefiles

Bazel is easier than Makefiles

Checking the user's email address in a chrome extension: part two

Checking the user's email address in a chrome extension: part two