When I run the
chroot command an error is given:
failed to run command ‘/bin/bash’: No such file or directory
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
If you have
/mnt/somedir/usr/bin/bash then execute
chroot /mnt/somedir /usr/bin/bash
/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/
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
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:
cp /lib64/ld-linux-x86-64.so.2 /secure/jail/lib64/
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.