Headless configuration of raspberry pi prior to boot

It’s a PITA to need keyboard, mouse and monitor just to initially configure a Raspberry PI which will be running headless.

https://www.tomshardware.com/reviews/raspberry-pi-headless-setup-how-to,6028.html explains the problem and largely solves it, but only for those running


which is weird. But there it is. Or am I missing something?

It would be really nice to have a Fedora app which, after we download a PI image, we could set its IP address and hostname (for a static IP network), a username and passphrase, wifi parameters, encrypted OS, and probably a couple other items before the SD card ever goes into the PI.

Is there such a Fedora project in the works?


Have a look if you can apply this tutorial to the available images we do have.

I agree it would be nice if there was a way to drop some sort of config file onto the SD card and on first boot it configures your system based on it. In the meantime, I just use an Ansible playbook to configure my Pi once it’s booted.

1 Like

Thanks much! That’s a pretty good doc. From there I should be able to figure out other configurations-- wifi, hostname, and others.

1 Like

It sounds like that works well for you. Great. I was looking for a way to configure enough of the PI’s SD card while it’s still in my PC’s card slot to be able to then boot the PI headless, ssh into it, and do the rest of the config that con be done headlessly. I’d like to get away from having a separate keyboard, mouse, monitor, and ethernet all standing in the corner just to set up a Pi.

sudo dnf install rpi-imager

and you got the program that is used in the article you are mentioning

1 Like

Hey, that’s right. The Raspberry Pi people need to update their webpage.

After downloading and installing it, I tried it out, and looked at a few youtubes, and found that rpi-imager handles most of what I was wanting to do, but not for all distros, so I’m guessing not Fedora. I still want to set up static IP networking, but the app seems to have no way to do that, no matter which distro you put on the Pi.

This shows that it is a bad idea to change to fix IP-Address from the beginning. In the end it is easier just to change from DHCP to fix IP than to get a duplicated IP and no access to the internet as you want to access headless.

With ansible this might be easy to achieve.

Thanks for the advice, but I’ve got lots of experience using static networks, even a hundred nodes. The current network will be much smaller, so keeping track of addresses isn’t any concern.

How about a login script to change it with nmcli?
Sorry, I not checked the tool yet you want to use.

The method used in the Medium.com article seems to be the most promising.

I just did this, and found out how it worked for me. Specifically the wifi part.

On fedora there are 3 partitions defined. One is vfat for the efi partition, and on F38 it seems about 600 MB size.

In that partition one needs to create a text file wpa-supplicant.txt with the following content.
(I copied it over from another sd card with octopi loaded – on that card it is named octopi-wpa-supplicant.txt)

# Use this file to configure your wifi connection(s).
# Just uncomment the lines prefixed with a single # of the configuration
# that matches your wifi setup and fill in SSID and passphrase.
# You can configure multiple wifi connections by adding more 'network'
# blocks.
# See https://linux.die.net/man/5/wpa_supplicant.conf
# (or 'man -s 5 wpa_supplicant.conf') for advanced options going beyond
# the examples provided below (e.g. various WPA Enterprise setups).
# Do not use Wordpad for editing this file, it will mangle it and your
# configuration won't work. Use a proper text editor instead.
# Recommended: Notepad++, VSCode, Atom, SublimeText.
# If you use Textedit to edit this file make sure to use "plain text format"
# and "disable smart quotes" in "Textedit > Preferences", otherwise Textedit
# will use incompatible characters and your network configuration won't
# work!

## WPA/WPA2 secured
#  ssid="put SSID here"
#  psk="put password here"

## Open/unsecured
#  ssid="put SSID here"
#  key_mgmt=NONE

## WEP "secured"
## WEP can be cracked within minutes. If your network is still relying on this
## encryption scheme you should seriously consider to update your network ASAP.
#  ssid="put SSID here"
#  key_mgmt=NONE
#  wep_key0="put password here"
#  wep_tx_keyidx=0

# Uncomment the country your Pi is in to activate Wifi in RaspberryPi 3 B+ and above
# For full list see: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
#country=GB # United Kingdom
#country=CA # Canada
#country=DE # Germany
#country=FR # France
country=US # United States

### You should not have to change the lines below #####################

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

One needs to edit the file and modify the 4 lines with a single # under ## WPA/WPA2 secured
Remove the # to uncomment the lines then enter the proper SSID and password for the AP. Once that is done then when fedora is booted it should automatically connect to the wifi AP. – It did for me.

Additionally, since fedora disables ssh by default, one needs to mount the raw image under fedora as is described here (using kpartx to create a loop device and the aarch64 environment) then use a chroot environment to enable sshd before moving the card to the Pi. That link does not address the wifi issue but further searching and having additional OSes for the pi allowed me to identify the fix.

Once the sd card is configured as needed then simply creating an image from the card using dd would provide a means of duplicating the config for other systems.

alternatively, if one has fully configured the .raw image as per the linked instructions then that can be the base for configuring other systems.