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 ?
Create a Chroot Jail and copy all system files into jail
3k views Asked by user1159517 AtThere are 2 answers
To create a basic debian-based root file systems (not necessarily on debian-based host systems), you can use debootstrap
or multistrap
tool. I think there is also a febootstrap
equivalent for fedora-based root file systems.
In debootstrap, you will have full control on which packages should be installed, over the base necessary packages, which are packages with "Priority: required" and "Priority: important" tag. In case of initial extra packages, you are responsible for package dependencies.
multistrap
is a newer tool, which uses apt and can leverage multiple repositories, and so takes care of the dependency issue.
You can also do cross-bootstrapping which is creating a root fs for another architecture. This is useful when creating embedded or virtualized systems.
sample debootstrap
command:
debootstrap wheezy rootfs/ http://ftp.us.debian.org/debian
then you can chroot into it and do whatever else is needed.
This is by far the easiest method to create chroots.
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:
On my system it shows the following output:
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.