easiest way to change into qemu based chroot (x86_64 -> armel)

Also already dreamed of just debootstraping another architectures rootfs onto
an SD card but woke up unpleasently by the hard reality of binary incompatibility?
Well.
There’s an easy way to make our dream come true after all!
First you’ll need the static qemu binary for your arch, in this case for armel it is
http://packages.debian.org/search?searchon=contents&keywords=%2Fusr%2Fbin%2Fqemu-arm-static&mode=path&suite=stable&arch=any
If you have some other distro then Debian running (I have done it under Gentoo) you can just extract the needed file with ark or any other app which can decompress debian packages.
Copy the binary into the root of the directory/mount point you wanna debootstrap your rootfs to.
This point requires binfmt_misc enabled within kernel! (/proc/sys/fs/binfmt_misc/register)
Type the following command for arm (change it if another arch is used!):
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
Now you can debootstrap as if you would do it onto a native arch:
debootstrap --arch armel sid arm_chroot/ http://mirror.switch.ch/ftp/mirror/debian/
Then comes the hottest part!
Chroot into it, like it would be a native arch! ;-D

One thought on “easiest way to change into qemu based chroot (x86_64 -> armel)”

  1. That’s pretty cool! Back then when I statically linked qemu (There was no package for it in Debian) to use it with a chroot I had to debootstrap –foreign first and copy qemu into the chroot-folder. Then chroot into it calling qemu and have debootstrap continue once I was inside the chroot. Your method is far more elegant. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *