Building Raspberry Pi images with Packer

I recently had to build a couple of Raspberry Pi images, I decided to try and set it up using Packer so the process was documented, version controlled and automatic.

I searched around for a bit, and found the project named packer-builder-arm by mkaczanowski.

Installing and running #

The project is distributed through a Docker image, so it’s quite easy to get started:

$ docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build mkaczanowski/packer-builder-arm:latest build install.json

The examples for the Packer code are a bit outdated inside the project, but for the newest version of Raspberry Pi OS (based on Debian Bookworm) this worked for me:

{
  "variables": {},
  "builders": [{
    "type": "arm",
    "file_urls" : ["https://downloads.raspberrypi.com/raspios_armhf/images/raspios_armhf-2023-10-10/2023-10-10-raspios-bookworm-armhf.img.xz"],
    "file_checksum_url" : "https://downloads.raspberrypi.com/raspios_armhf/images/raspios_armhf-2023-10-10/2023-10-10-raspios-bookworm-armhf.img.xz.sha256",
    "file_checksum_type": "sha256",
    "file_target_extension": "xz",
    "file_unarchive_cmd": ["xz", "--decompress", "$ARCHIVE_PATH"],
    "image_build_method": "resize",
    "image_path": "outputted-image.img",
    "image_size": "6G",
    "image_type": "dos",
    "image_partitions": [
      {
        "name": "boot",
        "type": "c",
        "start_sector": "8192",
        "filesystem": "vfat",
        "size": "256M",
        "mountpoint": "/boot"
      },
      {
        "name": "root",
        "type": "83",
        "start_sector": "532480",
        "filesystem": "ext4",
        "size": "0",
        "mountpoint": "/"
      }
    ],
    "image_chroot_env": ["PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"],
    "qemu_binary_source_path": "/usr/bin/qemu-arm-static",
    "qemu_binary_destination_path": "/usr/bin/qemu-arm-static"
  }],

Now I can build images with Packer, happy hacking! :)

 
0
Kudos
 
0
Kudos

Now read this

Enforcing host parameter usage for URLs in e-mail templates with Hamlcop

At Billetto we have multiple domains for our ticketing website depending on the market, as an example our danish organisation lives at billetto.dk and our swedish counterpart lives at billetto.se. All of our organisations shares the same... Continue →