1. Create the Script File
  • Inserted the SD card into your Windows PC.
  • Opened the boot partition folder inside VS Code.
  • Created a file named exactly firstrun.sh.
2. Configure for Linux (Crucial)
  • Changed the line endings in VS Code from CRLF to LF so the Pi could read the file.
3. Add the Configuration Code
  • Pasted a bash script into the file to inject your network details into NetworkManager (the network tool used by newer Raspberry Pi OS versions).
  • Entered your specific Wi-Fi name and password.
4. Boot the Pi & Found the IP
  • Put the card into the Pi 5 and powered it on.
  • Used the Windows Command Prompt to run ping raspberrypi.local to locate its new network IP address.

firstrun.sh

#!/bin/bash

# Create the NetworkManager connection file
cat << ‘EOF’ > /etc/NetworkManager/system-connections/preconfigured.nmconnection
[connection]
id=Preconfigured-Wifi
type=wifi
autoconnect=true

[wifi]
mode=infrastructure
ssid=YOUR_WIFI_NAME

[wifi-security]
auth-alg=open
key-mgmt=wpa-psk
psk=YOUR_WIFI_PASSWORD

[ipv4]
method=auto

[ipv6]
method=auto
EOF

# Set required strict security permissions for NetworkManager
chmod 600 /etc/NetworkManager/system-connections/preconfigured.nmconnection
chown root:root /etc/NetworkManager/system-connections/preconfigured.nmconnection

# Optional: Enable SSH so you can access it headlessly
systemctl enable ssh
systemctl start ssh