Running CentOS 5.5 in a Jail

Work In Progress

Contributed by JohnNielsen

This document is intended to serve as a walk-through for getting a Centos 5.5 jail running on a host running FreeBSD 8-STABLE.

Motivation

I have been working on a project to provide an arbitrary number of dev/test/demo environments for a 3-tier web application. The environments need to be independent, lightweight, easily replicated, network-reachable, and resemble the production environment as closely as possible. Being able to rapidly provision new environments is a plus. In this case the production environment runs CentOS 5, Python, Apache, and PostgreSQL.

Fully virtualized environments as provided by VMware or VirtualBox might have worked, but I wanted something more flexible and lightweight in terms of resource allocation and consumption. The virtual disks required by such VM's are also not ideal since they need to be a fixed size and generally need to be copied in full to be cloned.

I decided that I really wanted to use ZFS and FreeBSD jails. That combination meets all of the requirements except for being similar to the production stack running CentOS. Unless maybe CentOS could run inside a FreeBSD jail with Linux emulation...

It turns out that it can with a modest amount of effort. Now that I've been through that once I'd like to share what I've learned so anyone else who likes this crazy idea can quickly implement it. With a successful proof-of-concept in hand I will be using this solution for my project.

Preparing the Host

Bootstrapping the Jail

To get things rolling we will extract the squashfs environment used by the CentOS installer. We then use that environment to install the selected set of packages.

Configuring the Jail

Starting the Jail

With the changes to /etc/rc.conf above the jail will start automatically at reboot.

With any luck, you should be in business at this point. Use "jexec <num> bash" to look around inside the jail, where <num> is obtained from running "jls". SSH (as root) should work as well.

RPM and yum will be installed and functional, so installing new packages or updates to existing ones is much easier than bootstrapping the initial set.

Most things should work as you would expect.

Known Limitations

Example Cloning Procedure

Image/Linux/CentOS55 (last edited 2011-12-20 18:45:45 by JohnNielsen)