Skip to content

Instantly share code, notes, and snippets.

@chumaumenze
Last active July 23, 2024 21:18
Show Gist options
  • Save chumaumenze/f7be572f1af27cb9260c2b6852c62b37 to your computer and use it in GitHub Desktop.
Save chumaumenze/f7be572f1af27cb9260c2b6852c62b37 to your computer and use it in GitHub Desktop.
WiFi Access Point Setup on Headless Raspberry Pi
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
wifis:
renderer: networkd
wlan0:
access-points:
"<MY_WIFI_SSID>":
password: "<MY_WIFI_PASSWORD>"
dhcp4: true
optional: true

WiFi Access Point Setup on Headless Raspberry Pi

This guide does not require a booted device. Create or modify the files on the SD card.

Tested on

Device: Raspberry Pi 4B OS: Ubuntu 22.04.4 LTS (Jammy Jellyfish)"

Partitions

There are two partitions: system-boot and writable.

  • system-boot contains the boot files and it is also a cloud-init datasource (NoCloud).
  • writable is the OS root.

Approach 1: Modify Netplan Config

Modify the file /etc/netplan/50-cloud-init.yaml. This file is in the writable partition. The changes should look similar to the file 50-cloud-init.yaml in this gist.

Substitute <MY_WIFI_SSID> and <MY_WIFI_PASSWORD> with your Wifi name and password.

This method doest not persist after a reboot because cloud-init re-provisions the system overwriting the config. It is helpful for one-time boot.

Approach 2: Modify cloud-init NoCloud Datasource (**Recommended)

Similar to the steps in Approach 1, modify /network-config file. This file is present in the system-boot partition. Substitute the template variables <MY_WIFI_SSID> and <MY_WIFI_PASSWORD> with your Wifi name and password.

Ultimately, append the contents of user-data to /user-data file located in the boot partition. Eject and insert the SD card to your Raspberry Pi and connect it to a power source.

version: 2
wifis:
renderer: networkd
wlan0:
dhcp4: true
optional: true
access-points:
"<MY_WIFI_SSID>":
password: "<MY_WIFI_PASSWORD>"
# Append the following lines. DO NOT REPLACE the entire file.
power_state:
mode: reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment