A lightly modified Raspbian-light image with first boot customization.
Our goal is easy boot time customization of the standard Raspberry Pi OS - just edit a simple bash script.
Download the image from the Releases tab.
The standard Raspbian-lite image allows you to customize the wireless settings and enable SSHd before flashing it to an SD card. Unfortunately, there is no way to further customize the OS during the first boot, nothing like cloud-init or userdata. Without a display and keyboard, complex "headless" deployments are impossible.
With this image, you can run a custom script on first boot and:
- Set a unique hostname. (simple example)
- Configure HDMI, audio, and network settings. (example)
- Install apt software packages. (example)
- Setup an automatic reverse SSH tunnel for remote management. (example)
- Bootstrap a configuration management tool like Ansible/Chef/Puppet to prevent configuration drift.
- Deploy your IoT fleet with custom UUIDs and configurations.
There are two ways to use the image, pick one:
-
A. Download the image, customize the image with firstboot scripts, then flash the customized image to your SD card.
-
B. Download the image, flash the image to your SD card, then customize the SD card with firstboot scripts.
- Download the latest image from the Releases tab. Note we currenlty only support the raspbian-lite image.
- Mount the
/bootvolume OF THE IMAGE YOU JUST DOWNLOADED. This usually happens automatically if you "open" the image on Windows, MacOS, or Linux. - NOTE: references below to /mnt will be /Volumes on macos and under "My Computer" on Windows.
- Create a
/mnt/boot/firstboot.shscript with your custom contents examples here. - Optionally add additional custom configuration files or small binaries to /mnt/boot (the /boot partiton is small - keep your total additions under ~160MB).
- Remember, you can also add a /mnt/boot/wpa_supplicant.conf file for wifi configuration.
- Unmount the
/bootvolume:umount /mnton linux,diskutil unmount /Volumes/booton macos, right-click for Windows. - Flash the customized image to your SD card. We recommend using Balena Etcher for writing images on all platforms. Folks have run into issues with the official
Raspberry Pi Imager. - Boot your Pi...
/boot/firstboot.shwill be executed and renamed to/boot/firstboot.sh.done.
- Download the latest image from the Releases tab. Note we currenlty only support the raspbian-lite image.
- Flash the downloaded image to your SD card. We recommend using Balena Etcher for writing images on all platforms. Folks have run into issues with the official
Raspberry Pi Imager. - Mount the
/bootvolume OF YOUR THE SD CARD YOU JUST FLASHED. This usually happens automatically if you "open" the SD card volume on Windows, MacOS, or Linux. - NOTE: references below to /mnt will be /Volumes on macos and under "My Computer" on Windows.
- Create a
/mnt/boot/firstboot.shscript with your custom contents examples here. - Optionally add additional custom configuration files or small binaries to /mnt/boot (the /boot partiton is small - keep your total additions under ~160MB).
- Remember, you can also add a /mnt/boot/wpa_supplicant.conf file for wifi configuration.
- Unmount the
/bootvolume:umount /mnton linux,diskutil unmount /Volumes/booton macos, right-click for Windows. - Boot your Pi...
/boot/firstboot.shwill be executed and renamed to/boot/firstboot.sh.done.
- firstboot.service is installed in
/lib/systemd/system/firstboot.service - firstboot.service is enabled:
cd /etc/systemd/system/multi-user.target.wants && ln -s /lib/systemd/system/firstboot.service . - Nothing else!
- This requires modifying the second partition of the Raspbian image, which requires Linux for ext4 support.
- Source image is obtained from the official Raspberry Pi download page.
- Be sure to verify the SHA hash!
- Mount the second partition of the source image - the
mountcommand will require an--offsetflag, as described here.- Note: the mount_offset_tool helps calculate the
--offseton linux.
- Note: the mount_offset_tool helps calculate the
- Install firstboot.service in
/mnt/lib/systemd/system/firstboot.service - Enable firstboot.service for systemd:
cd /mnt/etc/systemd/system/multi-user.target.wants && ln -s /lib/systemd/system/firstboot.service . - Unmount the second partition of the source image.
- Carefully test & validate the image before distributing!