Crossbuilding Debian packages with sbuild (for Raspbian)

Yesterday I asked myself, how to setup a crossbuild environment on a Debian wheezy/amd64 to build binary packages compatible for Raspbian.

After digging around it seemed to be the easiest way to use mk-sbuild to setup such a build environment.
We just need to install sbuild (>= 0.64.0-1) and ubuntu-dev-tools (>= 0.146), both packages are available since jessie:

# aptitude install sbuild ubuntu-dev-tools

Some more packages are needed for crossbuilding:

# aptitude install qemu-user-static binfmt-support linux-image-amd64

Setting up the chroot is quite easy with:

# mk-sbuild --arch=armhf --debootstrap-mirror=http://archive.raspbian.org/raspbian jessie

Unfortunately you get thrown an error about bad signing key:

Release signed by unknown key (key id 9165938D90FDDD2E)

This happens cause debootstrap is using per default /usr/share/keyrings/${DISTRO}-archive-keyring.gpg, which doesn't ship the Raspbian signing key indeed. After looking how to solve that problem, I decided to use a quik&dirty fix:

# echo 'DEBOOTSTRAP_KEYRING="--keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg"' >> \
		/root/.mk-sbuild.rc
# cp -a /usr/bin/mk-sbuild /tmp/mk-sbuild
# patch -p0<./mk-sbuild_raspbian.diff /tmp/mk-sbuild

Now you should be able to setup your Raspbian sbuild chroot via:

# /tmp/mk-sbuild --arch=armhf --debootstrap-mirror=http://archive.raspbian.org/raspbian wheezy