Install Raspberry Pi OS

The best way to install Raspberry Pi OS onto an SD card, is to use rpi-imager from another computer. This allows you to set up the user account, network settings, and SSH credentials all from the imager software.

rpi-imager

  • On your personal workstation, Download the Raspberry PI Imager or install rpi-imager from your package manager.

  • Run rpi-imager.

  • Click on the menu labled Rasperry Pi Device.

    • Choose your model of Raspberry Pi.
  • Click on the menu labeled Operating System

    • Choose Raspberry PI OS (other)
    • Choose Raspberry PI OS Lite (64-bit).
  • Click on the menu labeled Storage.

    • Choose the Storage device to install to.
    • You may need to change the ownership of the device (e.g., I had to do sudo chown ryan /dev/sdb first).
  • Click Next.

  • Click Edit Settings.

    • On the General tab:

      • Enter the hostname (e.g., pi).
      • Enter a username and password (e.g., pi).
      • Optionally set up the Wi-Fi (I just use ethernet instead).
      • Set locale settings. (e.g., UTC).
    • On the Services tab:

      • Click Enable SSH
      • Choose Allow public-key authentication only
      • If you don’t have an SSH key yet, read the SSH chapter of the Linux Workstation book.
      • Paste the list of your SSH public keys into the box. (Find them on your workstation by running ssh-add -L or look in ~/.ssh/id_ed25519.pub)
      • The SSH key is important to protect, as this is the only way to remotely SSH into the Raspberry Pi
    • On the Options tab:

      • Unselect Enable telemetry unless you’re into that sort of thing.
  • Click Yes to the question Would you like to apply OS custom settings.

  • Confirm you would like to write to the SD card and wait for it to complete.

  • Once complete, unplug the SD card, put it into the raspberry pi, plug in the ethernet, and power it on.

Find the local IP address of the Pi on your LAN

Once the Pi is powered on, and is connected to your LAN, you need to figure out what its IP address is. There are a number of ways to do that:

  • If your network has configured multicast DNS (mDNS, Avahi, Bonjour), you can find the IP address by the hostname (e.g., pi set in rpi-imager), appended with the domain .local:
[bash]: Run this on your workstation:
ping -c3 pi.local
  • From any Linux computer attached to the same LAN, run arp -a to find and list local connections. Try doing this before and after you turn on the Pi, and then spot the difference.
[bash]: Run this on your workstation:
arp -a
  • If you have a central LAN router + DHCP server, check the console of the router (or DHCP log) for the newly added device.

  • Plug a monitor into the (micro) HDMI port of the Raspberry Pi, and the IP address will be printed to the console when it boots.

Create SSH config on your personal workstation

To connect your personal workstation to your Raspberry Pi, you will need to create an SSH config on your workstation, containing the temporary local IP address of the Raspberry Pi. This config is somewhat temporary, and once DNS is set up later on, it can be replaced with a permanent hostname config.

[bash]: Run this on your workstation:
cat <<EOF >> ~/.ssh/config
Host pi
    User pi
    Hostname X.X.X.X
    ControlMaster auto
    ControlPersist yes
    ControlPath /tmp/ssh-%u-%r@%h:%p
EOF

Replace X.X.X.X with the local IP address assigned to the Raspberry Pi.

Test that the SSH connection works:

[bash]: Run this on your workstation:
ssh pi

The first time you connect, it will ask you to confirm the remote host ssh key, you should simply type yes to trust whatever it says, and it will trust it automatically from now on.

If the connection is successful, you should now be logged into the remote shell console of the Raspberry Pi.

Set up Log2Ram

You can increase the expected lifespan of your SD card by installing log2ram

Run this on the Raspberry Pi
echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bookworm main" | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg  https://azlux.fr/repo.gpg
sudo apt update
sudo apt install log2ram

After installing log2ram, reboot the pi:

Run this on the Raspberry Pi
sudo reboot

After reboot, you will find /var/log/ is mounted as type log2ram:

(stdout)
ryan@pi5:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
...
log2ram         128M   14M  115M  11% /var/log

Format and mount SSD storage

Identify the device name of the NVME SSD:

Run this on the Raspberry Pi
sudo fdisk -l | grep -A5 nvme
(stdout)
Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 990 EVO 1TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

This shows the device is named /dev/nvme0n1.

Partition the device

Run this on the Raspberry Pi
sudo parted /dev/nvme0n1 --script mklabel gpt
sudo parted /dev/nvme0n1 --script mkpart primary ext4 0% 100%

Create filesystem

Run this on the Raspberry Pi
sudo mkfs.ext4 /dev/nvme0n1p1

Mount the filesystem

Run this on the Raspberry Pi
sudo mkdir -p /var/lib/docker

echo "/dev/nvme0n1p1  /var/lib/docker  ext4  defaults,nofail  0  3" | sudo tee -a /etc/fstab

sudo systemctl daemon-reload
sudo mount /var/lib/docker

Verify the mounted storage

Run this on the Raspberry Pi
df -h /var/lib/docker
(stdout)
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1  916G   28K  870G   1% /var/lib/docker

This shows the correct partition /dev/nvme0n1p1 mounted at the correct path /var/lib/docker and showing the correct size of the NVME SSD (916G; it’s always a bit smaller than advertised.)