bake customized raspberry pi sdcard images automatically
A shell script to bake raspberry pi OS disk images
(2x speed, most of it is output from apt on the pi, use pause if it’s too fast)
If you work a lot with raspberry pi’s, you find yourself repeatedly
downloading OS images, customize settings like changing /config.txt,
set the password, setup network, install packages, copy files etc.
With rpi-cookstrap you can create & use building blocks to build your
final image by just running bootstrap.sh. When booting or
logging in, the image can setup everything by itself non-interactively
(default) or interactively.
$ RPI_BOOTSTRAP_PLUGINS=raspbian,password RPI_PASSWORD_PW=secret ./bootstrap.sh
is a minimal example and will download the latest raspbian lite and set the password of the pi user to “secret”.
The wifi+upgrade example will create a working raspbian-lite image without any personal customizations.
Wifi will be configured (with the preset SSID and PSK) and a full upgrade will be perfomed:
The following will:
$ git clone https://github.com/heeplr/rpi-cookstrap
$ cd rpi-cookstrap/examples/wifi+upgrade
$ ./bootstrap.sh
$ dd if=.bootstrap-work/raspbian-lite.img of=/dev/sdX conv=fsync status=progress
Now you got a fresh and fully upgraded image. But the wifi is setup with wrong
credentials, since examples/wifi+upgrade/bootstrap.cfg doesn’t
contain your wifi’s name and password (hopefully).
You can add rpi-cookstrap into your raspberry project simply by using symbolic links.
e.g. with a git submodule:
$ cd my-raspberry-project-image
$ git submodule add https://github.com/heeplr/rpi-cookstrap bootstrap
$ ln -s bootstrap/bootstrap.sh bootstrap.sh
$ ln -s bootstrap/bootstrap-plugins bootstrap-plugins
Then create bootstrap bootstrap.cfg and bootstrap-dist in your project directory (s. below).
You can create a customized config that will always override a project’s bootstrap.cfg:
Create ~/.bootstrap.cfg and modify according to your needs, for example (comment out to disable):
# setup WIFI
RPI_BOOTSTRAP_PLUGINS+=( "wifi" )
RPI_WIFI_SSID="yourwifiname"
RPI_WIFI_PSK="your-secret-password"
# authorize SSH public key
RPI_BOOTSTRAP_PLUGINS+=( "ssh" )
RPI_SSH_AUTHORIZE=( "ssh-ed25519 AAAA... you@host" )
# set random 24 char PASSWORD for pi user
RPI_BOOTSTRAP_PLUGINS+=( "password" )
RPI_PASSWORD_PW=( "$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c24;echo;)" )
Now if you run ./bootstrap.sh
for any project, the image is created with
your personal settings.
Try running ./bootstrap.sh -h
to list commandline arguments and./bootstrap.sh -p
to list plugins.
Further documentation can be found in the wiki.
The wiki has a list of available plugins.
There’s also more documentation on the general plugin concept.
see examples/ for “complete” examples and plugin’s documentation for plugin specific examples.
Everything should be straight forward & verbose. You can always rm -rf .bootstrap-work
to clean up and start over.
Feel free to file an issue or even submit a pull request.
Contributions welcome!