Posts: 84
Joined: Thu Apr 04, 2019 8:14 pm

Script for creating RPI images (similar to pi-gen)

Sat Jul 13, 2019 3:18 pm

Hi All,

Using ideas from pi-gen and the Hypriot project, I have composed some scripts to enable the building of a working Raspberry Pi Image.

You can change settings such as the OS variant you want to build within the file.

To modify what packages are installed edit the file.

By default the script will build a Buster image with SSH root access enabled.

You will note that the Dockerfile is using an i386 image. This is deliberate as it is a work around for a current qemu bug affecting 64bit hosts. Do not change it or you will get strange issues in the resulting image, in particular with anything relying on SSL.

Default Credentials:

Username: root
Password: raspberry

(Please set your own password within the script)


Nothing groundbreaking, but it uses the newly introducing caching feature within debootstrap and the excellent apt-cacher. Both apt and debootstrap are configured to store cached files on the host PC in osbuilder/cache. So subsequent builds don’t need to download already downloaded packages again which saves a lot of time when experimenting.

Clone The Repo

You can get hold of the scripts by executing the following command on your host PC.

Code: Select all

git clone
Host Requirements

I used Ubuntu 18.04 server running in VMware for my docker host. You will need to install and ensure docker is working before continuing. In addition, the injection of the sysroot into the img file uses GuestFish. I couldn’t get it to work properly under docker (if someone can help with that I would be grateful) so this part of the process is handled outside of docker by the host OS, so in addition to a working docker setup you also need to install the following package…

Code: Select all

apt-get install libguestfs-tools

After cloning the repo, execute within the clone folder:

Code: Select all

Once the docker image is built, you can execute the Pi image build by simply running:

Code: Select all

Once finished, all going well you should end up with an image rpi-raw.img in the output folder ready for writing to an SD card.

Return to “Advanced users”