Daemon Hammer
ezjail

- Jail administration framework

News Overview Usage Config Version History TODO Details Flavours FAQ Author/Contact License Thanks Links Trackback


+ News

(2008-07-10) ezjail 3.0 is in its finalization stage. It comes with a new backup and migration toolset (archive/restore), has an ez-attach feature (console), brings start/stop/restart shortcuts and adds a lot of polish to enhance user experience. It is available from CVS, considered quite robust and ready for beta testers. Estimated release date is July 16th. Feedback and bug reports are very welcome. Eventually a "mergemaster all jails" feature may also slip in the new version. Stay tuned.

(2007-07-31) After a year of hanging ezjail 2 out to dry, I decided – encountering no problems – to roll up ezjail-2.1. All new features have been tested by volunteers from CVS. Refer to Version History for a list of changes and the download link. Please report any issues you may have.

(2007-03-22) A mailing list has been created. An archive can be found here. Please subscribe to post.


+ Overview

A Jail in FreeBSD-speak is one or more tasks with the same kernel Jail-ID, bound on a single IP address, having the same chroot-environment. One usecase of the FreeBSD Jail Subsystem is to provide virtual FreeBSD-systems within a Host-system. ezjail is about making this as easy as possible, aiming for minimum system resource usage. All further references to the term Jail are to a virtual FreeBSD-system consisting of a host name, an IP-address and a Jail root.

The jail(8) man page outlines the way to create Jails, however, when you need several Jails, complete Jail Directory Trees quickly use much of your valuable hard disc space. ezjail avoids this by using FreeBSDs nullfs feature. Most of the base system (/bin, /boot, /sbin, /lib, /libexec, /rescue, /usr/{bin, include, lib, libexec, ports, sbin, share, src}) only exists in one copy in the Host-system and is being mounted read only into all Jails via nullfs. Those Jails are quite slim (around 2mb each) and only consist of some soft links into the basejail mount point and non-shared directories like /etc, /usr/local, etc.

The ezjail approach offers lots of advantages:


+ Usage

ezjail consists of two scripts: ezjail-admin and ezjail.sh, the first used to create, update and remove Jails, the latter one to start, stop and restart Jails.

ezjail-admin

The ezjail-admin utility knows 4 subcommands: create, delete, update and list. They are introduced in the order you will need them. This is a quick start only, so please refer to the man pages for details.

ezjail-admin update [-i]

To work with ezjail you need a basejail, containing the part of the world that is shared between Jails. Its location is specified in the config file. Refer to the ezjail-admin(1) and ezjail.conf(5) man page for more details. The ezjail-admin update sub command creates the basejail for you, along with a template Jail which will be copied for each new Jail you create.

From time to time it is a good idea to update the basejail. Normally this is necessary, when you update the Host-system, so it should not be a problem stop all Jails before doing so. Care has been taken not to break applications by removing the old basejail. The new world is being copied over the old one, so any installed libs will be found by applications depending on them after the update.

The name update may be misleading for novices to ezjail, but although you will most commonly use this command to update the basejail you will first encounter it to setup the ezjail environment.

The -i option tells ezjail-admin not to invoke make world to build the world but rather make installworld, assuming you already did a make buildworld before, which will be the case, if you updated the Host-system.

ezjail-admin create [-f FLAVOUR] [-x] [-r JAILROOT] JAILNAME JAILIP

After the basejail is set up you can start creating Jails. A host name and an IP to bind to are mandatory. Per default all Jails are being created in /usr/jails and the Jail root is being derived from the JAILNAME given, however, you can alter the default ezjail root dir in its config file or specify a root directory for the Jail via the -r option. If the Jails root lies outside ezjails root, a soft link is created pointing to the Jails root. This helps keeping track of all your jails when you have to spread them all over the place for whichever reason you have.

ezjail-admin checks, whether the JAILIP is configured on a local interface and gives a warning, if it isn't. You should ensure to have the IP configured in order to be able to connect to it.

The -x option is useful if you already created a Jail and deleted it via ezjail-admin delete without the -w option. In that way you can alter some properties of your jail (mostly the JAILIP).

If the -f switch is specified, the Flavour FLAVOUR is being looked for at [ezjails Jail root]/flavours and copied over the newly installed Jail.

After creating the jail you can start it with the ezjail.sh script. However, if you enabled ezjail in rc.conf, all Jails in ezjails scope are being brought up on next system start up.

ezjail-admin delete [-w] JAILNAME

What this sub command does should be clear, however if you really want to remove the Jail, i.e. delete all files under the Jails root directory, you have to give the -w option. If you don't, you have the chance to recreate the Jail with different (or the same) properties via the ezjail-admin create -x command.

ezjail.sh

The ezjail.sh script normally (if installed from ports) is found in /usr/local/etc/rc.d/ezjail.sh. It takes sub commands start, restart and stop and options in form of zero or more Jail host names. If no option is given, all Jails currently in ezjails scope are being read. This usually happens at system startup, when all rc scripts are being started with the start sub command without any options. If one more options are given, ezjail.sh only acts upon the Jails specified.

ezjail.sh uses the very resourceful /etc/rc.d/jail script to do the actual work, forcing it to be started despite the lack of jail_enable rc.conf variable, so you don't have to set it. (It won't hurt if you do so).


+ Config

To enable ezjail (i.e. starting and stopping Jails in ezjails scope), you have to add the line ezjail_enable="YES" to /etc/rc.conf. This is due to $PREFIX/etc/rc.d/ezjail.sh being an rc-script, giving all the auto-start capabilities that comes with it. However the ezjail-admin utility works without the rc.conf variable set.

The config file at $PREFIX/etc/ezjail.conf controls ezjails behavior. As it is self explaining plus there is a man page, I kindly ask to look up the options there.


+ Version History

Since ezjail is useful under FreeBSD only, you might want to install it from ports sysutils/ezjail. A cvsweb is available at ezjail cvsweb, plus there is a fresh checkout. The most current version is available via cvs. Use cvs -d :pserver:anoncvs@cvs.erdgeist.org:/home/cvsroot co ezjail with an empty passwort to check it out. Just type sudo make install to install it. Older versions may be found here (checksums in tooltips):

Version history

+ TODO


+ Details

I have spent a lot of time investigating all tools FreeBSD provides for an easy handling of Jails. A run across a few that really helped a lot. I wrote a blog entry in German about it. In short, the most important facts:


+ Flavours

Version 1.2 of ezjail introduces the concept of Flavours. A flavour corresponds to a preconfigured Jail. Basically it is a directory being copied recursively over a new Jails root and a script being run on its first startup to do some initialization.

An example Flavour resides under /usr/local/share/examples/ezjail/default. For your convenience it is being copied to ezjails jail root (default: /usr/jails/flavours/), by the ezjail-admin update command. In this location all other flavours are being expected to reside, too.

Flavours will be copied recursively over any new Jail created with the ezjail-admin -f FLAVOUR command. In the example flavour an /ezjail.flavour script is provided which, if found by ezjail-admin, is being executed when the Jail starts up for the first time. The script demonstrates most of the common actions needed to prepare the Jail like creating groups, users, changing the ownership of files and installing packages. You may add your own code to do more post-install actions.

The default flavour demonstrates how to pkg_add some prefetched packages. Since no remote fetching of missing packages is requested, you need to provide all package dependencies yourself. Although I tried hard to provide easy means to setup Flavours, essential features are missing in the FreeBSD base system (like recursive package fetching without installing them). The portupgrade utility provides an pkg_fetch command, but since it requires ruby I am not really recommending it for the host system.

If you have ports in base system and are not afraid of compiling things there (which I personally would not recommend, either), the lines cd /usr/ports/<cat>/<port>; make PACKAGES=/usr/jails/flavours/<flav>/pkg/ package-recursive deinstall distclean will install the port and all dependencies to the base system, make packages of the port and all dependencies, put them to the flavours pkg directory and deinstall the port (unfortunally not its dependencies) from host system. You might also consider setting up a compile Jail to do this.

If you provide /usr/ports/ for your ezjails, the /ezjail.flavour can also install some ports for you. But note, that Jail creation time increases dramatically in this case. Be sure to have a working /etc/resolv.conf etc. in the Jail before trying to access the network.


+ FAQ

County Jail

+ Author/Contact

ezjail was written by Dirk Engling who likes to hear from happy customers. His mail address is erdgeist@erdgeist.org. Requests should go to the project mailing list ezjail@erdgeist.org. You can subscribe to that list at ezjail-subscribe@erdgeist.org. There is an IRC channel #ezjail on ircnet. Please send bug reports, comments and feature requests. Donations are welcome... in form of beer. See...


+ License

ezjail is considered beer ware.


+ Thanks

...are due to:


+ Links

+ Trackbacks

Thanks for spreading the word go to


FreeBSD Banner Valid XHTML 1.1