Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to chroot into a Arch Linux ARM filesystem from x86_64.

I've seen that it's possible to do using static qemu by copying the binary into the chroot system:

$ cp /usr/bin/qemu-arm archarm-chroot/usr/bin    

But despite this I always get the following error:

chroot: failed to run command ‘/bin/bash’: Exec format error

I know this means that the architectures differ. Am I doing something wrong?

share|improve this question
1  
You have to configure binfmt first, have a look at wiki.debian.org/QemuUserEmulation for a quiet short introduction. An example for configuring binfmt_misc can be found at svn.kju-app.org/trunk/qemu/qemu/qemu-binfmt-conf.sh –  Ulrich Dangel Jun 28 '12 at 23:00
    
Qemu static packages don't appear to be in the Arch repositories. –  Jivings Jun 28 '12 at 23:04
1  
Sorry i don't use arch, but you should probably be able to build a static qemu package by adding -static to the linker options –  Ulrich Dangel Jun 28 '12 at 23:07

4 Answers 4

up vote 7 down vote accepted

You cannot chroot into different architecture. By chrooting, you are executing the binaries (from the chroot) on your architecture. Executing ARM binaries on x86 (and x86_64 in that matter) would lead to "Exec format error".

If you want to run binaries from different architecture you will need an Emulation, Qemu is a good candidate for this, but you will need to learn how to use it. This would involve creating RootFS and compiling a kernel for ARM, you will need a toolchain for compiling ARM binaries (and kernel) perhaps. One thing is for sure: Forget the chroot method, you cannot run binaries compiled for ARM on x86 (x86_64).

Edit: After the small talk with @UrichDangel, I realized, it should be possible to enter the chroot environment with qemu-user programs (qemu-arm in this case). Chroot should be executing qemu-arm compiled for your host architecture, then the qemu-arm can execute your /bin/sh (compiled for arm)

share|improve this answer
3  
You should be able to use binfmt and qemu in combination to run non native targets - wiki.debian.org/QemuUserEmulation –  Ulrich Dangel Jun 28 '12 at 22:59
    
I know how to use Qemu for emulation. Apparently you can use it with chroot, although clearly I cannot work out how. –  Jivings Jun 28 '12 at 23:01
    
@UlrichDangel, Yes, this is a good information. But I think the OP were not looking for this king of solution. binfmt would be possible once he has properly installed qemu with qemu-arm emulation, but I believe he is wanting to enter his ARM emulation environment (e.g. Raspberry Pi) where he would need qemu-system-arm. –  0xAF Jun 28 '12 at 23:07
    
@0xAF but the binfmt/qemu-user solution is exactly what OP described, being able to chroot into into an arm chroot and run the commands without the need to build a dedicated rootfs etc. –  Ulrich Dangel Jun 28 '12 at 23:09
    
@Jivings, If you are looking to start just one binary compiled for ARM, you should be able to do this with qemu-arm program, then you will find the binfmt (@Ulrich Daniel suggestion) very handy. –  0xAF Jun 28 '12 at 23:10

You can most definitely 'chroot' into a (mounted) filesystem meant for a different architecture and do some meaningful work, you just need the right tools.

Have a look at PRoot, which is a user-space implementation of chroot, mount --bind, and binfmt_misc: http://proot.me/

Together with QEMU's user mode emulators, you're all set.

Although you usually cannot perform a 'full' boot (i.e. starting init and services), it is good enough to run some binaries from their 'natural' place, with access to all their configuration files, including some that are bind-mounted from the 'host' system, etc.

share|improve this answer

I just ran into the same issue on Ubuntu. I did have binfmt configured and qemu-arm-static copied to the same chroot-ed path as on host system.

After an hour, I did set|grep bash on a host machine. I found that I had /bin/bash in two env variables: SHELL and SUDO_COMMAND. After replacing the variables, my chroot to ARM worked:

SHELL=/bin/sh SUDO_COMMAND=/bin/sh chroot hd
share|improve this answer

I think the problem is that you should not copy qemu-arm but qemu-arm-static. This is a static compiled executable able to run from inside the chroot without any libraries.

You can also look in /proc/sys/fs/binfmt_misc if there exists a file qemu-arm. If not restart the service binfmt_support.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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