setting up a headless raspbian boot image

2020-12-12 ยท 2 min read

    Objective #

    1. Custom SD card boot image for Raspberry Pi Zero W.
    2. RPi should boot headless, connect to configured WiFi, run ssh.

    Better Alternative? #

    I only discovered this after successfully generating my own image, but it seems more convenient: (https://github.com/kenfallon/fix-ssh-on-pi, http://www.lpenz.org/articles/ansiblerpi/index.html). It just mounts a stock Raspbian image and directly modifies the wpa_supplicant.conf and other configuration, instead of building a fresh image from scratch, which takes like 45 minutes...

    Installation #

    $ git clone git@github.com:RPi-Distro/pi-gen.git
    
    • Add pi-gen/config
    IMG_NAME=raspbian_headless
    LOCALE_DEFAULT=en_US.UTF-8
    TIMEZONE_DEFAULT=America/Los_Angeles
    FIRST_USER_NAME=phlip9
    FIRST_USER_PASS=<..>
    WPA_ESSID="<..>"
    WPA_PASSWORD="<..>"
    WPA_COUNTRY=US
    ENABLE_SSH=1
    PUBKEY_ONLY_SSH=1
    PUBKEY_SSH_FIRST_USER="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGrOw2yrUxOYB9ItWrZW4e/AmatL5GH58jTnI/HNoXZz philiphayes9@gmail.com"
    STAGE_LIST="stage0 stage1 stage2"
    

    This config sets up all the locale shit and all, but most importantly, enables wifi on boot and pubkey-only ssh, so we can ssh into the running board without needing to hookup a keyboard / monitor.

    NOTE: The Raspberry Pi Zero W DOES NOT support 5GHz wifi.

    • Build the image
    $ ./build-docker.sh
    

    If the build hangs/fails for some inscrutable reason (happened the first time), just ^CTRL-C and try again with:

    $ CONTINUE=1 ./build-docker.sh
    

    I tried using the apt-cache, but uh... that didn't work...

    • Mount SD card.

    • Download Raspberry Pi Imager (https://www.raspberrypi.org/software/)

    • Open Raspberry Pi Imager

    • Select the "deploy/*.zip" file as the image to write and then image the mounted SD card.

    • Unmount the SD card, put it into the Pi, plug in the Pi, wait ~2 min to boot, and test:

    $ ssh raspberrypi.local
    
    phlip9@raspberrypi:~ $ exit