16

I'm a chroot novice trying to make a simple chroot jail but am banging my head against the same problem time and time again... Any help would be massively appreciated

I've created a directory /usr/chroot that I want to use as a jail and created subdirectories under it and copied the dependencies of /bin/bash into it:

[root@WIG001-001 ~]# cd /usr/chroot/
[root@WIG001-001 chroot]# ls
[root@WIG001-001 chroot]# mkdir bin etc lib var home


[root@WIG001-001 chroot]# ldd /bin/bash        
linux-vdso.so.1 =>  (0x00007fff99dba000)        
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000037a2000000)        
libdl.so.2 => /lib64/libdl.so.2 (0x000000379fc00000)        
libc.so.6 => /lib64/libc.so.6 (0x000000379f800000)        
/lib64/ld-linux-x86-64.so.2 (0x000000379f400000)

[root@WIG001-001 chroot]# cp /lib64/libtinfo.so.5 /usr/chroot/lib/  
[root@WIG001-001 chroot]# cp /lib64/libdl.so.2 /udr/csr/chroot/lib/  
[root@WIG001-001 chroot]# cp /lib64/libc.so.6 /usr/chroot/lib/  
[root@WIG001-001 chroot]# cp /lib64/ld-linux-x86-64.so.2 /usr/chroot/lib/  
[root@WIG001-001 chroot]# cp /bin/bash bin  
[root@WIG001-001 chroot]# pwd  
/usr/chroot  
[root@WIG001-001 chroot]# /usr/sbin/chroot .  
/usr/sbin/chroot: cannot run command `/bin/bash': No such file or directory  


it looks like the /bin/bash created under /usr/chroot is fine as the below works:  
[root@WIG001-001 chroot]# su - nobody -s /usr/chroot/bin/bash  
-bash-4.0$ 

Can anyone give me any idea where to go from here?

Warner
  • 24,174
  • 2
  • 63
  • 69

4 Answers4

30

The error message is misleading: /bin/bash: No such file or directory can mean either that /bin/bash doesn't exist, or that the dynamic loader used by /bin/bash doesn't exist. (You'll also get this message for a script if the interpreter on the #! line doesn't exist.)

/bin/bash is looking for /lib64/ld-linux-x86-64.so.2 but you provided /lib/ld-linux-x86-64.so.2. Make /usr/chroot/lib64 a symbolic to lib or vice versa.

1

Just do this: mv /usr/chroot/lib /usr/chroot/lib64

Mark Wagner
  • 18,428
-1

I also faced the same error. Best way is to find the difference between rescue image (live CD) "/" content and "/mnt/sysimage" content.

Issue got resolved by coping /bin and /sbin from "/" directory to "/mnt/sysimage" where it was accidentally deleted.

#cp -r /bin /sbin /mnt/sysimage
#reboot
Jenny D
  • 28,400
  • 21
  • 80
  • 117
-4

you shoud try copy .bashrc file in home directory. and it will help surely.