0

It seems like with the latest Bookworm the support for wpa_supplicant.conf is removed without providing us with an alternative. Consider you already have Bookworm OS installed on the SD card. And you have to connect to a different Wi-Fi without a monitor I don't think there's any way at all.

All the existing solutions on the internet talk about the obsolete wpa_supplicant.conf method or they want to go with the imager route where they reinstall the whole OS for just Wi-Fi SSID configuration change. Both of these don't make sense now.

Please suggest any reasonable solutions.

PS:

  1. Please don't suggest using a monitor or Ethernet cable.
  2. I have access to the SD card and am able to read/edit files.
Greenonline
  • 2,969
  • 5
  • 27
  • 38
router
  • 109
  • 3

3 Answers3

3

The short answer:

In your terminal:

$ sudo nmcli connection add type wifi con-name <new_connection_name> ifname wlan0 ssid <new_SSID>

When you're "in range" of your new wifi connection:

$ nmcli connection up <new_connection_name>

A longer, rambling, opinionated answer:

Sadly, we are now stuck with network manager (nm) as our default; wpa_supplicant.conf is gone (subsumed by nm). This is due to decisions made by "The Raspberries" just before the release of bookworm. FWIW, network manager came from the same place that systemd came from - that may help you understand the mindset at work behind the design.


EDIT:

If you're interested in alternatives to nm, there are some listed in the Debian wiki. I'll comment on two of them here:

  • systemd-networkd: There is an excellent group of Q&A here on RPi SE related to systemd-networkd (mostly fm @Ingo), but they are somewhat dated now - mostly 'buster'-vintage. I do not know if they are still applicable or not.
  • dhcpcd: Still available through apt, but dhcpcd5 (the default just prior to 'bookworm') is now labeled as a "dummy transitional package". There's a forum post on using it that seems fairly thorough. However, recall that RPi didn't follow the upstream version of dhcpcd for many years - they were "stuck" in version 5 (for reasons that are unclear) until 'bookworm' arrived.

Also note that none of the alternatives are supported with "official" documentation. That leaves you more or less "on your own" as far as configuring them for use on your RPi!

This edit was added to address a comment from our Moderator - who insists there are alternatives. I'll leave it to him to show us if they are practical alternatives or not.


Personally, I don't like network manager (nm); I think it's arcane and awkward to use, but I still use it. I'll continue hoping that something better will come along, but until that happens it seems that we'll have to learn enough nm to get by.

With that in mind, you might try the following:

List the nm "connections" on your system:

$ nmcli connection show
... on my system, here's what I see:
NAME                UUID                                  TYPE      DEVICE
preconfigured       4564bc40-6546-494e-847b-7efdfe918d60  wifi      wlan0
lo                  d9a67218-2f52-4d6c-a2d3-87ee0f60d161  loopback  lo
Wired connection 1  8282b463-5561-3ae6-a00d-34c201b3a8d1  ethernet  --

You've ruled out ethernet, and loopback isn't any help here, so we're left with preconfigured as the actual (bizarre) connection name. (No doubt this name was chosen by some really intelligent people.)

We know that preconfigured uses wifi (DEVICE=wlan0), so our approach will be to simply duplicate preconfigured to add another connection for a second wifi network.

As it turns out, the actual configuration file(s) are located in the folder /etc/NetworkManager/system-connections. We can view it:

$ ls -lA /etc/NetworkManager/system-connections

-rw------- 1 root root 262 May 27 2024 preconfigured.nmconnection

$ sudo cat preconfigured.nmconnection

[connection] id=preconfigured uuid=4564bc40-6546-494e-847b-7efdfe918d60 type=wifi timestamp=1716798784

[wifi] mode=infrastructure ssid=Mesh01

[wifi-security] key-mgmt=wpa-psk psk=nofyfb

[ipv4] method=auto

[ipv6] addr-gen-mode=default method=auto

[proxy]

Now we know what a properly-configured nm wifi connection looks like! If you're interested, you can view all the gory details of the connection as follows:

$ nmcli connection show "preconfigured"

Which provides about 175 lines of brain-numbing crap! But some of it may prove useful, so at least know it's there.

So - on with creating a new nm connection for a 2nd wifi network

It might be possible to simply make a copy of preconfigured.nmconnection file, generate a UUID and substitute the values for another wifi connection. But instead, let's ask nm to do that for us:

$ sudo nmcli connection add type wifi con-name "preconfigured2" ifname wlan0 ssid "Mesh01"

Note that I decided to call this connection "preconfigured2", and used the same SSID. You could change either or both of these to suit your needs/desires.

Afterwards, we now find a new file has been added in folder /etc/NetworkManager/system-connections. Note that it is essentially the same as the preconfigured connection without the password/authentication section:

$ ls -lA /etc/NetworkManager/system-connections

-rw------- 1 root root 215 Jan 4 09:20 preconfigured2-aa3e2db6-d295-4c28-a8e5-51ea4d48e042.nmconnection -rw------- 1 root root 262 May 27 2024 preconfigured.nmconnection

$ sudo cat preconfigured2-aa3e2db6-d295-4c28-a8e5-51ea4d48e042.nmconnection

[connection] id=preconfigured2 uuid=aa3e2db6-d295-4c28-a8e5-51ea4d48e042 type=wifi interface-name=wlan0

[wifi] mode=infrastructure ssid=Mesh01

[ipv4] method=auto

[ipv6] addr-gen-mode=default method=auto

[proxy]

Let's use nmcli to show our connections again:

$ nmcli connection show
NAME                UUID                                  TYPE      DEVICE
preconfigured       4564bc40-6546-494e-847b-7efdfe918d60  wifi      wlan0
lo                  37ad01d0-d685-4949-81f4-0e532ded0721  loopback  lo
preconfigured2      aa3e2db6-d295-4c28-a8e5-51ea4d48e042  wifi      --
Wired connection 1  8282b463-5561-3ae6-a00d-34c201b3a8d1  ethernet  --

And so we now have a new nm connection that we can use to connect to a new/different wifi network. To make the connection:

$ nmcli connection up preconfigured2
Seamus
  • 23,558
  • 5
  • 42
  • 83
2

With a bit of prep work, this can be achieved relatively simply

In the boot partition:

Edit cmdline.txt and add the following at the end of the line

systemd.run=/boot/firmware/addwlan.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target

This info is in a comment of the code, for easy future reference

Create a file in the boot partition, addwlan.sh, contents at the end of the answer, and fill in the details of the new connection

  • NAME: this will be the name of the .nmconnection file created and its ID - note that UUID is generated
  • SSID: the SSID you want to connect to
  • PRIORITY: use negative for higher priority - FYI: default for wifi connections is zero
  • HIDDEN: set this to true if the SSID is hidden
  • PASS: leave blank for an open AP

Put the SD card back in the pi and reboot. Note, there will be a second reboot once the config is written, so be patient.

Tested to work on Pi 4 running latest Raspberry Pi Bookworm

The code is heavily based on set_wlan function in /usr/lib/raspberrypi-sys-mods/imager_custom with added functionality to set a name(ID) for the connection

#!/bin/bash

add to end of /boot/firmware/cmdline.txt

systemd.run=/boot/firmware/addwlan.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target

this will be removed once the connection is created

Based on set_wlan function in /usr/lib/raspberrypi-sys-mods/imager_custom

With added functionality to set a name(ID) for the connection

---- configure connection

NAME=connectionName SSID=SSID PASS=password HIDDEN=false PRIORITY=0

---- end configure connection

CONNFILE=/etc/NetworkManager/system-connections/${NAME}.nmconnection UUID=$(uuid -v4)

cat <<- EOF >${CONNFILE} [connection] id=${NAME} uuid=${UUID} type=wifi autoconnect-priority=${PRIORITY} [wifi] mode=infrastructure ssid=${SSID} hidden=${HIDDEN} [ipv4] method=auto [ipv6] addr-gen-mode=default method=auto [proxy] EOF if [ ! -z "${PASS}" ]; then cat <<- EOF >>${CONNFILE} [wifi-security] key-mgmt=wpa-psk psk=${PASS} EOF fi chmod 600 ${CONNFILE}

rm -f /boot/firmware/addwlan.sh

sed -i 's| systemd.run.*||g' /boot/firmware/cmdline.txt exit 0

Once this runs, the cmdline.txt has the added options removed

Bravo
  • 290
  • 3
  • 9
0

Don't saw off the branch while you are sitting on it.
It IS possible to manually edit/create config files although not normally recommended.

It is probably easier to copy your existing then edit the copy.

See How do I set up networking on Raspberry Pi OS - Bookworm - particularly:-
Each WiFi network has a separate config file in /etc/NetworkManager/system-connections/

If you had created an Access Point (with lower priority than your normal WiFi) you could login without access to a network.


NOTE You can continue to use dhcpcd if you wish but networkmanager is the default.
wpa_supplicant.conf has NOT been removed; wpa_supplicant is still used but configured via /etc/NetworkManager/system-connections/

Milliways
  • 62,573
  • 32
  • 113
  • 225