{"id":350,"date":"2021-04-04T00:05:34","date_gmt":"2021-04-04T00:05:34","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=350"},"modified":"2022-04-11T20:22:59","modified_gmt":"2022-04-11T20:22:59","slug":"setting-up-a-headless-raspberry-pi-zero-w-with-raspberry-pi-os-lite","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/100-days-challenge\/setting-up-a-headless-raspberry-pi-zero-w-with-raspberry-pi-os-lite\/","title":{"rendered":"Setting up a Headless Raspberry Pi Zero W with Raspberry Pi OS Lite"},"content":{"rendered":"\n
Photo by Pimoroni<\/a><\/p>\n\n\n\n Not quite what you think. Running a Raspberry Pi in headless mode means you set it up so that it can boot and run without needing a display, keyboard and mouse.<\/p>\n This guide should work with most Raspberry Pis.<\/p>\n No glitches in the matrix here.<\/p>\n I originally wrote a guide on how I setup a Pi Zero W to run headless back in July 2019 but never got round to polishing and publishing it. This was part of a timelapse project I did while we lived in a rental place (because we were put out of our home due to a fire caused by my neighbour) that had a stunning view.<\/p>\n Alex Ellis wrote this amazing article<\/a> about how he did timelapse photography using a Pi Zero and also wrote the phototimer software<\/a>.<\/p>\n My "server" is in storage at the moment but I will share some of the timelapsing I did back in 2019 as soon as I can.<\/p>\n Pimoroni<\/a> is currently (April 2021) running an easter special and I ordered the Grow Kit<\/a> along with a Raspberri Pi Zero WH<\/a>. I opted for the pre-soldered header one, mainly just because all my electronics and tools are in storage.<\/p>\n So now is an excellent time to revisit setting up a Raspberry Pi Zero (W) to run headless.<\/p>\n Originally back in 2019 I had issues getting the Raspberry Pi Zero W with Raspbian Buster to allow SSH to work on boot. However I came across this tutorial<\/a> that allows you to SSH over USB. While writing this guide I will see if now in 2021 we still face the same issues or not. UPDATE: Didn’t have any of these issues. 🙂<\/p>\n Note:<\/strong> Raspbian has been renamed to Raspberry Pi OS.<\/p>\n Download the latest Raspberry Pi OS Lite image from here<\/a>.<\/p>\n Ensure the SHA256 checksum matches.<\/p>\n Flash the image to a microSD card. I prefer to use balenaEtcher<\/a> (aka Etcher).<\/p>\n Note:<\/strong> balenaEtcher will unmount the SD card and you have to re-insert it to add the required config files.<\/p>\n You do not need to do this if you are setting up a full blown Raspberry Pi (e.g. 3, 4 etc.) and you are only planning on using the ethernet network connection.<\/p>\n Create a file named SSH is disabled by default on the Raspberry Pi OS for good reason of course.<\/p>\n Create a file named Note:<\/strong> The files Safely remove the SD card and insert it into the Rasperry Pi.<\/p>\n Connect the Raspberry Pi to a power supply and notice that the green LED should be blinking and eventually be completely ON.<\/p>\n Wait for about 2 minutes. The Pi Zero takes a while to boot (especially the first time after a new image is flashed onto the SD card).<\/p>\n Identify the IP address of the Raspberry Pi.<\/p>\n You should be able to ping the Pi using the hostname If you can’t find the Pi on your network then it is worth trying nmap.<\/p>\n SSH into the Pi.<\/p>\n Message of Doom! I got this big warning, but in my case it is just because I already had another raspberrypi.local’s SSH fingerprint in my .ssh\/known_hosts file. To fix this I just removed the raspberrypi.local entry from ~\/.ssh\/known_hosts.<\/p>\nHeadless zombies?<\/h2>\n
Deja vu<\/h2>\n
Hardware<\/h2>\n
Software<\/h2>\n
<\/p>\n
$ shasum -a 256 2021-03-04-raspios-buster-armhf-lite.zip\nea92412af99ec145438ddec3c955aa65e72ef88d84f3307cea474da005669d39 2021-03-04-raspios-buster-armhf-lite.zip\n<\/code><\/pre>\n
<\/p>\n
Configure the Pi to use your WiFi network<\/h3>\n
wpa_supplicant.conf<\/code> in the root directory of the SD card volume named
boot<\/code>. On macOS the location would be \/Volumes\/boot.<\/p>\n
ctrl_interface=DIR=\/var\/run\/wpa_supplicant GROUP=netdev\nupdate_config=1\ncountry=GB\n\t\t\nnetwork={\n ssid="NAME OF YOUR WIFI"\n psk="WIFI PASSWORD"\n scan_ssid=1\n}\n<\/code><\/pre>\n
Enable SSH<\/h3>\n
ssh<\/code> (no extension) in the root directory of the SD card volume named
boot<\/code>. This file can be empty.<\/p>\n
$ touch \/Volumes\/boot\/ssh\n<\/code><\/pre>\n
Booting time<\/h2>\n
wpa_supplicant.conf<\/code> and
ssh<\/code> will be deleted after the Pi has booted.<\/p>\n
raspberrypi.local<\/code> if mDNS is working on your network.<\/p>\n
$ ping -c 3 raspberrypi.local\nPING raspberrypi.local (192.168.4.25): 56 data bytes\n64 bytes from 192.168.4.25: icmp_seq=0 ttl=64 time=16.157 ms\n64 bytes from 192.168.4.25: icmp_seq=1 ttl=64 time=6.543 ms\n64 bytes from 192.168.4.25: icmp_seq=2 ttl=64 time=10.337 ms\n<\/code><\/pre>\n
$ nmap -sP 192.168.1.0\/24 | grep raspberrypi\n<\/code><\/pre>\n
Configuring the Raspberry Pi<\/h2>\n
$ ssh pi@raspberrypi.local\n\nThe authenticity of host 'raspberrypi.local (192.168.4.25)' can't be established.\nECDSA key fingerprint is SHA256:R0QP0uLq1ed+TYRi7CkTmrk36DZRcoXjEfesF5aUjWc.\n+---[ECDSA 256]---+\n| .o=o. .+ |\n| .o=+.+o.E|\n| . o.=. *+ |\n| o.= +o...|\n| .SO.+.o.. |\n| . *.+ +. .|\n| . . + = o |\n| . = o . . .|\n| o.o o.. |\n+----[SHA256]-----+\nAre you sure you want to continue connecting (yes\/no\/[fingerprint])?\n\n# Type yes\n<\/code><\/pre>\n
<\/p>\n