# Management tool for ZFS jails with VNET



## zulu (Jun 1, 2012)

Just a quick note for anyone who might be interested in ZFS jails management with VNET.

I've created a script called zjail and is available from sourceforge here:
http://sourceforge.net/projects/zjails/

Some of the available features:

templating
VNET support
hot cloning
thin & thick creation
replication (with helper script and zfsnap)
up to 3 vnet (epair) interfaces per jail
start and stop (boot/BP) prioritization
soft and cold restart
See README for more info.

It is in early stages (expect bugs) but quite usable for non production work loads.

Peter


----------



## zennybsd (Nov 5, 2013)

Hi Peter:

It seems to be a nice script with vnet support. BTW, is this included into the ports? It would be nice if it is included into FreeBSD ports.


----------



## gkontos (Nov 5, 2013)

This looks very interesting indeed. I will certainly try it.


----------



## zulu (Nov 6, 2013)

I am interested to hear your feedback guys, so please report back once you've tested it. There is a new port request PR 181959 for this in PR, but stagnating a bit. Would be nice to have it in the ports tree to get a bit of traction and hammer out the last bits and pieces.

For now you can download the zjail-0.7-port.tar.gz archive and just do a `make install`.


----------



## zennybsd (Nov 6, 2013)

*Error on FreeBSD10-Beta3 fresh install*

@Zulu/Peter: Find attached the output of `make install` in FreeBSD10-Beta3, fyi.


----------



## zulu (Nov 6, 2013)

Let me check that, I need to fire up a 10-BETA3. Have you tried on 9.2 as well?


----------



## zennybsd (Nov 7, 2013)

Nope, I didn't try with 9.2, but with 8.3 with pf-enabled kernel, it failed.


----------



## zulu (Nov 8, 2013)

Just tried with 10-BETA3 and 9.2 same result, the install error shows. Interestingly on 9.1 it is OK. Something must have changed in 9.2, will need to chase that up. The scripts are installed OK though, despite throwing an error.

With 10-BETA3 the FTP pull fails as it isn't a full RELEASE yet. Will be fixing these issues in the next version.


----------



## zennybsd (Nov 8, 2013)

Yep, it got installed (with errors shown) in FreeBSD-10-Beta3 after I moved zjail to the /usr/ports/sysutils folder, and used portmaster.

However, `zjail install` yielded:


```
# zjail install
    Creating base jail ZFS datasets..
    Creating zroot/zjails/jds/local
    Creating zroot/zjails/jds/remote
    Creating zroot/zjails/jds/replicated
    Creating zroot/zjails/jds/templates
 Cannot change working directory /pub/FreeBSD/releases/amd64/10.0-BETA3 : No such file or directory.
```

This is obvious, but how can one create more than one basejails with different versions of FreeBSD say 8.4, 9.2 and 10 using zjail?


----------



## zulu (Nov 9, 2013)

Seem to be a script variable problem, edit zjail and put a 
	
	



```
chomp $release;
```
 statement straight after this variable declaration (it will work). This is a temporary workaround, will be fixed in the next version (soon).

Let me know whether this resolved the problem. You can also use `zjail install itype=src` - this should do a full `make world` and install (takes time!).

PS: Thanks for debugging these issues!


----------



## zulu (Nov 9, 2013)

It is fixed now. Delete your zjail-0.7.tar.gz dist file from /usr/ports/distfiles and reinstall your port. Alternatively downloading the file from Sourceforge and just overwrite the zjail script (don't forget to merge your configuration).


----------



## zennybsd (Nov 9, 2013)

zulu said:
			
		

> Seem to be a script variable problem, edit zjail and put a "chomp $release;" statement straight after this variable declaration (it will work).



which variable are you referring to append?




			
				zulu said:
			
		

> This is a temporary workaround, will be fixed in the next version (soon).



Look forward to!



			
				zulu said:
			
		

> Let me know whether this resolved the problem.



I shall!



			
				zulu said:
			
		

> You can also use "zjail install itype=src" - this should do a full make world and install (takes time!).



But does this (itype=src flag) allow me to have more than one basejail with different versions of FreeBSD?



			
				zulu said:
			
		

> PS: Thanks for debugging these issues!



My pleasure!

BTW, does zjail work with netgraph or only with epair and if_bridge combo? I just compiled my kernel with netgraph and netgraph_bridge and so on because it is discussed over this forum and elsewewhere that netgraph is more reliable. What do you say, Peter?


----------



## zulu (Nov 9, 2013)

It was a trailing space in the $release variable (within zjail) which broke FTP downloads - it is fixed now.

You just need download the fixed version or just put the 
	
	



```
chomp $release;
```
 line after the 
	
	



```
my $release = ...;
```
 line.

Jails should be always at the same release number -  I believe this is best practice, otherwise you can end up with some issues. Zjail was scripted with this in mind - does not support mixing releases. However you could create templates and just overwrite them with any userland you like. Mixing major release numbers though is not a good idea.

Have not tried netgraph yet - only epair which seem to be fairly stable (since at least 9.1 going forward). You can use the soft restart/shutdown option with zjail (default behavior) - this will prevent the known memory leak issue on epair VNET destroy.

You can reach me on my email (listed in zjail script) if you need more info or help.


----------



## zennybsd (Nov 9, 2013)

Appending 'chomp $release;' tried to pull from 11-CURRENT, hmmm..



> # zjail install
> Warning: /zjails/jds/templates/base already exists! - would you like to continue?
> (yes -  will overwrite your base template)
> yes|no: yes
> ...


----------



## zulu (Nov 10, 2013)

That's expected as 11.0-CURRENT is not on the FreeBSD FTP servers, you can use 9.x or 10.x.


----------



## zennybsd (Nov 10, 2013)

zulu said:
			
		

> That's expected as 11.0-CURRENT is not on the FreeBSD FTP servers, you can use 9.x or 10.x.



`zjail install` only tries to pull 11.0-CURRENT, how can I pull eith 9.x or 10.x branch explicitly with zjail?

Tried to work with '`zjail install -r 9.2-RELEASE`' also, but it didn't:


```
# zjail install -r 9.2-RELEASE
   Warning: /zjails/jds/templates/base already exists! - would you like to continue?
    (yes -  will overwrite your base template)
Can't open 9.2-RELEASE: No such file or directory at /usr/local/sbin/zjail line 1392.
Use of uninitialized value $answer in scalar chomp at /usr/local/sbin/zjail line 1393.
Use of uninitialized value $answer in string eq at /usr/local/sbin/zjail line 1395.
Use of uninitialized value $answer in string eq at /usr/local/sbin/zjail line 1395.
Use of uninitialized value $answer in string eq at /usr/local/sbin/zjail line 1399.
Use of uninitialized value $answer in string eq at /usr/local/sbin/zjail line 1399.
Use of uninitialized value $answer in concatenation (.) or string at /usr/local/sbin/zjail line 1403.
 Error: invalid answer:  exiting..
```


----------



## zulu (Nov 10, 2013)

It pulls the release of your currently installed FreeBSD OS. If you are running 11 CURRENT it will try to pull that. There is no support for mixing releases in zjail.

You could hack the $release variable in the script and use 9.2-RELEASE - this is asking for trouble though.

Just install a proper RELEASE (9.1 forward) and it will work.


----------



## zennybsd (Nov 10, 2013)

My oversight, Peter! Actually the problem is because I pulled from SVN head and recompiled the kernel. After I pulled from stable/10 branch and recompiled the kernel, zjail works fine. Thanks for the nice zjail script.


----------



## zennybsd (Nov 11, 2013)

Back again.

After successful zjail install, I tried to create new jails, but ... (see the output)


```
#[CMD]zjail create ip=192.168.69.10 hostname=jail10.local defaultroute=192.168.69.254 netmask=24 jail10[/CMD]
Can't locate Getopt/Lucid.pm in @INC (@INC contains: /usr/local/lib/perl5/5.16/BSDPAN /usr/local/lib/perl5/site_perl/5.16/mach /usr/local/lib/perl5/site_perl/5.16 /usr/local/lib/perl5/5.16/mach /usr/local/lib/perl5/5.16 .) at /usr/local/sbin/zjail line 39.
BEGIN failed--compilation aborted at /usr/local/sbin/zjail line 39.
```


```
#[CMD]zjail list all[/CMD]
Can't locate Getopt/Lucid.pm in @INC (@INC contains: /usr/local/lib/perl5/5.16/BSDPAN /usr/local/lib/perl5/site_perl/5.16/mach /usr/local/lib/perl5/site_perl/5.16 /usr/local/lib/perl5/5.16/mach /usr/local/lib/perl5/5.16 .) at /usr/local/sbin/zjail line 39.
BEGIN failed--compilation aborted at /usr/local/sbin/zjail line 39.
```

Meaning either portmaster could not build GetOpt/Lucid or something wrong with port build script! FYI.

Solved with 
#`pkg install p5-Getopt-Lucid-1.05 and p5-Perl6-Form-0.04`


----------

