Steve/Jail Images

From FBSD_tips

Jump to: navigation, search

Back to "Admin building blocks"

Jails are great. Also great is being able to easily move a jail to another host. The way I do that is to put them on disk images. To do that, is this:

   dd if=/dev/zero of=jail0.img bs=1 count=1 seek=4294967296

This creates an empty 4gb file that takes up about 64k on disk, because it is what is called a "sparse file". More on that later/elsewhere.

The next step is to put a filesystem on this disk image. To do that, you first have to mount the disk image loopback, like so:

   mdconfig -f jail0.img

This will print the md device this file is using, usually md0. Now we're ready to put the filesystem on, like so

   newfs /dev/md0

At this point, the image file takes up about 2MB on disk.

Now you can mount this disk image somewhere and install a jail to it like you would with any jail. See Jail_building for more details. Once you've done that, you'll want to make the jail available at startup by adding a line like this to your fstab:

   md /path/to/mount/your/jail0     mfs -F/path/to/jail0.img,-P,rw     2 0

Now you can add this jail to rc.conf as normal.

The point of this is that it lets you easily move jails between hosts. One small note: moving/copying sparse files (locally and between machines) requires care. Using standard tools causes the file to take up the entire size of the file. Instead, use rsync or gnutar (bsdtar currently lacks support for sparse files).

Personal tools