• Stars
    star
    158
  • Rank 237,131 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightly modified Raspbian-light image supporting first boot customization.

raspberian-firstboot

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.

Why would I use this image?

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.

Quick Start

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.

Quick Start A

  1. Download the latest image from the Releases tab. Note we currenlty only support the raspbian-lite image.
  2. Mount the /boot volume OF THE IMAGE YOU JUST DOWNLOADED. This usually happens automatically if you "open" the image on Windows, MacOS, or Linux.
  3. NOTE: references below to /mnt will be /Volumes on macos and under "My Computer" on Windows.
  4. Create a /mnt/boot/firstboot.sh script with your custom contents examples here.
  5. Optionally add additional custom configuration files or small binaries to /mnt/boot (the /boot partiton is small - keep your total additions under ~160MB).
  6. Remember, you can also add a /mnt/boot/wpa_supplicant.conf file for wifi configuration.
  7. Unmount the /boot volume: umount /mnt on linux, diskutil unmount /Volumes/boot on macos, right-click for Windows.
  8. 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.
  9. Boot your Pi... /boot/firstboot.sh will be executed and renamed to /boot/firstboot.sh.done.

Quick Start B

  1. Download the latest image from the Releases tab. Note we currenlty only support the raspbian-lite image.
  2. 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.
  3. Mount the /boot volume OF YOUR THE SD CARD YOU JUST FLASHED. This usually happens automatically if you "open" the SD card volume on Windows, MacOS, or Linux.
  4. NOTE: references below to /mnt will be /Volumes on macos and under "My Computer" on Windows.
  5. Create a /mnt/boot/firstboot.sh script with your custom contents examples here.
  6. Optionally add additional custom configuration files or small binaries to /mnt/boot (the /boot partiton is small - keep your total additions under ~160MB).
  7. Remember, you can also add a /mnt/boot/wpa_supplicant.conf file for wifi configuration.
  8. Unmount the /boot volume: umount /mnt on linux, diskutil unmount /Volumes/boot on macos, right-click for Windows.
  9. Boot your Pi... /boot/firstboot.sh will be executed and renamed to /boot/firstboot.sh.done.

What changes were made to the standard Raspbian-lite image?

  1. firstboot.service is installed in /lib/systemd/system/firstboot.service
  2. firstboot.service is enabled: cd /etc/systemd/system/multi-user.target.wants && ln -s /lib/systemd/system/firstboot.service .
  3. Nothing else!

How to reproduce this image yourself

Note: these are the steps used to produce the images in the Releases section of this repo. Once you have created a generic image with these steps, you can proceed to customize it by following the Quick Start.

  1. This requires modifying the second partition of the Raspbian image, which requires Linux for ext4 support.
  2. Source image is obtained from the official Raspberry Pi download page.
  3. Be sure to verify the SHA hash!
  4. Mount the second partition of the source image - the mount command will require an --offset flag, as described here.
    • Note: the mount_offset_tool helps calculate the --offset on linux.
    • Example usage (thanks @tgelite):
$ cd mount_offset_tool/
$ go run main.go /media/share/2021-01-11-raspios-buster-armhf-lite.img
/media/share/2021-01-11-raspios-buster-armhf-lite.img1 mount command:
  mount -v -o offset=4194304,loop /media/share/2021-01-11-raspios-buster-armhf-lite.img /mnt
/media/share/2021-01-11-raspios-buster-armhf-lite.img2 mount command:
  mount -v -o offset=272629760,loop /media/share/2021-01-11-raspios-buster-armhf-lite.img /mnt
 * Alternatively, you can mount it with `guestmount` (thanks @bastien-roucaries):
$ guestmount -v -a 2021-01-11-raspios-buster-armhf-lite-firstboot.img -m /dev/sda2 -m /dev/sda1:/boot /mnt
later, unmount with: $ guestunmount /mnt
  1. Install firstboot.service in /mnt/lib/systemd/system/firstboot.service
  2. Enable firstboot.service for systemd: cd /mnt/etc/systemd/system/multi-user.target.wants && ln -s /lib/systemd/system/firstboot.service .
  3. Unmount the second partition of the source image.
  4. Carefully test & validate the image before distributing!

More Repositories

1

glauth

LDAP authentication server for developers
63
star
2

notion-offliner

A CLI tool that you can use create regular offline backups of your Notion.so Pages.
Go
15
star
3

aws-lambda-forwarder-for-ses

Accept incoming email with AWS SES - use this AWS Lambda function to forward it somewhere else
JavaScript
14
star
4

nightwatchjs_exporter

nightwatchjs_exporter runs https://nightwatchjs.org/ tests periodically and exports the results for https://prometheus.io/
Go
12
star
5

darknetd

darknetd: run darknet as a service, with a REST API
Go
10
star
6

edge-netdog

edge-netdog performs emergency remediation (such as a reboot) for edge devices when network connectivity has failed.
Go
10
star
7

nanostill

limited clone of raspistill for Jetson Nano: provides a simple CLI tool to capture images on the Jetson Nano.
Go
8
star
8

check_asa_l2lvpn

Nagios plugin for monitoring site-to-site VPNs on a Cisco ASA
Perl
6
star
9

sms_twilio

My work on the sms_twilio module
PHP
4
star
10

job

Drupal-based management of external jobs, ala: Jenkins
PHP
3
star
11

freshpow

FreshPow tracks public ski resort lift and trail status, alerting you about changes.
Go
3
star
12

neddns

Authoritative DNS server backed by S3
Go
3
star
13

check_aws_rds

Nagios plugin for monitoring Amazon AWS's Relational Database Service (RDS)
PHP
2
star
14

etcfw

manage iptables with etcd
Go
2
star
15

drupal_nagios

My work on the Drupal 7 nagios module
PHP
2
star
16

do_route53_backup

A nagios/icinga "check" to backup an AWS Route53 zone
Python
1
star
17

drupal7_chartbeat

PHP
1
star
18

gopro_timelapse_panhead

Custom time-lapse gopro pan controller made with 3d printed parts and an arduino controller
Arduino
1
star
19

job_dashboard

PHP
1
star
20

sms_twilio_d6

Ongoing patches to Drupal 6 version of sms_twilio
PHP
1
star
21

shoutbox_rules

Drupal 6 module to add Rules support to Shoutbox
1
star
22

smsblast

Drupal module to send SMS blasts to bulk numbers.
1
star
23

atsms

Drupal Rules, Token, and Content Profile integration for the sms_framework module.
1
star
24

check_buildbot_lastbuild

Nagios plugin to monitor Buildbot builder status
Python
1
star
25

nmcclain.github.com

Ned's Github Page
1
star
26

check_cname

Nagios plugin specifically for checking CNAMEs
PHP
1
star
27

formbricks-helm

Helm chart for deploying Formbricks on Kubernetes
Smarty
1
star
28

smsframework

My work porting the smsframework module to D7
PHP
1
star
29

firesheep_drupal_example

Sample Firesheep plugin against non-SSL-protected Drupal.
JavaScript
1
star