You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like /boot/custom.toml is applied on firstboot, but if I have an SD card of an existing image, and move from one location to another and want to update the wifi, can we have /boot/custom.toml apply on every boot?
custom.toml is just an experimental thing in case cloud-init doesn't work out. There are no plans to support it and it will be removed after cloud-init is added.
Outside of the specific implementation I mentioned (with custom.toml), is there generally a way to update the wifi settings after first boot via the sd card with cloud-init?
I should clarify that there's no supported way. There's nothing stopping anybody from implementing their own preferred scheme. Getting basic cloud-init functionality isn't too difficult and google should give plenty of examples. You can also tell systemd to run a specific script on startup by editing cmdline.txt and providing the script in the boot/firmware partition. That approach is how rpi-imager works, if you need a reference for how to do it.
If I was interested in extending rpi-imager's firstrun.sh to create a supported way, anything else I should look out for? Where would be the most appropriate place for discussion and potential pull requests?
(Likely something as simple as cp /boot/*.nmconnection /etc/NetworkManager/system-connections && rm /boot/*.nmconnection)
Just to add a bit of context, so it doesn't sound like I'm just dismissing a potential quality of life improvement for no reason..
When we had a few changes like turning on SSH or configuring wifi, dropping files into the boot partition was a quick and dirty solution. However, it has some drawbacks.
The underlying OS itself can also change. /boot has changed to /boot/firmware, but rpi-imager has /boot hard-coded everywhere. Network Manager doesn't use a static wpa_supplicant.conf file, so the previous approach doesn't work at all.
It's not a standard way of doing things, so it leaves other distros out and requires rpi-imager to try to guess what the right way to do things is.
Users will always want to do something more than whatever functionality we provide. If we keep extending things by dropping files into the boot partition we'll soon have to support 50 other files that can be added.
Good luck making sure all of these options work in all the possible combinations
So should we update rpi-imager any time the OS changes and pray that all users always use the latest version? How would rpi-imager know what the right approach is?
custom.toml addresses only addresses the first point.
As a de-facto industry standard, cloud-init should address everything and will be a better long-term solution overall.
Yeah I’m happy to help with cloud-init if that’s the best way forward, just do not have experience with how it’s integrated with raspberry pi OS right now, so trying to figure out what’s needed to enable per-boot updates support, and how to get cloud-init to read updates from /boot
No help or discussion needed, it's all on the todo list already. It's just a matter of getting around to it. We've just launched the pi5 and the bookworm release, so as you can imagine, things are a bit busy right now.
I can't just merge proposed changes without fully understanding and testing them. This isn't something that can be rushed along.
Sorry for reviving this issue @XECDesign, but I just wanted to understand the situation a bit better. The initial config appears to be quite confusing at the moment.
If you use the official imager tool, it will generate /boot/firstboot.sh which calls /usr/lib/raspberrypi-sys-mods/imager_custom to configure the system, with fallback to doing things manually in case the imager doesn't exist. The imager will use raspi-config for WiFi, while the fallback will just set /etc/wpa_supplicant/wpa_supplicant.conf, which no longer works on Bookworm (12) according to official docs. Should I understand that the fallback is for the old Bullseye (11), and the "correct" way to do it for Bookworm (12) is via the imager? I've been reading some people successfully configure WiFi on Bookworm by just setting wpa_suppplicant.conf, so I am a bit confused here...
And lastly, on the cloudinit vs. custom.toml part. it seems like the second init script /usr/lib/raspberrypi-sys-mods/firstboot checks for a custom.toml and passes it to /usr/lib/raspberrypi-sys-mods/init_config if it exists. This script will then parse it and invoke the imager just like above. I saw no trace of cloudinit support, and no custom.toml is generated with the official imager. Should I understand that the former is not implemented yet, while the latter is just an experiment in case cloudinit support cannot be added?
One year later, what is the blessed way to bulk-produce a set of sdcards with already-booted images, but different wifi-settings, i.e. "how to update wifi after first boot"?
Reacted by julioviegas, n4495, Robert R. and Adam Faryna
I'm missing exactly this option... Only have access to the SD card on an MacBook, I only can access bootfs.
There is no way for me to change the wifi and keep all the data on de card.
debug - remove quiet if it is there; get as much info logged as possible systemd.run=<script to run> - eg. /boot/firmware/something.sh systemd.run_success_action=reboot - reboot back into a normal state. This only works if these systemd.* options are removed from cmdline.txt systemd.run_failure_action=exit - stop the system so that you know it failed. Alternative is none, which MIGHT (untested) leave you in a state where you can debug via ethernet, eg ssh then sudo journalctl -u kernel-command-line.service -n 200 systemd.unit=kernel-command-line.target - changes the default systemd unit of default.target
A possibly not obvious, but important, detail: systemd.run triggers systemd-run-generator, which creates a unit named kernel-command-line.service BUT it doesn't do anything more. You must also add systemd.unit=kernel-command-line.target to override the default of default.target
Remember that the boot partition is mounted at /boot/firmware/ now-a-days, no longer just /boot/
Create your own .nmconnection file. Suggest you modify an existing one. Use your brain - I don't know what yours looks like, but this was what I needed to do:
Put this script on the boot partition, called add_wifi_connection.sh and tweak the TODO parts:
#!/bin/bash
# Append `debug systemd.run=/boot/firmware/add_wifi_connection.sh systemd.run_success_action=reboot systemd.run_failure_action=exit systemd.unit=kernel-command-line.target` to cmdline.txt to run this file
# remove `quiet` option (replaced by debug)
# exit on first error (doesn't seem to work)
set +e
# configure wifi
raspi-config nonint do_wifi_country "AU" # TODO
echo Adding new wifi config
NETWORK_CONNECTION_FILE=wifi.nmconnection # TODO
NETWORK_CONNECTION_PATH=/etc/NetworkManager/system-connections/$NETWORK_CONNECTION_FILE
mv /boot/firmware/$NETWORK_CONNECTION_FILE $NETWORK_CONNECTION_PATH
chmod 600 $NETWORK_CONNECTION_PATH
chown root:root $NETWORK_CONNECTION_PATH
rm /etc/NetworkManager/system-connections/old.nmconnection # TODO, remove old connection file, if needed
# clean up
echo Cleaning up
# remove the "on startup" instructions that launch this script, then reboot. Replacing debug first is important
sed -i 's| debug | quiet |g' /boot/firmware/cmdline.txt
sed -i 's| systemd.*||g' /boot/firmware/cmdline.txt
exit 0
Debug, if needed
use an ethernet cable to ssh into the Pi, if you can
systemctl status kernel-command-line.target, journalctl, dmesg are all useful; sorry, I've turned the Pi off now and don't have the exact commands I was using to hand. Google is your friend.
Activity
jedahan commentedon Oct 24, 2023
This assume
custom.tomlis any (partial? full?) cloud-init file. I haven't gotten to digging that far yet.jedahan commentedon Oct 24, 2023
What would it take to support per-boot updates?
https://cloudinit.readthedocs.io/en/latest/explanation/events.html#apply-network-config-every-boot
XECDesign commentedon Oct 25, 2023
custom.tomlis just an experimental thing in case cloud-init doesn't work out. There are no plans to support it and it will be removed after cloud-init is added.jedahan commentedon Oct 25, 2023
Outside of the specific implementation I mentioned (with custom.toml), is there generally a way to update the wifi settings after first boot via the sd card with cloud-init?
XECDesign commentedon Oct 25, 2023
Not right now, no.
XECDesign commentedon Oct 25, 2023
I should clarify that there's no supported way. There's nothing stopping anybody from implementing their own preferred scheme. Getting basic cloud-init functionality isn't too difficult and google should give plenty of examples. You can also tell systemd to run a specific script on startup by editing cmdline.txt and providing the script in the boot/firmware partition. That approach is how rpi-imager works, if you need a reference for how to do it.
jedahan commentedon Oct 25, 2023
Thanks for the context.
If I was interested in extending rpi-imager's firstrun.sh to create a supported way, anything else I should look out for? Where would be the most appropriate place for discussion and potential pull requests?
(Likely something as simple as
cp /boot/*.nmconnection /etc/NetworkManager/system-connections && rm /boot/*.nmconnection)XECDesign commentedon Oct 25, 2023
Why would that be better than cloud-init?
XECDesign commentedon Oct 25, 2023
Just to add a bit of context, so it doesn't sound like I'm just dismissing a potential quality of life improvement for no reason..
When we had a few changes like turning on SSH or configuring wifi, dropping files into the boot partition was a quick and dirty solution. However, it has some drawbacks.
So should we update rpi-imager any time the OS changes and pray that all users always use the latest version? How would rpi-imager know what the right approach is?
custom.toml addresses only addresses the first point.
As a de-facto industry standard, cloud-init should address everything and will be a better long-term solution overall.
jedahan commentedon Oct 25, 2023
Yeah I’m happy to help with cloud-init if that’s the best way forward, just do not have experience with how it’s integrated with raspberry pi OS right now, so trying to figure out what’s needed to enable per-boot updates support, and how to get cloud-init to read updates from /boot
XECDesign commentedon Oct 25, 2023
No help or discussion needed, it's all on the todo list already. It's just a matter of getting around to it. We've just launched the pi5 and the bookworm release, so as you can imagine, things are a bit busy right now.
I can't just merge proposed changes without fully understanding and testing them. This isn't something that can be rushed along.
ViRb3 commentedon Nov 7, 2023
Sorry for reviving this issue @XECDesign, but I just wanted to understand the situation a bit better. The initial config appears to be quite confusing at the moment.
If you use the official imager tool, it will generate
/boot/firstboot.shwhich calls/usr/lib/raspberrypi-sys-mods/imager_customto configure the system, with fallback to doing things manually in case the imager doesn't exist. The imager will useraspi-configfor WiFi, while the fallback will just set/etc/wpa_supplicant/wpa_supplicant.conf, which no longer works on Bookworm (12) according to official docs. Should I understand that the fallback is for the old Bullseye (11), and the "correct" way to do it for Bookworm (12) is via the imager? I've been reading some people successfully configure WiFi on Bookworm by just settingwpa_suppplicant.conf, so I am a bit confused here...And lastly, on the
cloudinitvs.custom.tomlpart. it seems like the second init script/usr/lib/raspberrypi-sys-mods/firstbootchecks for acustom.tomland passes it to/usr/lib/raspberrypi-sys-mods/init_configif it exists. This script will then parse it and invoke the imager just like above. I saw no trace of cloudinit support, and no custom.toml is generated with the official imager. Should I understand that the former is not implemented yet, while the latter is just an experiment in case cloudinit support cannot be added?Thanks a lot!
XECDesign commentedon Nov 7, 2023
The fallback is for very old images which didn't have
imager_custom.That doesn't have a chance of working on a Raspberry Pi OS Bookworm image, so there's probably some missing context.
Yup, spot on.
omya3qno commentedon Nov 23, 2024
One year later, what is the blessed way to bulk-produce a set of sdcards with already-booted images, but different wifi-settings, i.e. "how to update wifi after first boot"?
matthijs166 commentedon Dec 3, 2024
I'm missing exactly this option... Only have access to the SD card on an MacBook, I only can access bootfs.
There is no way for me to change the wifi and keep all the data on de card.
adamkerz commentedon Feb 17, 2026
I had the same need, moved house, WiFi changed. Spent too long to figure out this fairly simple guide.
You can run a script on startup by changing
cmdline.txton the boot partition. Add to the end:debug- removequietif it is there; get as much info logged as possiblesystemd.run=<script to run>- eg. /boot/firmware/something.shsystemd.run_success_action=reboot- reboot back into a normal state. This only works if thesesystemd.*options are removed from cmdline.txtsystemd.run_failure_action=exit- stop the system so that you know it failed. Alternative isnone, which MIGHT (untested) leave you in a state where you can debug via ethernet, egsshthensudo journalctl -u kernel-command-line.service -n 200systemd.unit=kernel-command-line.target- changes the default systemd unit ofdefault.targetA possibly not obvious, but important, detail:
systemd.runtriggerssystemd-run-generator, which creates a unit namedkernel-command-line.serviceBUT it doesn't do anything more. You must also addsystemd.unit=kernel-command-line.targetto override the default ofdefault.targetRemember that the boot partition is mounted at
/boot/firmware/now-a-days, no longer just/boot/Create your own .nmconnection file. Suggest you modify an existing one. Use your brain - I don't know what yours looks like, but this was what I needed to do:
Put this script on the boot partition, called
add_wifi_connection.shand tweak the TODO parts:Debug, if needed
systemctl status kernel-command-line.target,journalctl,dmesgare all useful; sorry, I've turned the Pi off now and don't have the exact commands I was using to hand. Google is your friend.