Vanilla Headless Setup

This setup is the basis for getting a Raspberry Pi to boot and then being able to use it remotely through your local network.

Just follow the steps, don’t ask questions, I know what I’m doing.

1.1.        Buy a microSD Card

This step isn’t as trivial as it seems, but it is critical. There are countless types of SD card with different speed standards and for the most part those standards offer no indication of the actual performance of a card.

Disclaimer : I’m not getting paid to recommend any product. Remember, this is my personal website and I’m merely nice enough to let you read it and learn from my experience. In the end, you do you.

After some experimentation, I have found that the SD card which offers the best compromise between speed, reliability and price is the SanDisk High Endurance microSDHC card, which looks like this before you ravage its packaging :

Price is between 15 and 20 € depending on Jeff Bezos’ haircut. The 32 GB is the smallest one in the family, which goes all the way up to 256 GB. I have yet to come up with a project that requires anything bigger than 32 GB, but given enough time I probably will.

It’s designed for continuous operation in CCTV applications, so it should survive well in a Raspberry Pi. None has died on me yet. As for the speeds printed on the packaging, the real-life numbers I’ve observed are actually quite good : 55 MB/s write speed and 66 MB/s read speed. More than enough. Sure, there are faster cards out there, but they’ll be very expensive and well past the point of diminishing returns.

It is a fact, no SD Card is designed to operate as the system drive of a computer. SD cards are designed for recording photos and videos in digital cameras. Using one like it’s a hard drive or an SSD is actually a form of abuse. Keep that in mind, especially if you’re going to run programs that write a lot of data to disk.

Because Raspberry Pi’s are very cheap, it’s tempting to use a cheap SD card as well. Resist that temptation. It’s OK for your SD card to be more expensive than the Raspberry Pi it’s slotted into. It’s not OK to slow down your entire project and/or have it die within a few weeks just to save a dozen Euros.

1.2.        Download and Flash Raspbian

In the spirit of sticking as much as possible to what most people use, download the official Raspberry Pi OS, Raspbian, from its official location : https://www.raspberrypi.org/downloads/raspberry-pi-os/

At the time of writing, the latest version (which you should always try to use) is dated May 27th, 2020. Based on the Raspberry Pi Foundation’s track record of maintaining compatibility across all generations of their products, it’s quite safe to assume that any instructions on my site will work with later versions.

There are three variants of Raspbian to pick from :

  •         “With desktop and recommended software” should be avoided unless you have a specific reason to use it. It’s the kind of distro you’d install on a generic desktop for generic use.
  •         “With desktop” is the best option : all of the features, none of the bloatware.
  •         “Lite” has no desktop. If you are certain you won’t need a graphical user interface for your project, it’s a great choice.

Typically, use the “with desktop” variant while prototyping : this give you a great window into your Pi while you debug your project. Then when your project is done and ready to deploy, and assuming it doesn’t have a GUI, use the “Lite” variant to save resources.

The official site will tell you how to flash Raspbian to your SD card, you don’t need me for that.

Once you’re done flashing, however, do not eject the card from your PC : we need to do a few modifications to it. If you’re using Etcher to flash your SD card, chances are it auto-ejected on completion. Unplug your SD card and plug it back in.

Your SD card should now appear on your computer as a disk named “boot“. This is a FAT32 partition that lets you tweak Raspbian outside of a Raspberry Pi. We’ll be working in that partition next.

1.3.        Setting Up WiFi

If your Raspberry Pi features WiFi, or if you plan on using a WiFi dongle, Raspbian needs to know which network(s) it should try to connect to, and of course it should know the security keys for those networks.

To that end, create a file named “wpa_supplicant.conf” at the root of the SD card’s “boot” partition. This file’s contents must look like this :

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=FR

network={
ssid="Network_1_Name"
psk="Network_1_Key"
key_mgmt=WPA-PSK
priority=2
}

network={
ssid=" Network_2_Name "
psk=" Network_2_Key "
key_mgmt=WPA-PSK
priority=1
}

If necessary, change the country code to match your current location : it dictates which WiFi frequencies will be used. Using the wrong frequency can result in lower performance but also legal issues.

The file needs to contain at least one “network” block but may contain several. The “priority” values are optional. Needless to say, replace the SSID’s and keys with the actual ones for your own network(s).

With this file present, the Raspberry Pi will try to connect to WiFi as soon as it’s done booting.

Pro tip : keep a copy of your “wpa_supplicant.conf” file on your computer so it can be easily copied to new SD cards.

1.4.        Enabling SSH on Boot

In order to use a headless system you need to be able to access it remotely. The simplest way to do that is through SSH (Secure Shell). SSH lets you log into a computer remotely over networks to send commands exactly as if you were using a physical console connected to that computer. It’s a very powerful tool and, as you might imagine, the bread and butter of most hackers… which is why SSH is disabled by default on all versions of Raspbian.

On a normal install of Raspbian, where you’re using a physical console, you could enable SSH by using the “raspi-config” utility in a terminal window… but we have a chicken-and-egg situation here : there’s no console attached to our Pi because we want to access it over the network. SSH is disabled so you can’t log in and use “raspi-config” to enable SSH. What a predicament !

This is solved by creating an empty file named “ssh” (no extension) at the root of the SD card’s “boot” partition.

A word of caution : a freshly-flashed Raspbian SD card has a default user account with a default password that everybody knows. Enabling SSH on a Raspberry Pi connected to the internet without having changed its default credentials exposes it to getting hijacked. Ideally, do not connect your Pi to the internet until after you’ve changed its password. That’s why SSH is disabled by default.

1.5.        First Boot

With all previous steps completed, you’re now the lucky owner of an operational Raspberry Pi SD card. Time to use it.

Eject it from your PC and insert it in your Raspberry Pi. Goes without saying, but hey, we all get distracted once in a while.

Because we’re operating headless, you only need to connect a network cable to the Pi, going to your Ethernet switch. If you’re adept as configuring your PC’s network settings you may even connect your Pi’s Ethernet directly to that of your PC.

If you’d rather use WiFi, then you obviously don’t need a network cable.

Finally, apply power to your Pi. For most people, that means plugging a USB charger into the Pi’s power input socket.

Deprived of a display, you won’t be able to know if or when your Pi has booted. Sure, there are some LED’s on the Pi but that’s not exactly helpful since none of those is a dedicated “I’m ready” LED. But there are tell-tale signs :

If you’ve configured WiFi, the Pi will attempt to connect to your network as soon as it’s ready. When the Pi appears in the list of devices connected to your access point, it’s done booting.

If you’re using Ethernet, the Pi will request an IP address from your LAN using DHCP. Keep an eye on your LAN’s list of DHCP clients : as soon as the Pi appears, it’s done booting.

The Pi’s default network name is raspberrypi. Note down its assigned IP address, it might come in handy.

If the Pi never shows up, review all previous steps. Maybe you typed something wrong. Maybe your SD card died immediately for some reason. Maybe your Pi itself is dead.

1.6.        First Login

Once you see the Pi on your network, SSH into it. On a Windows PC you can use the Command Prompt application.

Use the following command :

ssh pi@raspberrypi

If you’ve already been connecting to Pi’s with this method, it’s possible Windows will not be able to resolve the name “raspberrypi” because it’ll be associated with a different board. Just replace “raspberrypi” with the Pi’s IP address.

Whichever method you use, here’s what it’ll look like :

The default password is raspberry. Once you enter it, you get this :

Congratulations : you are now in command of your Raspberry Pi.

Notice the security warning. I told you so. Let’s fix this right away.

1.7.        Change the Default Credentials

The very first command you should type at this point is :

sudo raspi-config

This will launch the Raspbian configuration tool, in terminal mode :

Do change the password for the default “pi” user. The change will be effective immediately, you don’t need to reboot. Which is nice, because there are other things we need to setup in “raspi-config”.

1.8.        Expand the File System

Raspbian images assume your SD card has a capacity of 8 GB. If yours is larger than that, you need to expand the file system to use your whole SD card. Let’s not leave money on the table.

Under Advanced Options select Expand Filesystem, then reboot the Pi.

1.9.        Miscellaneous Settings

The “raspi-config” tool has various entries that may be worth your time. In fact you may end-up using it on a regular basis.

Network Options lets you change the network name of your Raspberry Pi. This is very useful if you have more than one Pi on the same network. It’s also a way to name your system according to your application. Remember : that name is stored on the SD card. If you’re using several SD cards for different projects you can give each of them their own name.

Boot Options lets you decide whether the Pi boots straight to desktop, or to the command line. Booting to the command line means you’re not running a GUI. This saves resources and may be perfect for an embedded application. But you won’t be able to use VNC to connect to the Pi’s desktop remotely :

Well duh !

The “auto-login” options are nice if you love living dangerously for the sake of saving a few keystrokes here and there.

Interfacing Options is my favorite entry. Note that by default, the camera interface, SPI, I2C, 1-Wire and remote GPIO access are all disabled. Later on, you may need to come back here to enable any interface your project requires. The UART on the GPIO connector, however, is enabled by default and can also be used to login. This is a headless option for people who also don’t have (or don’t want) a local network.

1.10.   Starting VNC Server on Boot

SSH will only get you a command line. If you have need of a GUI, and have selected a Raspbian “with desktop”, you need to use VNC to gain remote access to the Pi’s desktop.

The VNC protocol is open, you can install any client that you like on your PC.

Raspbian (with desktop) includes a VNC server, but it is not enabled by default, for the same reason that SSH isn’t enabled by default.

Under “raspi-config”, go into Interfacing Options. It’s all self-explanatory. Notice our good friend SSH is there. Choose the VNC entry and enable it.

You can now fire up your VNC client and connect to the Pi. You will see something like this :

You’re in !

And you’re done ! This concludes the Vanilla Headless Setup.