2

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.

Maxxer
  • 143

1 Answers1

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.

Stephen Kitt
  • 434,908
  • 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 '19 at 05: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 '19 at 05:46
  • I now have a working mipsel chroot after running the commands in my updated answer. – Stephen Kitt May 17 '19 at 05: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 '19 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 '19 at 11:00
  • I found I need to run sbuild-createchroot --arch=mipsel --setup-only wheezy /root/wheezy-mipsel-chroot/ http://archive.debian.org/debian/ to prepare the chroot for sbuild, but still the same error – Maxxer May 17 '19 at 11:01
  • Yes, sbuild-createchroot doesn’t seem to cope with a completely foreign chroot; I couldn’t get it to work correctly. I’ll add the registration steps to my answer in a few minutes. – Stephen Kitt May 17 '19 at 11:39