Simple CHROOT base system

Say you've got a special application that only runs using an older LibC or other shared libraries, but you don't want to have to run a separate server using an older operating system just for that one application. Here's the solution...

chroot is a simple command which lets you change your root folder to a different location. You're still running with the same kernel, but you are using different libraries, different shells, different user accounts and basically a completely different folder hierarchy. This utility is often used for security reasons to isolate an application from the rest of the system, but it does have other practical uses.

In Debian, there is a very simple utility you can use called debootstrap (apt-get install debootstrap). If your system isn't running Debian, you can still download the debian package for debootstrap and then use a utility like Alien to convert the package from .deb to .rpm. If you can't use an RPM on your system, you could also download a bootable CD with debootstrap on it (like Knoppix) and then boot off that, mount your drive, and continue on.

Now that you have debootstrap, the process is simple. Make a folder which will contain your chroot system (mkdir /chrootbase) and then run the following command:

debootstrap woody /chrootbase

The woody in this command represents the Debian distribution you want to installed (woody, sarge, sid, etc.). From here, you'll see debootstrap download and install a base system inside the folder you specified (in our case /chrootbase).

Now that you have a base system installed inside that folder, you can simply run:

chroot /chrootbase

and you now have a shell inside your chroot environment. If you want to run a command inside this chroot environment you simply run:

chroot /chrootbase <command_name>

In this case you'd replace <command_name> with the path (relative to the chroot folder) to the program you want to run. This means if you want to run a executable in /chrootbase/root/mytestexec, you would run:

chroot /chrootbase /root/mytestexec

And that's it. With debootstrap, making a chroot environment for any application is extremely simple!


Author: DPAK
Created: Oct 20 2005 (last modified Jan 25 2006)
Categories: Debian - Linux
TechByte #60

Warning: By visiting this site and/or by using any information contained herein, you agree to the Techbytes.ca terms of use.



Add a comment about this TechByte

If you wish to add a comment regarding this TechByte, please use the form below. Please note that by submitting comments using this form you are allowing all of the information submitted to be visible on this website. Any comments submitted using this form will only be shown on the website if they are approved by the administrators of this site. IF APPROVED, COMMENTS MAY TAKE SEVERAL DAYS TO BE POSTED.

Posted By: (Optional)

Comments:


Other TechBytes: