This approach uses the rpi-imager software created by the Raspberry Pi Foundation. This allows configuring and writing the OS image all in one step. No text file editing required. This process can do all the same setup except for the UART enabling.
Information on installing and running rpi-imager can be found here:
Once you've installed rpi-imager and launched it, you should see the initial screen. Configuration settings are accessed via the Advanced Options by clicking on the gear icon:
The Advanced Options should look like this:
The top drop down lets you choose between applying the settings just once (for this session only) or every time you burn an image (to always use). The later can be useful so you don't have to type in the same information each time you burn an image.
And then you can just scroll through and enable any of the options you want and configure as appropriate. Be sure to scroll, there are more items than can fit in the small rpi-imager app window.
Set Hostname
This is the name the Raspberry Pi will show up as on your network. If nothing is done here, the default is raspberrypi.
Enable SSH
Not only can you enable SSH, you can set a new password to use as well. By default, SSH is disabled.
Set Username and Password
As of the bullseye release of the Raspberry Pi OS, the default account with username pi and password raspberry has been removed. This blog post has more information.
To create a user account, fill in the username and password. This can be whatever you want, including the old default pi:raspberry.
Configure WiFi
This sets up the Raspberry Pi to be able to connect to your local WiFi network. Type in your WiFi network name (SSID) and password. Be careful not to have any typos.
Don't forget to also set the country code.
Burn OS Image
Once done with the settings, click the SAVE button to get back to the main rpi-imager screen. Then, pick an OS image by clicking the CHOOSE OS button.
Most of these options will download the selected image from the internet before burning. If you want to instead use a specific OS image you've already downloaded, then scroll to the very last option - Use Custom.
Click CHOOSE STORAGE to pick the SD card to use. Be careful to select the correct device here.
Then click WRITE to start writing the image to the SD card. You'll be prompted to confirm before starting.
Click YES and away it goes. It will take several minutes to complete. Longer if it also has to download the image first.
Once done, you get this pop up, and...well...you're done.
How It Works
This process seems to rely entirely on creating a custom script called firstrun.sh in the /boot partition of the SD card. It does not create a wpa_supplicant.conf or ssh file. Nor does it alter config.txt.
Here are the contents of the firstrun.sh file created after the screen shots above and burning the OS image.
NOTE: The SD card has not been booted in a Pi yet.
#!/bin/bash set +e CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"` echo wintermute >/etc/hostname sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\twintermute/g" /etc/hosts FIRSTUSER=`getent passwd 1000 | cut -d: -f1` FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6` echo "$FIRSTUSER:"'$5$.JCul6mnDH$/TjzLsqN9iHpAhva/OlrCoANkWNU7nn6dfQplh3.WBC' | chpasswd -e systemctl enable ssh cat >/etc/wpa_supplicant/wpa_supplicant.conf <<'WPAEOF' country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev ap_scan=1 update_config=1 network={ ssid="mynetwork" psk=69e49214ef4e7e23d0ece077c2faf3c73f7522ad52a26b33527fa78d9033ff35 } WPAEOF chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf rfkill unblock wifi for filename in /var/lib/systemd/rfkill/*:wlan ; do echo 0 > $filename done rm -f /etc/xdg/autostart/piwiz.desktop rm -f /etc/localtime echo "America/Los_Angeles" >/etc/timezone dpkg-reconfigure -f noninteractive tzdata cat >/etc/default/keyboard <<'KBEOF' XKBMODEL="pc105" XKBLAYOUT="us" XKBVARIANT="" XKBOPTIONS="" KBEOF dpkg-reconfigure -f noninteractive keyboard-configuration rm -f /boot/firstrun.sh sed -i 's| systemd.run.*||g' /boot/cmdline.txt exit 0
This is just a bash script that will get copied over and run (with elevated privileges!) the first time the Pi is booted (run). It's sort of a rubber ducky hacker style approach.
Page last edited March 08, 2024
Text editor powered by tinymce.