You are not logged in.

#1 2011-09-09 18:02:51

ar5007eg
Member
Registered: 2008-06-29
Posts: 45

Setting up a chroot jail for a simple program.

Is there a easy way to setup a chroot environment for a simple program?
I have a '/chroot' folder and a 'simple_program' inside it. When I try to

chroot . simple_program

I get a "chroot: failed to run command `simple_program': No such file or directory", but there is a simple_program executable file inside /chroot.

After a little search, I realized I have to copy the libs simple_program depends on to /chroot/lib. Here is the output of "ldd simple_program":

$ldd simple_program
	linux-gate.so.1 =>  (0xb7815000)
	libncursesw.so.5 => /lib/libncursesw.so.5 (0xb77a4000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb76b6000)
	libm.so.6 => /lib/libm.so.6 (0xb768c000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb766f000)
	libc.so.6 => /lib/libc.so.6 (0xb7506000)
	/lib/ld-linux.so.2 (0xb7816000)

But I'm not sure what do I have to copy, if I have to make symlinks myself, if I have also to mount /proc and /dev, etc... Is there some kind of tool that can automatically generate a chroot jail based on the dependencies of simple_program? If not, can you tell me what do I have to setup?

Thanks in advance

Last edited by ar5007eg (2011-09-09 18:04:03)

Offline

#2 2011-09-09 18:36:05

ar5007eg
Member
Registered: 2008-06-29
Posts: 45

Re: Setting up a chroot jail for a simple program.

Did it. Instead of manually copying the files I just installed them with pacman using /chroot as the destination. Searched for the right packages using pacman -Qo. Just for reference this is what I did:

mkdir /chroot
cd /chroot
mkdir -p var/lib/pacman 
mkdir -p var/cache/pacman/pkg
pacman -Sy -r .

pacman  -Su --cachedir var/cache/pacman/pkg -S glibc -r .
pacman  -Su --cachedir var/cache/pacman/pkg -S gcc-libs -r .
pacman  -Su --cachedir var/cache/pacman/pkg -S ncurses -r .

mkdir dev
mkdir proc
mkdir sys
mount -t proc /proc ./proc
mount -t sysfs /sys ./sys
mount -o bind /dev ./dev

cp ~/simple_program .
chroot . ./ep1

Maybe that's not the easiest way to do it, but it doesn't spend too much space, just 66MB here.

Offline

Board footer

Powered by FluxBB