27

I was following the instructions of this tutorial HOWTO: Purge and Reinstall Grub 2 from the Live CD, when I encountered an error at step 1, as I launched the command

sudo chroot /mnt/temp

The error was the following:

chroot: failed to run command `/bin/bash': Exec format error

Where does that come from? How do I get through?

0

6 Answers 6

26

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

1
  • It is but still cannot chroot
    – Starx
    Mar 29, 2012 at 10:03
8

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

2
  • Work fine for me! Note: mkdir and cp this file before running debootstrap command Feb 14, 2022 at 18:19
  • Changed my machine and had this issue, forgot about the qemu stuff. Thanks a lot! Dec 22, 2023 at 14:47
1

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.

1

In my case, I was using a new Linux VM installation as ther host for chroot, This VM did not have the qemu and binfmt packages installed. Error: chroot: failed to run command /bin/bash: Exec format error got solved installing below packages:

  1. sudo apt install qemu-user-static
  2. sudo apt install binfmt-support

Just to clarify, the Linux VM was using ubuntu-20.04, x86_64 and to be chrooted system was armhf i.e. 32-bit system.

0

Indeed this is a 64-bit 32-bit incompatibility.

Although with

cp /bin/bash /mount/temp/tmp

(copies 32-bit exec to the new root in the tmp directory

chroot /mount/temp /tmp/bash

chroot is fine, all commands still fail. You would have to copy them all over.

-1

In my case, I was trying to chroot into a 64-bit version of Linux but my current Linux was 32-bit.

I had mounted a disk image (master image, for replication on multiple machines).

2
  • Same answer as @GrandOxymore's above. Jun 4, 2017 at 15:45
  • @KarlRichter Similar but not the same. Running 32bit program in a 64bit OS is not the same as running a 32bit program in a 64bit virtual environment (or OS). I could run a 32bit guest os and it would have run fine.
    – azuer88
    Jun 5, 2017 at 4:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .