I use sbuild and btrfs for my debian packaging, it’s quick, solid and was a big improvement on my git-pbuilder setup. I think that’s due to the snapshotting and disposable nature of live chroots. This has been my bible for this, and is a regular reference for me when things break.

At the moment, I’m working on a project which will require a repository covering multiple architectures, distribuitions and targets. I’m looking at ubuntu i386, x84_64, maybe armhf/aarch64, raspberry pi armhf & aarch64 and some debian targets too eventually.

Long term, I’d love a CI pipeline in which I commit a released package and it can build across the universe, but at the moment I’ll settle for building for Raspberry Pi OS stable.

Raspbian chroot

This git gist was my starter for setting up an sbuilder chroot, but I made a few tweaks. CHROOT_DIR= is on my btrfs disk

VERSION= is stable

This has left me with the below. I think I can do better, and maybe take in DIR, VERSION and ARCH as command line arguments, but that also seems overkill for something taht changes rarely.

#!/bin/bash

CHROOT_DIR=/media/bigdisk/chroot/raspbian-stable-armhf-sbuild
MIRROR=http://archive.raspbian.org/raspbian
VERSION=stable - (more to follow on why)
CHROOT_ARCH=armhf

sudo mkdir -p $CHROOT_DIR

sudo debootstrap --foreign --no-check-gpg --include=fakeroot,build-essential \
    --arch=${CHROOT_ARCH} ${VERSION} ${CHROOT_DIR} ${MIRROR}
sudo cp /usr/bin/qemu-arm-static ${CHROOT_DIR}/usr/bin/
sudo chroot ${CHROOT_DIR} ./debootstrap/debootstrap --second-stage
sudo sbuild-createchroot --arch=${CHROOT_ARCH} --foreign --setup-only \
    ${VERSION} ${CHROOT_DIR} ${MIRROR}

Package preparation

To indicate that I want to target raspbian, at the moment I am releasing the package for stable, which involves setting the distro in debian/copyright to be stable where it would normally read unstable or UNRELEASED.

sbuild cross build

sbuild will happily cross build using the above chroot and output a valid image for Raspberry Pi using the following:

sbuild --host=armhf --build=armhf

Sadly I’ve not been able to set the build target through gbp buildpackage, but the above works well enough for building and releasing. I’ve built up quite a reliable gbp workflow which will have a second post to cover, and that’ll explain my disappointment.