chroot: failed to run command bash: Exec format error

Written by - 0 comments

Published on - Listed in Linux

When you need to do certain maintenance tasks (such as replacing the root partition) or need to troubleshoot boot issues of a Linux machine, a common way to do this is by booting the machine from a live/rescue image and then chroot into the installed OS.

Knoppix is such a live Linux image and contains a lot of tools and commands to do such maintenance tasks or fix issues within an installed Linux. It can be used in graphical or in text mode.

Exec format error when trying to chroot

But after I mounted the OS-partition (just /dev/sda1 in this case) and the other required run-time partitions, I ran into an error:

root@Microknoppix:/# mount /dev/sda1 /mnt
root@Microknoppix:/# for mp in proc sys dev run; do mount /${mp} /mnt/${mp}; done
root@Microknoppix:/# chroot /mnt bash
chroot: failed to run command 'bash': Exec format error

Huh? What did I do wrong? Did I miss mounting a specific partition?

No. It turns out I started Knoppix the wrong way. That's something I already had run into in the past. And I probably will again, hence writing this post will create a beacon in my brain.

Booting knoppix64

The Knoppix Cheat Codes show a couple of very helpful (or rather must-use!) boot parameters, which can be entered right under the Knoppix logo. A simple [Enter] at the boot screen starts Knoppix in the default settings and starts up a user interface (init 5 for the older Sys Admins like me).

But the default boot settings also starts Knoppix as a 32bit system. On a 64bit machine, whether physical or virtual, this doesn't make sense and you will run into that error (Exec format error) when trying to run a 64bit command (from the chroot environment) with the booted 32bit Live/Rescue system and vice versa.

To boot Knoppix in 64bit mode, the first boot parameter should be knoppix64 followed by additional parameters, such as lang (for the keyboard language):

The following boot parameters are used in this example:

  • knoppix64 => Starts Knoppix/Linux in 64bit mode
  • lang=ch => Sets keyboard language to Swiss (German)
  • init 3 => Starts text mode only. The number 3 would probably be enough though.

Successful chroot in 64bit mode

Now that Knoppix has started up again in 64bit mode, let's try the chroot again:

Knoppix chroot

Chrooting into the OS installed on the disk now worked.

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.