Scripts for modifying Raspberry Pi OS images before writing to SD card.
git clone https://github.com/cinderblock/RaspberryPi-Image-Generator.git
cd RaspberryPi-Image-Generator
# Edit `setup.sh`. This gist adds *my* keys!
./new.sh
./new.sh path-to-raspbian.img.zip
- Download a Raspberry Pi OS image and unzip it:
wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest --trust-server-names --timestamping --quiet unzip *-*-*-raspios-buster-lite-armhf.zip
- Download gist files:
wget https://raw.githubusercontent.com/cinderblock/RaspberryPi-Image-Generator/master/{setup,chroot,grow,new}.sh --timestamping --quiet chmod +x {setup,chroot,grow,new}.sh
- Edit
setup.sh
as desired. default adds my keys! - Run scripts.
sudo ./chroot.sh 2020-05-27-raspios-buster-lite-armhf.img [executable] [mount point]
sudo ./grow.sh 2020-05-27-raspios-buster-lite-armhf.img [megabytes]
./new.sh [image-path]
# `setup.sh` is meant to be run on a Raspberry Pi image in a chroot.
sudo ./edit-boot.sh 2020-05-27-raspios-buster-lite-armhf.img
./get-latest.sh
The default setup.sh
script will fail unless you grow
the standard .img
by ~400MB first (as of 2021-07-15).
Runs the setup.sh
(or other) script in a chroot in specified image.
Gives you a chroot in the image to change whatever manually.
./chroot.sh my-raspios.img
If anything goes wrong, the script should cleanup after itself and not leave dangling mounts or loopback devices.
Planned changed: Use systemd-nspawn
instead of chroot
.
Maintains a separate ".bash_history
" that is re-used for all images in a .persist
folder.
This behavior can be overridden by setting LEAVE_HISTORY_ALONE=yes
(any non-zero length string).
The ./chroot.sh
script can also be run in "prepare" mode.
Give it a second argument of an executable to run inside the chrooted environment as root.
For example: ./chroot.sh my-raspios.img some-executable
.
Grow the image (and main partition) by some number of megabytes.
./grow.sh my-raspios.img 400
This only affects the local .img
file. On first boot, Raspbian will automatically grow the parition to fill the full card.
Adding 100MB adds aproximately 10 seconds to the write time when transfering to an SD card.
Does all the steps needed to get a brand new image in a single command. Assumes other scripts are in the same folder.
./new.sh
The steps are:
- Download a new
img
file unzip
it on the fly- Save to a custom img file (overwritting if it exists)
- Grows the image
- Runs
setup.sh
inside thechroot
- Zips the img to save space
This script is meant to be run inside a raspberry pi chroot, as root.
It might run succesfully running directly on a Pi, but that is not a supported use case.
- Adds ssh keys
- Enables sshd, without passwords
- Sets US locale
- Adds WiFi configuration to
/boot
- Adds a new script to change a Pi's hostname with a file
/boot/hostname
- Sets timezone to
America/Los_Angeles
- Updates & Upgrades
- Installs
git
,vim
,screen
, andnode
- Sets the passwd for
pi
- Sets
python3
as the default Python version - Sets
vim
as the default editor
A simplified mounting of the filesystem that only accesses the image's /boot
parition.
Download the official latest version of raspios-lite. Don't overwrite if it already exists. Continue downloading if previously interrupted.
- https://github.com/RPi-Distro/pi-gen - Full featured
.img
generator - https://wiki.debian.org/RaspberryPi/qemu-user-static - Debian instructions to grow/mount/chroot/qemu-run
- https://gist.github.com/htruong/0271d84ae81ee1d301293d126a5ad716 - Instructions to grow and chroot
- https://gist.github.com/htruong/7df502fb60268eeee5bca21ef3e436eb - Script to just mount & chroot (no loopback)
- https://gist.github.com/kmdouglass/38e1383c7e62745f3cf522702c21cb49 - Script: loopback, mount, chroot. No cleanup.