Whether you need to install your Raspberry Pi headless,
Or whether you plan to mass-produce SD card for a big IoT project,
In both case, Ubuntu offer a very standard way to pre-configure your image, based on Cloud-init.
Preamble
Flash your SD card with an Ubuntu image: Install Ubuntu Server on a Raspberry Pi 2, 3 or 4. You can use balenaEtcher to install the image on your media in the blink of an eye!
Cloud-init configuration
(Re)mount your SD card volume, then you have acces to the two files we will update: user-data
and network-config
. Cloud-init is a de facto standard for Cloud VM configuration. You can do pretty everything with it.
System configuration
user-data
file contains some examples to help you with your configuration. For more details, you can refer to the Cloud-init documentation; or you can jump directly to examples.
You can find below my own configuration file, which:
- set a hostname
- set a (default) user
pi
with an authorized public ssh key and sudo rights
1 | #cloud-config |
Network configuration
network-config
relies on Netplan format (reference).
The default configuration of the Ubuntu pre-installed image enables network on the ethernet port, using DHCP:
1 | version: 2 |
For example, if you want to enable both ethernet and wifi, update the file accordingly:
1 | version: 2 |