Raspberry Pi cheatsheet

Image

Flashing

For a headless setup, download Lite version:

https://www.raspberrypi.org/downloads/raspberry-pi-os/

Plug a micro SD card and burn the image on it with Etcher, no need to unzip it, Etcher got your back.

Etcher unmounted the card so you can take it on and off again for your computer to mount it again.

Enable SSH

# From your computer
touch /Volumes/boot/ssh

If you do not have Ethernet or do not want to use it you need to enter some wifi credentials

# From your computer
vi /Volumes/boot/wpa_supplicant.conf

Fill this file with

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

network={
    ssid="NETWORK-NAME"
    psk="NETWORK-PASSWORD"
}

Unmount either through the finder with a click, or by finding the identifier through the diskutil command:

#From your computer
$ diskutil list
# [...]
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.9 GB    disk2
   1:             Windows_FAT_32 boot                    268.4 MB   disk2s1
   2:                      Linux                         1.6 GB     disk2s2
$ sudo diskutil umountDisk disk2

Plug the micro SD card into the Raspberry Pi, power it on and then wait a minute for it to appear on your network.

# From your computer
$ ssh pi@raspberrypi
# The default password is raspberry

If you can not reach it through its hostname you can scan your local network:

# From your computer
$ nmap -sP 192.168.1.\*

Etcher alternative

First steps

Change the password

# From the Pi
passwd

Passwordless ssh access

Copy your public key to the Raspberry Pi:

# From your computer
ssh-copy-id pi@raspberrypi

More on the subject

Upgrade

# From the Pi
$ sudo apt update
$ sudo apt full-upgrade

Hardware

Enabling the camera

# From the Pi
$ sudo raspi-config
# Select interfacing options > camera > enable the camera and reboot when asked to

More on the subject

Backup and restore

Backup

Plug the Raspberry Pi's micro SD card in your computer. Find it with the diskutil list command and unmount it

# From your computer
$ sudo diskutil umountDisk disk2

If you do not unmount it you will get the error:

dd: /dev/disk2s1: Resource busy

The Disk Destroyer command, dd:

# From your computer
$ sudo dd bs=4m if=/dev/disk2 of=20200906__pi-zero__raspbian__camera.img
15931539456 bytes transferred in 1769.633776 secs (9002732 bytes/sec)

Roughly 30 minutes for a 16Gb micro SD card.

Restore

Same drill as for the previous backup section: plug, find and unmount.

# From your computer
$ sudo dd bs=4m if=/Users/mat/images/20200906__pi-zero__raspbian__camera.img of=/dev/disk2
15931539456 bytes transferred in 4487.789624 secs (3549975 bytes/sec)

Roughly 75 minutes for the same card.

An error you might encounter:

dd: bs: illegal numeric value

It is probably because you wrote 4M and not 4m.

Installing

node.js

Get the machine's architecture

# From the Pi
$ uname -a
Linux raspberrypi 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l GNU/Linux

The architecture is armv6l as it should in a Raspberry Pi Zero.

Unfortunately node.js does not support armv6l in their latest LTS releases, namely v14 and v12.

Either go for a v10 build:

https://nodejs.org/dist/latest-v10.x/node-v10.22.0-linux-armv6l.tar.gz

Or go for Rod Vagg's unofficial builds:

https://unofficial-builds.nodejs.org/download/release/v14.10.0/node-v14.10.0-linux-armv6l.tar.gz

Thank you Rod!

Let's get v10:

# From the Pi
wget https://nodejs.org/dist/latest-v10.x/node-v10.22.0-linux-armv6l.tar.gz
tar -xzf node-v10.22.0-linux-armv6l.tar.gz
sudo cp -R node-v10.22.0-linux-armv6l/* /usr/local
rm - rf rm -rf node-v10.22.0-linux-armv6l*

Git

# From the Pi
sudo apt-get install git -y

git config --global user.name "Sarah Conor"
git config --global user.email sarah@cyberdyne.com
Mastodon