Creating and copying jail images

Josh Paetzel josh at tcbug.org
Fri Aug 10 18:43:05 UTC 2007


I've been searching for a way to create and copy jail images around
for some time now and I've found a solution that works for me and
thought I would share it with list and see if anyone can poke any
holes in it.

Problem: I need to create a jail image that I can deploy on multiple
servers, ala a generic apache jail or postgresql jail or whatever.  I
need to be able to simply explode this image in to a directory and
have it work, I'd also like to be able to compress the image because
it occasionally has to go over lower-speed WAN links.

Here are the tools that I've investigated and the problems I've had
with them:

tar, cpio, pax:  All 3 of these tools have problems with various
combinations of meta-data, links, and things like device nodes.

cpdup: makes perfect copies, no way to create an archive or image

dump: only operates on filesystems.

mksiofs: After 3 hours of trying various flags I was unable to create
a perfect image, although I got close a couple of times.

I finally hit on a solution that works for me.

Create a filebacked md filesystem and create the initial jail on that,
then dump it.  From there you can use restore to explode it anywhere
it's needed.

so, as a quick example....

dd if=/dev/zero of=/data/jailfile bs=2m count=1000
mdconfig -a -t vnode -f jailfile -u 0
newfs /dev/md0
mount /dev/md0 /mnt
cd /usr/src ; make installworld distribution DESTDIR=/mnt
do the things you do to start the jail
jexec in to it, install what you need, customizations, so on...
stop the jail
dump -0Laf jail.img /dev/md0
bzip2 jail.img

Now you have a bzip2'd image file that you can restore to an empty
directory any time you want a perfect copy of that jail.

Another interesting thought is that you could restore to a file backed
md device and impliment quotas...at the cost of preallocating the disk
space.

Anyways, for my problem set it seems to be a workable solution,
whether it is useful for anyone else or not I don't know.

Also, if you have a different solution or can see a flaw in this one
I'd love to hear about it.

-- 
Thanks,

Josh Paetzel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-chat/attachments/20070810/39fed3b7/attachment.pgp


More information about the freebsd-chat mailing list