0

Raspberry Pi Image Prep

Raspberry Pi
Photo by Vishnu Mohanan on Unsplash

Over the years, I’ve set up a *lot* of Raspberry Pi’s, which usually requires I pull out a spare keyboard and monitor to do basic configuration, which gets really annoying.

Inspired by the PiBakery project, I decided to do something about it. Introducing pi-image-prep:

Animation showing the script in use
View on Asciinema for a larger video

This is a simple python script to help prepare a raspberry pi image in a matter of minutes. Currently, it can do the following:

  • Set system locale
  • Set system timezone
  • Set passwords for root and pi users
  • Add authorized keys for root and pi users
  • Enable ssh
  • Set hostname
  • Enable WiFi
  • Install packages by name

In order to do this, it will mount both boot and root partitions within a temporary location on the host computer.

Some changes such as the hostname, SSH, WiFi, and authorized keys are implemented on the image directly. Many others can only be implemented after the first boot. These are handled by placing a temporary script within /etc/cron.d/.

In particular, note there is a very small window in which a Raspberry Pi could be connected to the network with the default pi user password. In practice, this would be extremely difficult to exploit, except in a situation where the password change fails for an unexpected reason.

This script is designed to run only on Linux systems, and requires root (for now), and can be installed via pip:

sudo pip3 install pi-image-prep

Visit the following locations for more information:

ryan

Leave a Reply

Your email address will not be published. Required fields are marked *