Creating a chroot environment in Fedora with bash and other utils.

2011-09-19 424 words 2 mins read


I am testing some of my scripts to work on a very old system and there the versions of the most popular applications are very old, real old :(. So, some of things that I am very used to since last couple of years, do not seem to work as expected and I need to keep verifying a lot of things on the server, very inconvinient to keep testing the script on the server (need to connect on VPN) just to test some very simple things.

But if I want to test it on my local desktop or laptop then I need to donwgrade all the applications on my system. Other option is changing the scripts or the paths to get the lower version to work. I found the third option which I liked best and gives me a very controlled environment – chroot.

So, what do we need to achieve this. Here are the steps

  • Create a empty directory

  • Create the minimum required directories under this directory

mkdir -p {root,home,dev,etc,lib,usr,bin}
   mkdir -p usr/bin
   mkdir -p libexec/openssh
  • Copy the minimim files required for the chroot
mknod -m 666 dev/null c 1 3
   cd etc
   cp /etc/ .
   cp -avr /etc/ .
   cp -avr /etc/ .
   cp /etc/ .
   cp /etc/nsswitch.conf .
   cp /etc/passwd .
   cp /etc/group .
   cp /etc/hosts .
   cp /etc/resolv.conf .
  • Copy the required libs for the commands that you would like to have in the chroot

This will have a output like this: => (0x00e77000) => /lib/ (0x46bf1000) => /lib/ (0x46bba000) => /lib/ (0x46020000) => /lib/ (0x47fb3000) => /lib/ (0x46a09000) => /lib/ (0x46bb3000)
/lib/ (0x469e8000) => /lib/ (0x46b97000) => /lib/ (0x46960000)
Here you would need to copy all the files mentioned after the => sign in the output to your lib directory for the chrooted environment. Also make sure that if the above are links then you copy the actual files also to ensure that you have the actual libs for the commands to work.

  • Copy the actual command to the chroot environment.

Copy the command with cp command to the bin directory of your chroot environment.

Once all this is done, you can simply chroot to this directory with the command


Voila, you are done.

Check that you have all the utils/commands that you have copied and nothing less/nothing more.

Enhanced by Zemanta


Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it