Part
1
  |  
First Principles
  |  
Chapter
3

First Boot

Flashing an SD card takes five minutes — but the twenty minutes after that determine whether your Pi is a reliable machine or a time bomb waiting for a corrupted filesystem.
Reading Time
9
mins
BACK TO RASPBERRY PI MASTERCLASS

The mistake is treating first boot like an afterthought. Someone reads a quick-start guide, downloads the first OS image they find, flashes it to whatever SD card is lying around, plugs in power, and celebrates when a desktop appears. Three days later, the card corrupts because it was a cheap Class 4 from a gas station. Or SSH doesn't work because they forgot to enable it. Or the filesystem is running at 50% capacity because they never expanded it. Or they can't find the Pi on the network because they skipped the hostname step and there are now four devices on the subnet all called "raspberrypi."

The twenty minutes after flashing the SD card determine whether your Pi is a reliable machine or a time bomb waiting for a corrupted filesystem.

I've seen this pattern where a developer flashes a card, skips configuration, and spends three hours debugging a network issue that would have been solved by setting the hostname and enabling SSH in the Imager before the first boot. The order of operations matters. Do it right the first time, and you never think about it again. Do it wrong, and you'll reflash this card more times than you write actual code.

This chapter is the zero-failure sequence from bare SD card to a working, updated, SSH-ready system. Follow it exactly. Skip nothing.

Choosing the Right SD Card

The SD card is the Pi's hard drive, and it's the single most common point of failure. Not the board. Not the power supply. The card. Every corrupted filesystem, every mysterious crash, every boot failure I've diagnosed traces back to a bad card or a card that was never meant for continuous operation.

Framework · The First-Boot Checklist · FBC

A zero-failure sequence for every new Pi: right card, right OS, pre-configure SSH and WiFi in the Imager, first boot headless, update packages, set hostname, enable interfaces, expand filesystem. Skip a step, pay for it later.

Here's what to buy:

  • Brand: SanDisk, Samsung, or Kingston. Not the unbranded card from a market stall. Not the promotional card that came with a camera five years ago. A known brand with a warranty.
  • Speed class: A2 (Application Performance Class 2) or, at minimum, Class 10 / U1. The A2 rating matters because it specifies random read/write performance, not just sequential speed. The Pi's operating system does thousands of small random reads and writes per minute. A card rated only for sequential speed will bottleneck everything.
  • Size: 32 GB for headless projects, 64 GB if you're running the desktop environment or storing camera footage. Don't go below 16 GB — the OS alone takes 4-5 GB, and you want room for packages, logs, and data. Don't go above 128 GB — if you need that much storage, use a USB drive or NVMe instead. The SD card should hold the OS and your application. Nothing more.
  • Endurance: For projects that write data continuously (logging, camera capture), look for "High Endurance" variants. SanDisk MAX ENDURANCE and Samsung PRO Endurance are designed for continuous write workloads. A standard card will degrade under 24/7 write cycles within a year.
The card you already have

That SD card from your old phone, your camera, or the junk drawer? Don't use it. Used cards have unknown wear levels, potential bad sectors, and no guarantee of the speed class they were originally rated for. A new 32 GB A2 card costs $8. The time you'll waste debugging a flaky card costs more.

Key takeaway

The SD card is the Pi's single most common failure point. Buy a name-brand A2-rated card in the 32-64 GB range, and treat it as a consumable — replace it annually for any Pi running in production.

Flashing with Raspberry Pi Imager

Forget manual formatting. Forget dd commands. Forget balenaEtcher. The official Raspberry Pi Imager does everything right, and — critically — it lets you pre-configure the system before first boot, which eliminates an entire class of setup headaches.

Download it from https://www.raspberrypi.com/software/ for macOS, Windows, or Linux. Then:

  1. Insert your SD card into your computer.
  2. Open Raspberry Pi Imager and click "Choose Device." Select your Pi model (Pi 4 or Pi 5).
  3. Choose OS. Two options matter:
    • Raspberry Pi OS Lite (64-bit) — no desktop, no GUI, just a terminal. This is what I use for every project. A headless Pi with no desktop environment boots faster, uses less RAM, has fewer running processes, and has a smaller attack surface. If you need a graphical interface, you'll VNC into it from your laptop — the Pi doesn't need a local desktop for that.
    • Raspberry Pi OS with Desktop (64-bit) — full LXDE desktop environment. Use this only if you're building a kiosk, a digital sign, or something where the Pi itself drives a display. For development and deployment, Lite is the right choice.
  4. Choose Storage. Select your SD card. Double-check — the Imager will overwrite everything on the selected drive.
  5. Click the gear icon (or "Edit Settings") — this is the critical step most guides skip.

The gear icon in the Imager is the critical step most guides skip — it's the difference between a Pi that works on first boot and one that needs a monitor and keyboard to configure.

Pre-Configuration: Do It Now, Not Later

The Imager's settings panel lets you configure the system before the SD card is even written. This means the Pi will boot fully configured, with no need for a monitor or keyboard. Fill in every field:

Set hostname: Change raspberrypi to something descriptive. If you're building a temperature monitor for the lab, call it lab-temp-monitor. If you're building a camera system for the workshop, call it workshop-cam. You'll SSH into this name, so make it memorable and unique on your network. Use lowercase letters, numbers, and hyphens only.

lab-temp-monitor.local

Enable SSH: Check the box. Choose "Use password authentication" for now — you'll switch to key-based authentication in the next chapter for security. Set a strong password. Do not leave the default password as "raspberry." Seriously. Port scanners find default-password Pis within hours on a public network.

Set username and password: Create a username (I use pi by convention, but any name works) and a strong password. Write this down. You'll need it in ten minutes.

Configure wireless LAN: Enter your WiFi network name (SSID) and password. Set the country code (required for WiFi regulatory compliance — the Pi won't connect to 5 GHz channels without the correct country code). If your Pi will use Ethernet, you can skip this — but I configure WiFi anyway as a fallback.

Set locale settings: Set your timezone and keyboard layout. The timezone matters for log timestamps. Getting it wrong means every timestamp in your sensor data is offset by some number of hours, and you'll discover this at the worst possible moment.

Now click "Write." The Imager downloads the OS, writes it to the card, and verifies the write. Wait for verification to complete — don't eject early.

Pre-configuration under the hood

What the Imager actually does is write a file called firstrun.sh to the boot partition along with your settings. On first boot, the Pi executes this script, configures WiFi, enables SSH, sets the hostname, creates your user, and then deletes the script. This is why pre-configuration only works on the first boot — if you've already booted the card, you'll need to either reflash or configure manually.

First Boot Sequence

With the SD card flashed and pre-configured:

  1. Insert the SD card into the Pi's microSD slot on the underside of the board.
  2. Connect Ethernet if available — it's faster and more reliable than WiFi for the initial setup.
  3. Connect the USB-C power supply. The Pi has no power button. It boots the moment power is applied.
  4. Wait two minutes. The first boot takes longer than subsequent boots because the Pi runs the pre-configuration script, resizes the filesystem, generates SSH keys, and initializes the system. The activity LED (green, next to the power LED) will flicker intensely during this process.
  5. Find your Pi on the network. From your computer's terminal:
# Option 1: mDNS (works on macOS and most Linux distributions)
ping lab-temp-monitor.local

# Option 2: If mDNS isn't working, scan your local network
# macOS/Linux — find all devices on your subnet
nmap -sn 192.168.1.0/24

# Option 3: Check your router's admin page for connected devices
# Look for the hostname you set in the Imager
  1. SSH in:
ssh pi@lab-temp-monitor.local

Accept the host key fingerprint when prompted. Enter the password you set in the Imager. If you see a command prompt, the first boot is complete.

✕ Without pre-configuration
  • Need monitor and keyboard for first boot
  • Default hostname collides with other Pis
  • SSH disabled — must enable manually
  • WiFi not configured — must plug in Ethernet
  • Default password — security liability
✓ With Imager pre-configuration
  • Boot headless — no monitor needed
  • Unique hostname — findable on the network
  • SSH enabled immediately
  • WiFi configured before first power-on
  • Custom password — secure from the start

Updating the System

The image on the SD card is a snapshot from whenever it was last built. It's outdated the moment you flash it. Update immediately:

# Update the package list
sudo apt update

# Upgrade all installed packages
sudo apt full-upgrade -y

# Clean up cached packages to free SD card space
sudo apt autoremove -y
sudo apt clean

# Update the Pi's firmware (Pi 4 and Pi 5)
sudo rpi-update
rpi-update is optional

The rpi-update command installs bleeding-edge firmware that hasn't been through the full testing cycle. For most users, the firmware that ships with apt full-upgrade is sufficient and more stable. Only run rpi-update if you need a specific firmware fix or hardware feature that hasn't reached the stable channel yet.

This process takes five to fifteen minutes depending on your internet connection and how stale the image is. Don't interrupt it. A partial upgrade can leave the system in an inconsistent state that's harder to fix than reflashing.

After the upgrade, reboot:

sudo reboot

Wait thirty seconds, then SSH back in to confirm the system comes back cleanly.

Enabling Interfaces

The Pi ships with most hardware interfaces disabled by default. You need to enable the ones your project requires. Use raspi-config:

sudo raspi-config

Navigate to Interface Options and enable what you need:

  • Camera (Legacy) — enable if using the CSI camera module with raspistill/raspivid commands. Note: on newer OS versions, the camera uses libcamera instead and doesn't need this toggle.
  • SSH — should already be enabled from the Imager, but verify.
  • SPI — enable for SPI devices (displays, some sensors, ADCs like the MCP3008). Exposes /dev/spidev0.0 and /dev/spidev0.1.
  • I2C — enable for I2C devices (most sensors, OLED displays, motor controllers). Exposes /dev/i2c-1. This is the interface you'll use most.
  • Serial Port — enable for UART communication (GPS modules, some sensors, serial-to-USB adapters). Disable the serial console if you're using the serial port for your own devices.
  • 1-Wire — enable for 1-Wire devices (DS18B20 temperature sensors). Uses GPIO 4 by default.
# After enabling interfaces, verify they're active
ls /dev/i2c*        # should show /dev/i2c-1
ls /dev/spidev*     # should show spidev0.0 and spidev0.1
Key takeaway

Enable I2C and SPI now, even if you're not sure you'll need them. Enabling them costs nothing, and having to re-enable them later means another reboot and another SSH reconnection cycle.

Post-Boot Hardening

Three quick changes that prevent future headaches:

# 1. Set a static hostname (if you want to change what you set in the Imager)
sudo hostnamectl set-hostname lab-temp-monitor

# 2. Set the timezone (if the Imager setting didn't take)
sudo timedatectl set-timezone America/New_York
timedatectl    # verify

# 3. Install essential tools you'll need in every project
sudo apt install -y python3-pip python3-venv git htop tmux

The htop install is a personal requirement. The Pi has limited RAM, and you need to see what's consuming it. tmux lets you run persistent terminal sessions that survive SSH disconnections — you'll use this constantly once you start running long sensor-collection scripts.

Verify Everything Works

Before moving on, confirm each subsystem:

# System info
cat /etc/os-release         # should show Raspberry Pi OS (Bookworm or newer)
uname -a                    # should show aarch64 for 64-bit
free -h                     # check available RAM
df -h                       # check disk space — filesystem should use the full SD card

# Network
hostname -I                 # should show your IP address
ping -c 3 google.com        # should succeed — confirms internet access

# Python
python3 --version           # should be 3.11 or newer
pip3 --version              # should work without errors

# GPIO readiness (don't run GPIO commands yet — just verify the module exists)
python3 -c "import RPi.GPIO; print('GPIO module available')"

If any of these fail, fix them now. Don't carry a broken foundation into the next chapter.

What to Do Monday Morning

Flash your SD card using Raspberry Pi Imager with full pre-configuration

Set a unique hostname, enable SSH, configure WiFi, set your timezone. Use Raspberry Pi OS Lite (64-bit). Wait for verification to complete before ejecting the card.

Boot the Pi headless and SSH in within two minutes

No monitor. No keyboard. Insert the card, apply power, wait two minutes, and SSH in using the hostname you configured. If this doesn't work, your pre-configuration has an error — reflash and try again. Do not plug in a monitor to fix it. Headless-first is a discipline, not a convenience.

Run the full update and reboot cycle

sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean && sudo reboot. SSH back in after the reboot. Confirm the system comes back cleanly.

Enable I2C, SPI, and the camera interface in raspi-config

Even if you don't need them today. Verify with ls /dev/i2c* and ls /dev/spidev*. These interfaces are prerequisites for nearly every project in this book.

Install the essential toolkit: python3-pip, python3-venv, git, htop, tmux

Run sudo apt install -y python3-pip python3-venv git htop tmux. Then open htop and look at your Pi's resource usage. Know your baseline before you start loading it with applications.

The trap isn't that first boot is hard. The trap is that it seems trivially easy — flash and go — and that false simplicity creates a system with default passwords, a collision-prone hostname, disabled interfaces, outdated packages, and a filesystem that's one power glitch away from corruption. Spend the twenty minutes. Follow the checklist. Build on a foundation that doesn't crack the moment you put weight on it.

Build on a foundation that doesn't crack the moment you put weight on it.