Since I've been working on qcontrol I've had need of a way to build packages in an ARM environment. Since all my native ARM hardware is "production" (at least so far as something can be production in a home environment) I prefer to avoid installing development tools on them. When I started looking into this all my ARM systems ran from relatively small flash devices which also ruled out the possibility of a development chroot. After search the web a bit I discovered that it is possible to use qemu-user-static together with [[!binfmt-support ]] to create cross architecture chroots which can be entered mostly transparently. It is also possible to combine this with schroot and sbuild which makes the day to day use pretty much the same as a native or biarch chroot.
Since I've now had to rediscover how to do this twice (once for Sid and then again when I realized I also needed a Wheezy environment) I thought I should write it down for the benefit of my future self.
First things first lets install the various packages which we need. As
well as debootstrap to create the chroot we need
qemu-user-static
and binfmt-support
to allow us to run ARM
binaries:
$ sudo apt-get install debootstrap qemu-user-static binfmt-support
I'm using schroot
's lvm-snapshot mode so we need an LVM volume,
formatted with a filesystem and mounted in a temporary location:
$ sudo lvcreate -L8G -n sbuild-wheezy-armel /dev/VG
$ sudo mkfs.ext3 /dev/VG/sbuild-wheezy-armel
$ sudo mount /dev/VG/sbuild-wheezy-armel /mnt/
Next we need to create the chroot. For this we use debootstrap
in
foreign mode which does a 2 stage setup, firstly by using the
--foreign
option:
$ sudo debootstrap --variant=buildd --include=fakeroot,build-essential \
--arch=armel --foreign \
wheezy /mnt http://<DEBIAN-MIRROR>/debian/
Now we (temporarily) copy the qemu-arm-static
binary into the chroot
(at the place where binfmt-support
expects it), change into the
chroot and run debootstrap
's second stage to finish the basic chroot
setup:
$ sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/
$ sudo chroot /mnt
(chroot)# ./debootstrap/debootstrap --second-stage
(chroot)# exit
Now that we have a basic chroot in place it needs a little bit of
tailoring. I've found the easiest way to do this is to use
sbuild-createchroot
and then tweak the result:
$ sudo sbuild-createchroot --arch=armel --foreign --setup-only \
wheezy /mnt http://<DEBIAN-MIRROR>/debian/
If we were building a native chroot then we could have skipped the
debootstrap
stuff and let sbuild-createchroot
handle
things. Unfortunately this doesn't seem to play nicely with
--foreign
.
Now we can remove the qemu-arm-static
binary from the
chroot. schroot
will automatically bind mount the version from the
host into the chroot which ensures it remains up to date. We can also
unmount the chroot since we will let schroot
manage that from here
on:
$ sudo rm /mnt/usr/bin/qemu-arm-static
$ sudo umount /mnt
Next we need to tweak the resulting schroot
/sbuild
configuration
since sbuild-createchroot
assumes the use of schroot's directory
mode. First remove the symlink to /mnt which it created:
$ sudo rm /etc/sbuild/chroot/wheezy-armel-sbuild
Lastly we need to edit /etc/schroot/chroot.d/wheezy-armel-sbuild-<SUFFIX>
(where is randomly generated) and reconfigure it to use
lvm-snapshot mode, by apply the following changes:
[wheezy-armel-sbuild]
-type=directory
-directory=/mnt
+type=lvm-snapshot
+device=/dev/VG/sbuild-wheezy-armel
+lvm-snapshot-options=--size 2G
description=Debian wheezy/armel autobuilder
groups=root,sbuild
root-groups=root,sbuild
profile=sbuild
That's it, we now have a chroot which we can trivially invoke via
sbuild
to build armel packages:
$ sbuild --arch=armel --dist=wheezy <... other options...>
We can also use sbuild-update
to keep the chroot up to date:
$ sudo sbuild-update -udcar wheezy-armel
You can also use schroot
to login to the chroot directly, although
for that case you'll likely want to create a different chroot using
schroot
's directory
or block-device
mode instead lvm-snapshot
and drop some of the sbuild specific setup. I expect I'll blog about
this configuration in some more detail at some point in the future
since I'll want to document it to give a more convenient build
environment for Xen on
ARM
than the build
farm
which we have at work.
I'm sorry if it was a bit awkward to do the initial setup part, which definitely does need better documentation. But I'm very pleased that this is all working as originally intended--support in schroot and sbuild for all this is relatively recent and not yet massively tested (since it's quite a niche use case), so many thanks for trying all this stuff out and showing that it works!
Roger
Roger,
Please feel free to take what you need!
It all works remarkably smoothly, thanks for the cool feature.
Ian.