I'm trying to do some work on an image for a raspberry pi, but I don't have access to the pi itself, just the SD card that runs the OS.

I'd like to chroot onto the pi's SD card (mainly to run some pip commands), but I'm getting errors with bash :

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

I assume this is because the programs are compiled for the pi's processor and not mine.

The only thought I have is changing the $PATH to point to my /bin, but I can't imagine that being good practice or safe in any way

Is there a way to make this work?


It is possible.

You need to install qemu-user-static on your x86/x86_64 computer:

sudo apt-get install qemu-user-static

Let's assume that your rootfs is mounted to /mnt.

Then try:

sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

cd /mnt
sudo mount --bind /dev dev/
sudo mount --bind /sys sys/
sudo mount --bind /proc proc/
sudo mount --bind /dev/pts dev/pts
#sudo rm /mnt/etc/ld.so.preload # not sure about this
sudo chroot .
  • Can you expand on the ld.so.preload? Would it only be a bad idea because it may load something that I need in the chroot? – Brydon Gibson Feb 16 '18 at 17:34

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.