# Creating jails and simply copying them



## kpedersen (Apr 27, 2011)

Hello,

I have just performed a:-


```
# cd /usr/src
# make buildworld
# make installworld DESTDIR=/usr/jails/john
# make distribution DESTDIR=/usr/jails/john
```

Is it possible to simply copy /usr/jails/john to /usr/jails/sally or do I need to use the *make installworld* and *make distribution* to do it?

Can I simply tar.gz up the /usr/jails/john directory or does it contain hardcoded links?

The issue is that I need to create some jails on many machines and would like to avoid the compilation on each of the machines.

Best Regards,


----------



## anomie (Apr 27, 2011)

Yes, you can create a "baseline" jail and then use it to create more jails. The sysutils/cpdup utility works nicely for this purpose.


----------



## mhunet (Apr 27, 2011)

Get sysutils/cpdup and then:
[CMD=]cpdup /usr/jails/john to /usr/jails/sally[/CMD]

I recommend creating a template though in /usr/jails and [CMD=]cpdup /usr/jails/template /usr/jails/newjail[/CMD] instead of copying from an existing jail.


----------



## kpedersen (Apr 28, 2011)

Ah brilliant,

I was worried I was going to need to copy a prebuilt /usr/src directory around just to execute *make install* on each client.

Thanks!


----------



## SirDice (Apr 28, 2011)

kpedersen said:
			
		

> I was worried I was going to need to copy a prebuilt /usr/src directory around just to execute *make install* on each client.


You don't need to copy anything at all. Make use of nullfs(4).

When you are running ZFS creating jails is even easier. Just install in a clean directory, make a snapshot and clone the snapshot as many times as you need :e


----------



## Hety (May 12, 2011)

Try using sysutils/ezjail. Easy and works like a charm.


----------



## Zhwazi (May 13, 2011)

I use ZFS snapshots and nullfs mounts. There's an article in the handbook (http://www.freebsd.org/doc/handbook/jails-application.html) mentioning using nullfs to have a shared root, with only a few directories not being shared (/etc, /root, /usr/local, /var, /tmp, and /home.)

Using nullfs means you don't waste the space of having the same shareable portion of the system occupying 20 different directories, and means that you don't have to run installworld on each of your jails when upgrading the system. Using snapshots for the unshared portion makes those more space efficient as well by using the shareable portions while not being so rigid that you cannot change them. That's not as big a gain though unless you plan to have several jails with all the same software running in them and already installed.


----------



## SirDice (May 13, 2011)

It should also be possible to use mount_unionfs(8). With that you can make a read-only copy of a basic system and overlay it with a writeable filesystem. The writeble filesystem will store the changes you make. 

I've never tried it though.


----------

