carlosperate / rpi-os-custom-image

Raspberry Pi OS images with autologin and ssh enabled
MIT License
8 stars 4 forks source link

Raspberry Pi OS customised images

Minimally customised Raspberry Pi OS images.

The main reason these have been created is to be able to run them in automated CI testing with https://github.com/carlosperate/docker-qemu-rpi-os. But they can also be used like normal OS images in a physical Raspberry Pi, or any other emulation method.

Currently the following images are being created:

These customised images have been generated from different versions of Raspbian/Raspberry Pi OS and all can be found and downloaded from the GH Releases page.

How does it work

It uses a method very similar to this article (thank you Ben!): https://www.hardill.me.uk/wordpress/2020/02/21/building-custom-raspberry-pi-sd-card-images/

In this case all is encapsulated in a Python script:

How to run this project

Docker

First build the Docker image with all the dependencies installed.

docker build -t "rpi-os-imager" .

Then to run these scripts, as they themselves run Docker, need Docker to be launched with configuration flags to use Docker Out of Docker (DooD).

From the root directory of this repository:

docker run --rm -v $(pwd):$(pwd) -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock rpi-os-imager python run_all.py

Local

Requirements:

Install the Python dependencies (much better in a virtual environment):

pip install -r requirements.txt

Run the Python script:

python run_all.py

Change default options

Ideally the options should be selectable via command line arguments, but until that is implemented the defaults can be changed in the source code global variables.

OS customisation options

You can run the customise_os.py Python script directly if you'd like to modify an existing Raspberry Pi OS image (e.g., if you've downloaded a specific one).

The path to the .img file needs to be provided as a command line argument:

python customise_os.py path/to/my.img

The options in the customise_os.py header can be changed to select what to modify:

###############################################################################
# Configuration data start

# If this script is run on its own, select here what features to update
AUTOLOGIN = True
SSH = True
EXPAND_FS = False

# Configuration data end
###############################################################################

These options do not affect run_all.py runs, only customise_os.py.

Download OS image options

You can run the download_os.py Python script directly if you'd like to download an unzip a different Raspberry Pi OS image.

The URL should be passed as a command line argument:

python download_os.py https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-08-24/2020-08-20-raspios-buster-armhf-lite.zip

Executing the script without arguments will download the default image:

python download_os.py 

The global variables at the top of download_os.py can be edited to change the default:

###############################################################################
# Configuration data start

# URL of the Raspberry Pi OS Lite zip file to download and check
# Find options in https://downloads.raspberrypi.org/raspios_lite_armhf/images/
OS_IMAGE_ZIP = "https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-08-24/2020-08-20-raspios-buster-armhf-lite.zip"
OS_IMAGE_SHA = "https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-08-24/2020-08-20-raspios-buster-armhf-lite.zip.sha256"

# Configuration data end
###############################################################################

Changing these URLs will affect run_all.py as well.