As you probably know, I’m a fan of the Raspberry Pi and Pi Zero Internet of Things (IoT) devices. Well, I recently had a moment where I felt like a total newbie. I go through a lot of installations of Raspbian Linux and during every installation I go through a network configuration process. This process of configuration is either by Ethernet or UART connection. Well, it turns out there is an easier way.
It is actually possible to apply a network configuration through the FAT mountable partition saving the hassle of having to connect over UART or Ethernet first. We’re going to see how this is possible.
In case you haven’t already seen the previous articles I wrote on the subject, you might benefit from learning how to configure a Raspberry Pi as a headless unit as well as using the GPIO pins for a UART connection.
So let’s assume you’ve just installed a fresh copy of Raspbian to a micro SD card. As it turns out, in 2016 Raspbian started looking for a particular file in the boot directory of the mountable FAT partition. More information on this set of updates can be found on the Raspberry Pi blog.
Mount your micro SD card to a Windows, Mac, or Linux host computer and open the boot directory. What you’ll want to do is create a file called wpa_supplicant.conf at the root of this directory. This file should contain something like the following:
You’ll want to replace the SSID and the WPA with that of your actual wireless network. What is happening is Raspbian will replace the Linux file equivalent file found at /etc/wpa_supplicant/wpa_supplicant.conf with the file that you’ve provided. This happens when you try to boot the Raspberry Pi.
After the Raspberry Pi or Pi Zero has finished booting, you can connect to it over WiFi. If you’re using a Pi Zero, but aren’t sure how to get wireless internet, check out a few options on the subject.
There are many ways to take control of your Raspberry Pi or Pi Zero device. While you could use UART or Ethernet to configure the wireless access point information, it is no longer necessary. Instead you can just create a simple file after flashing the micro SD card with your network information. This can save a lot of time, specially if you’re constantly installing Raspbian like I am.