I'm sharing my steps, which helped me to correctly configure Wifi connection profile for headless RPI installation with Bookworm OS. This was tested on Raspberry Pi ZERO.
download and install Raspberry PI Imager (I'm using v1.8.1, on Ubuntu)
in the Imager GUI, do not select RPI device in the first step. Currently, Pi ZERO is not on the supported list in RPI Imager for Bookworm. This means, you will not be able to flash Bookworm OS, when you select filter for PI ZERO device at first step.
select Raspberry PI OS Lite (32bit Bookworm), if you want to do headless installation
choose your microSD card, the target device for flashing
click next and you will be able to set some settings, like system username and password, hostname, wifi credentials, timezone etc. Configure this settings, without Wifi connection settings. This do no work for Bookworm at this time (december 2023)
Once the card is ready, remove microSD card from the computer and connect it again
If you are using for example Ubuntu, the 2 partitions will be auto mounted - bootfs and rootfs . In this steps we expect, that partitions are mounted as /media/martin/bootfs and /media/martin/rootfs. Change it in the following steps according your needs.
we will activate ssh connection
$ sudo touch /media/martin/bootfs/ssh
this step I'm not sure if is needed, give it a try
$ sudo vim /media/martin/rootfs/boot/firmware/firstrun.sh
Write following content: (change do_wifi_country to your country ISO code)
#!/bin/bash
# Stripped back version of the Bookworm firstrun.sh generated by the Raspberry Pi Imager
# also calls raspi-config to set Wifi country, which in turn calls iw on Bookworm
set +e
rfkill unblock wifi
for filename in /var/lib/systemd/rfkill/*:wlan ; do
echo 0 > $filename
done
raspi-config nonint do_wifi_country SK
# edited to remove a bug in rpi-imager that is a hangover from Bullseye
# rm -f /boot/firstrun.sh
rm -f /boot/firmware/firstrun.sh
exit 0
generate PSK for your wifi connection settings:
$ wpa_passphrase networknameSSID yourWifipassword
insert the wifi connection profile
Note: Name the file according your wifi SSID
$ sudo vim /media/martin/rootfs/etc/NetworkManager/system-connections/Matho-Wifi.nmconnection
[connection]
id=Matho-Wifi
uuid=710ace81-db6e-47d9-adca-2835818c7b4b
type=wifi
interface-name=wlan0
autoconnect=true
[wifi]
mode=infrastructure
ssid=Matho-Wifi
[wifi-security]
auth-alg=open
key-mgmt=wpa-psk
psk=YOUR-PSK-HERE
[ipv4]
method=auto
[ipv6]
method=auto
use the following content:
- replace Matho-Wifi with your SSID name
- you can keep the uuid the same. If you change it, the syntax need to meet this length and format
- set psk to the value, you have generated in previous step 10
Apply chmod 600 and chown the profile
$ sudo chmod -R 600 /media/martin/rootfs/etc/NetworkManager/system-connections/Matho-Wifi.nmconnection
$ sudo chown -R root:root /media/martin/rootfs/etc/NetworkManager/system-connections/Matho-Wifi.nmconnection
$ sudo ls -la /media/martin/rootfs/etc/NetworkManager/system-connections/Matho-Wifi.nmconnection
unmount the partitions, for example via Nautilus GUI
insert the microSD card to your RPI ZERO. Give it some time, on my end it took ~6 minutes to be fully booted
connect via ssh with the username and password you have set via RPI Imager tool