# zfs in jail auto mount issue



## Noodle (Nov 3, 2011)

Hi Forum,

Don't know if this right place to ask, this is a question regarding to zfs in jail and auto mount.

I created a jail to install mysql database, and database data folder on zfs. So on host: I created zfs and set jailed=on.

Now I installed jail, and on host I run [cmd=]zfs jail <jid> tank/data/mysql[/cmd] to export zfs to jail, and inside jail, I run [cmd=]zfs mount -a[/cmd] and set dbdir of mysql to /mnt/tank/data/mysql. So far so good.

Now the problem is automate. I want my jail start during system boot. So db jail been added into host's /etc/rc.conf. And I need a poststart script to run [cmd=]_jail_id = $(cat /var/run/jail_db.id)[/cmd] and then [cmd=]zfs jail ${_jail_id} tank/data/mysql[/cmd]

I had to put it into poststart, because before that, there's no JID. But poststart means jail already started (include all services), and mysql already started and using /mnt/tank/data/mysql, which not a zfs mount as data dir. so /mnt/tank/data/mysql is cannot mounted in db jail.

I believe this is common usage of zfs in jail, so I must did something wrong. probably not in poststart? Any tip?

Thanks a lot

Noodle


----------



## SirDice (Nov 3, 2011)

Why don't you just mount it from the host? That's what I do.


```
root@molly:~#zfs list -r tank/FreeBSD/jails/j2
NAME                          USED  AVAIL  REFER  MOUNTPOINT
tank/FreeBSD/jails/j2        1.03G  1.27T   993M  /jails/j2
tank/FreeBSD/jails/j2/mysql  61.5M  1.27T  61.5M  /jails/j2/var/db/mysql
```


----------



## Noodle (Nov 3, 2011)

Because I want to maintain zfs inside db jail, for example: take snapshot.


----------



## Noodle (Nov 3, 2011)

also, if everything can mount from host, why export zfs to jail?


----------



## SirDice (Nov 3, 2011)

Because I want a separate filesystem for the MySQL databases. That should make updating the jail a little easier.


----------



## Noodle (Nov 3, 2011)

So, zfs cannot be auto mount in jail?


----------

