During a chroot attempt, I got this error: "chroot: failed to run command '/bin/bash': Exec format error"

Solution 1:

Verify that you are using the right Live CD. For example, verify you are not using a 32bit CD instead of a 64bit CD. You need a 64bit kernel to run 64bit code, so check your architecture.

Assuming you mounted your system to be chrooted in /media/sda1, to determine the architecture you can:

ls /media/sda1/*

if you see lib64 in the output, it's probably a 64bit system

Solution 2:

I had the same problem when making an image for armhf arch. I had to install qemu-user-static and then copy it to chroot bin folder.

sudo cp /usr/bin/qemu-arm-static /path/to/mount/usr/bin

You may have to run

systemctl restart systemd-binfmt.service

then you should be able to chroot into the environment

Solution 3:

The error means that your jail (/mnt/temp) does not contain a bash shell, or does not contain the libraries required to run the bash shell.

If you created your jail using something like this:

debootstrap --variant=buildd --arch i386 lucid /mnt/temp \
    http://archive.ubuntu.com/ubuntu/

You probably meant to do this instead:

debootstrap --variant=minbase --arch i386 lucid /mnt/temp \
    http://archive.ubuntu.com/ubuntu/

However, as a technical answer to your problem, try:

cp -r /bin /lib /mnt/temp

This should allow you to chroot successfully, at which point you can do other things.

There are about a million things wrong with doing that though, and almost certainly you do not want to do that. Use minbase when you create your jail, or install ubuntu on a blank target (eg. a virtual machine) and create a tar archive of the entire system which you then decompress into /mnt/temp.