linuxsecurityubuntuchrootjail

Create a Chroot Jail and copy all system files into jail


I am creating chroot jail in linux , but i do not have access to any system file like ls/cd/gcc/g++. What are the necessary libs/bin/systme files i need to copy to my chroot jail ?


Solution

  • Executables like ls/cd/gcc/g++, they depend on shared library (unless you didn't build them to be statically). So, what you need to do is copy all those shared library dependencies to appropriate location into your chroot jail, also you need to find what are those shared dependencies are. To find out you need help from "ldd".

    To see what shared dependencies gcc has, do the following:

               ldd /usr/bin/gcc
    

    On my system it shows the following output:

    linux-vdso.so.1 =>  (0x00007fffd9bff000)
    libc.so.6 => /lib64/libc.so.6 (0x00000030c9c00000)
    /lib64/ld-linux-x86-64.so.2 (0x00000030c9800000)
    

    So, gcc has the dependency of standard c library libc.so and it also needs ld (executable loader), place these shared libraries into appropriate place (i.e libc under /lib64) into your chroot jail, along with gcc. So gcc can load necessary stuffs while you call gcc.