When I run the chroot command an error is given:

failed to run command ‘/bin/bash’: No such file or directory 
share|improve this question
1  
Can the question be considered a pure duplicate of unix.stackexchange.com/questions/76490/…? The answers to the questions represent a possible solution for the problem definitely worth a link, but that doesn't make the question a duplicate of it. – Karl Richter Sep 26 '14 at 17:15
1  
The issue for me was that I was using a 32-bit Live CD to mount a 64-bit OS disk and chroot to it. A 32-bit kernel can't run 64-bit bash. The solution was to get a 64-bit Live CD. (The linked duplicate is entirely unrelated.) – Leons Oct 2 '14 at 17:41
    
This is not a duplicate, despite the explanation of the source of the problem being applicable to both questions. The question this is marked a duplicate of is about missing libraries on a generic install, whereas this question is specifically about an error occurring in a chrooted environment. – bschlueter Nov 13 '17 at 22:09

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

share|improve this answer
1  
There is a /bin/bash file in the rootfs folder – USER3254789 May 6 '14 at 7:24
1  
It might be caused by some failing command/line in /root/.bashrc or /root/.bash_profile in your chroot. Can you temporarily rename these files? Also can you make sure that bash is executable (chmod +x /chroot/bin/bash)? – phoops May 6 '14 at 7:28
    
aspade@home-ba:~/DebianArm$ sudo chmod +x rootfs/bin/bash. aspade@home-ba:~/DebianArm$ sudo chroot rootfs. chroot: failed to run command ‘/bin/bash’: No such file or directory – USER3254789 May 6 '14 at 7:50
    
I have the same problem. I have bin/bash inside the folder I'm trying to chroot to, but it still tells me the same thing. – Dalibor Filus Nov 3 '15 at 14:25
18  
I figured it out. bin/bash is there, but I didn't have /lib and /lib64 inside it. /bin/bash depends (ofc) on libc, ld-linux, libdl etc... So simple cp -a /usr rootfs/, cp -a /lib rootfs/, cp -a /lib64 rootfs/ was enough. (You can mount-bind those ofc, but I copied them, because I want to run something dangerous, which might corrupt those files in rootfs.) The message from chroot could be more descriptive. "no such file or directory" really means "I can't run this sh...". – Dalibor Filus Nov 3 '15 at 14:28

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

share|improve this answer
2  
There is a /bin/bash file in the rootfs file so what is the problem – USER3254789 May 6 '14 at 7:18
1  
to whoever downvoted: although this was not the problem in the poster's case, this is a valid and not unprobable explanation of the error in the question. If you see any other problem, please leave a comment when you downvote something. – crater2150 Sep 17 '14 at 19:10

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

ld-linux-x86-64.so.2

It was fixed by executing the following:

cp /lib64/ld-linux-x86-64.so.2 /secure/jail/lib64/
share|improve this answer
    
didn't fix it for me, but doing cp -r /lib /lib64 /secure/jail fixed it, i needed something from both lib and lib64, and i didn't bother to figure out exactly what. (probably because i had multiarch enabled) – hanshenrik Dec 15 '17 at 21:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.