3 minutes
RPi Headless Config
Initial Raspberry Pi Config, Headless
We’re at the very beginning of a golden age of single board computers, and the Raspberry Pi is currently leading the charge. From the Raspberry Pi Zero (and Zero W), to the Raspberry Pi 4 (with up to 4GB of RAM), you have choices in both size and power. Best of all, they’re all pretty affordable: from $10 to about $60.
I’ve bought several (read: many) at this point, and typically use them as some kind of server. Servers generally don’t need displays, keyboards, or much more than power and network connectivity. I’m generally just too lazy to hook one up to all of this anyway. To avoid this, you can set up a Raspberry Pi completely headless.
Since I’ve done this more than once, I’m noting this as much for myself, as to share for others. Let’s get to it.
Get Raspbian on an SD Card
Download the latest Raspbian distribution and use dd or Balena Etcher to get it on an SD card. If you use Etcher, it will dismount the card after writing the image, Remount the SD card you just created. Once you do, look for the /boot partition. (On a Mac, this will appear as /Volumes/boot, or just look for it in a Finder window sidebar.)
Enable serial console
One way to manage a RaspberryPi is via a serial console. You’ll need a serial cable, a terminal program (screen
on macOS and Linux work just fine), and an edit to a config file. If you want to enable this prior to any setup, you’ll need to do the following:
Edit /boot/config.txt
Add the line: enable_uart=1
Enable ssh
More commonly, you’ll want to access your Pi over ssh, and that requires ssh being enabled. To do this prior to first boot, do the following:
In /boot create an empty file named “ssh”
cd /Volumes/boot touch ssh
Enable WiFi
ssh is not a great solution if there’s no network connectivity, and generally, that’s over WiFi. You can configure WiFi prior to first boot, so it’s ready for further config. To do so:
In /boot, create the file wpa_supplicant.conf
Add the following lines:
country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev network={ ssid="YOUR_SSID" psk="SSID_PASSWORD" key_mgmt=WPA-PSK }
Change the country
setting to your country code.
key_mgmt
can also be “NONE” (no quotes) if you’re connecting to an access point with no password.
You can also create multiple network=
stanzas, and each will be tried in order, which is useful for connecting to different networks depending on your conditions.
Fin
That should be everything you need to set up a RaspberryPi running Raspbian completely headless on first boot.
438 Words
2019-12-31 00:00