Proper way to execute zfs jail at jail startup

James Gritton jamie at gritton.org
Thu May 4 13:04:28 UTC 2017


On 2017-05-03 08:05, joris dedieu wrote:
> Hi guys,
> Is there a clean way to execute _zfs jail $jid $dataset_ at jail
> startup ? I have tried with an exec.poststart script but it's too late
> in start order. I also tried to use a prefixed jid and exec.prestart,
> but zfs complains that jail does not exists.
> 
> Any idea ? Something I missed ?

It sounds like what you need is a hook for running host-level commands 
after the jail is created but before anything is run from exec.start.  
Unfortunately there is no such parameter - there probably should be.  
There probably also should be a simpler zfs option to jail(8).  But 
those are future concerns.

A workaround is to have nothing in exec.start.  exec.poststart would 
first run the "zfs jail" command, and then do the exec.start work.  
Something like:

   exec.poststart += "zfs jail $jid $dataset";
   exec.poststart += "jexec $jid sh /etc/rc";

It's not a particularly clean solution, but it should work.

- Jamie


More information about the freebsd-jail mailing list