Unix & Linux: chroot: failed to run command /bin/bash : No such file or directory (8 Solutions!!)

preview_player
Показать описание
Unix & Linux: chroot: failed to run command /bin/bash : No such file or directory

The Question: When I run the chroot command an error is given:
failed to run command '/bin/bash': No such file or directory

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 37 people ==
This error means that there is no /bin/bash directory inside chroot. Make sure
you point it to where bash (or other shell's) executable is in chroot
directory.
If you have /mnt/somedir/usr/bin/bash then execute chroot /mnt/somedir /usr/
bin/bash

== This solution helped 4 people ==
chroot tries to start the shell that is set in your $SHELL environment variable
by default, but it looks for it in your new root dir, which seems not to
contain /bin/bash, so it cannot start.
You can tell chroot to start another program inside the new root by simply
adding it as a parameter:
chroot /your/new/root /bin/foo --options...
Note that the path of the command is interpreted inside your new root, so in
this example the called program is in fact in /your/new/root/bin/foo

== This solution helped 3 people ==
I was getting the same error when trying to ssh to a chrooted account on a
remote server. In my case, I was missing the following file in the remote lib64
directory. Server is Centos6.9
It was fixed by executing the following:

== This solution helped 17 people ==
I had /bin/bash inside chrooted directory, but I didn't have /lib and /lib64
inside it. The message from chroot could be more descriptive. "no such file or
directory" really means "I can't run this...".
/bin/bash depends of course on libc, ld-linux, libdl etc., you can use ldd /
bin/bash to see which libraries it requires.
1) You can mount -o bind these directories under chroot 2) Or you can copy
these libraries to chroot, if you don't trust the chrooted env to not corrupt
them, like so:
cp -a /usr rootfs/
cp -a /lib rootfs/
cp -a /lib64 rootfs/

you need to run ldd against bash ldd $(which bash), then you might find a
missing dependency, for example if you didn't mount/copy lib64, for 64 systems,
it will through this error.

Рекомендации по теме