Chroot is the operation of changing the root directory on Unix-like operating systems. A program launched with a modified root directory will only have access to the files contained in this directory.
Dependency Installation
The first thing to do is run the following installation commands, which will be explained later
apt-get install binutils debootstrap
Then you should choose a place to configure chroot. We recommend using will use /var/chroot directory
Create the necessary directories
You need a create chroot folder
mkdir -p /var/chroot
This completes the setup of the preliminary steps. Next, you need to copy all the commands and their dependencies. This requires a command interpreter, so let’s copy bash.
mkdir -p /var/chroot/bin
cp /bin/bash /var/chroot/bin
Having looked at all the dependencies, you can run the following program
ldd /bin/bash
If you are using (for example) a 32-bit version, it will look just like this:
linux-gate.so.1 => (0xb773e000)
libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7718000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb7714000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75c3000)
/lib/ld-linux.so.2 (0xb773f000)
The following is the copying of files:
mkdir -p /var/chroot/lib
mkdir -p /var/chroot/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libtinfo.so.5 /var/chroot/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libdl.so.2 /var/chroot/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libc.so.6 /var/chroot/lib/i386-linux-gnu
Testing the environment
Checking the bash setting
chroot /var/chroot
If you need to connect to the network in chroot, you will need to run the following commands:
mkdir -p /var/chroot/etc
cp /etc/resolv.conf /var/chroot/etc
cp /etc/gai.conf /var/chroot/etc
Leave A Comment?