2

I am trying to understand chroot.

I am trying to run just "ls" command in chroot environment.

So i copied "ls" and "bash" and its dependencies(as shown by ldd) to corresponding bin, lib, lib64 directories in new root directory and ran chroot command. But I get following error.

root@vig-debian:/home/vignesh# chroot /home/vignesh/my_chroot/ my_chroot/bin/bash 
chroot: failed to run command ‘my_chroot/bin/bash’: No such file or directory

below are logs of what I tried.

=========================================================

root@vig-debian:/home/vignesh/my_chroot# mkdir bin  
root@vig-debian:/home/vignesh/my_chroot# mkdir lib  
root@vig-debian:/home/vignesh/my_chroot# mkdir lib64  
root@vig-debian:/home/vignesh/my_choot# cp /bin/ls bin/  
root@vig-debian:/home/vignesh/my_choot# cp /bin/bash bin/  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot# ldd bin/ls  
    linux-vdso.so.1 (0x00007ffd463f2000)  
    libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fa1e4bf8000)  
    libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007fa1e49ef000)  
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa1e4644000)  
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fa1e43d6000)  
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa1e41d2000)  
    /lib64/ld-linux-x86-64.so.2 (0x00007fa1e4e1d000)  
    libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007fa1e3fcd000)  
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa1e3db0000)  
root@vig-debian:/home/vignesh/my_chroot# ldd bin/bash   
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot#  
    linux-vdso.so.1 (0x00007fff276dd000)  
    libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f5ecbaab000)  
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f5ecb881000)  
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5ecb67d000)  
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5ecb2d2000)  
    /lib64/ld-linux-x86-64.so.2 (0x00007f5ecbcd0000)  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot# cp /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libacl.so.1 /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libattr.so.1 /lib/x86_64-linux-gnu/libpthread.so.0 lib/  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot# cp /lib64/ld-linux-x86-64.so.2 lib64/  
root@vig-debian:/home/vignesh/my_chroot# cp /lib/x86_64-linux-gnu/libncurses.so.5 /lib/x86_64-linux-gnu/libtinfo.so.5 /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libc.so.6 lib/  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot#  
root@vig-debian:/home/vignesh/my_chroot# ls  
bin  lib  lib64  
root@vig-debian:/home/vignesh/my_chroot# cd ../  
root@vig-debian:/home/vignesh# chroot /home/vignesh/my_chroot/ my_chroot/bin/bash   
chroot: failed to run command ‘my_chroot/bin/bash’: No such file or directory
root@vig-debian:/home/vignesh# 

I then created debian image using "debootstap" and then could execute "chroot" without any error..

So, is whatever I tried wrong??

3

You should run chroot /home/vignesh/my_chroot/ /bin/bash. The first argument is where to chroot and the second the command. The path of the command is relative to where you chroot.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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