Chrooting to arm(el) environment on a linux PC

This How-To describes a way to chroot to arm(el) environment on your linux PC. It has been designed for and tested on Debian, but something similar should be possible to achieve on other distributions as well.

Why would we need this? Well, personally, I used this method to generate MyLenny root filesystems, to build EABI Bluerings kernel, and this is also how I maintain all my firmwares. From a user's point of view, this trick is also invaluable, since it provides a way to 'natively' compile binaries for your nas on your PC, thus:
1. Not having to worry about cross-toolchains, their bugs and cross-environments.
2. Having binaries built a lot faster than doing so on the nas.

Note this setup is incompatible with Scratchbox (both use the binfmt_misc module to register the same formats), so it's recommended to remove it (or stop its init script) before continuing.

So, let's get going:

1. Download and compile qemu-arm-eabi:

# mkdir -p ~/src
# cd ~/src
# wget
# tar -xjvf qemu-arm-eabi-0.3.tar.bz2
# cd qemu-arm-eabi-0.3
# ./
# apt-get install build-essential gcc-3.4 zlib1g-dev libsdl1.2-dev # the packages needed to build qemu-arm-eabi
# ./

2. Install binfmt-support

# apt-get install binfmt-support

3. Next we'll have to register arm binaries using binfmt-support.
Either install the qemu-binfmt package I provide (it depends on qemu):

# apt-get install qemu
# cd ~/src
# wget
# dpkg -i qemu-binfmt_0.8.2-4_all.deb # this registers arm, armeb, mips, mipsel, powerpc and sparc binaries, so you should
## never do this on one of these architectures!

Or register them manually:
i) create /usr/share/binfmts/qemu-arm with the following content:
package qemu
interpreter /usr/lib/qemu-binfmt/arm
magic \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00
mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff

ii) update binfmt_misc kernel module's settings using binfmt-support:
# update-binfmts --import
##it will probably complain about not finding /usr/lib/qemu-binfmt/arm executable - just ignore it

4. Copy arm-linux-user binary into place:

# rootfs=/path/to/arm(el)/rootfs #the path to arm(el) rootfs you want to chroot to
# mkdir -p ${rootfs}/usr/lib/qemu-binfmt
# rm -rf ${rootfs}/usr/lib/qemu-binfmt/arm
# cp -f ~/src/qemu-arm-eabi-0.3/qemu-arm-eabi/arm-linux-user ${rootfs}/usr/lib/qemu-binfmt/arm

Now you can chroot to your rootfs:

# chroot ${rootfs}

and execute arm(el) binaries as long as qemu-arm-eabi supports the system calls they use.

The next time you want to chroot to some other arm(el) rootfs, you'll just need to repeat step 4.

Have fun,


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License