1

I'm trying to cross-build a Debian/Ubuntu package on a running amd64 system to mips arch. I've tried several methods, from pubilder to sbuild, but I keep failing. About the latter, on a freshly installed Debian 9 I do:

apt-get -y install sbuild
sbuild-createchroot --arch=mips --make-sbuild-tarball=/srv/chroots/wheezy-sbuild.tgz wheezy /srv/chroots/wheezy http://archive.debian.org/debian/

But in the end I get:

W: Failure trying to run: chroot /srv/chroots/wheezy dpkg-deb -f /var/cache/apt/archives/dpkg_1.16.18_mips.deb Version
W: See /srv/chroots/wheezy/debootstrap/debootstrap.log for details
W: Failure trying to run: chroot /srv/chroots/wheezy mount -t proc proc /proc
W: See /srv/chroots/wheezy/debootstrap/debootstrap.log for details
E: Error running debootstrap at /usr/sbin/sbuild-createchroot line 268.

and the log contains:

chroot: failed to run command 'dpkg-deb': Exec format error
chroot: failed to run command 'mount': Exec format error

All the methods I tried end up with that Exec format error while trying different commands.

  • Do you have to target Wheezy? It would be much easier if you could target Stretch. – Stephen Kitt May 15 at 21:12
  • Yes, wheezy. I need to compile a package for UniFi Edge Router which is based on that version – Maxxer May 16 at 2:45
2

Cross-building only became nice and easy with Debian 9 as a target; it’s do-able with Debian 8 too, but targeting Debian 7 is a bit too complex. (EmDebian was dropped before Debian 7.)

There is however a simple setup to build mipsel Wheezy packages on any system capable of running QEMU, and building packages there will still be much faster than building on your router:

  • start an mipsel setup in a chroot using debootstrap:

    sudo debootstrap --arch=mipsel --foreign --variant=buildd \
                     --include=fakeroot,build-essential \
                     wheezy ./wheezy-mipsel-chroot \
                     http://archive.debian.org/debian
    
  • install QEMU and binfmt_misc support:

    sudo apt install qemu-user-static binfmt-support
    
  • copy the QEMU binary into the chroot:

    sudo cp /usr/bin/qemu-mipsel-static wheezy-mipsel-chroot/usr/bin
    

    (it’s statically-linked, so it will work fine)

  • enter the chroot and finish debootstrap:

    sudo chroot wheezy-mipsel-chroot /debootstrap/debootstrap --second-stage
    

You can now use your chroot to build packages. Manually, copy your package into the chroot, enter it, and build with dpkg-buildpackage after installing the build dependencies.

To build with sbuild, you’ll need to at least register the chroot with schroot; add a file named /etc/schroot/chroot.d/wheezy-mipsel-sbuild with the following contents:

[wheezy-mipsel-sbuild]
description=Debian wheezy/mipsel autobuilder
groups=root,sbuild
root-groups=root,sbuild
profile=sbuild
type=directory
directory=/usr/var/backups/steve/wheezy-mipsel-chroot
union-type=overlay

There are probably other steps required to get the chroot to work correctly with sbuild, in particular setting up the sbuild group inside the chroot and fixing ownership.

  • Before running the last commands I had to copy some dirs as stated here. But even if I can enter the chroot when running debootstrap package installation fails because package architecture (mipsel) does not match system (amd64) – Maxxer May 17 at 5:41
  • You’ve destroyed the chroot by copying the directories. (The chroot contained foreign binaries which you overwrote with amd64 binaries.) I ran all those commands before posting my answer, on a Debian 9 system, and it worked as described. (Although I realise now that I got the target arch wrong; I’ll run them again with mipsel...) What failed in your case, that led you to copy the directories? – Stephen Kitt May 17 at 5:46
  • I now have a working mipsel chroot after running the commands in my updated answer. – Stephen Kitt May 17 at 5:53
  • I've accepted the answer because all works. Unfortunately the chroot is not liked by sbuild. If I run sbuild --dist=wheezy --host=mipsel -c /root/wheezy-mipsel-chroot/ I get E: /root/wheezy-mipsel-chroot/: Chroot not found – Maxxer May 17 at 10:17
  • If you want to use the chroot with sbuild in its default schroot mode, you need to register it with schroot. – Stephen Kitt May 17 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.