# How to export and mount ZFS as READ-ONLY in jail?



## ikevinjp (Feb 14, 2012)

What is the easiest way to export a ZFS filesystem (created using "zfs create ..." command) and mount it as READ-ONLY in a jail? 

The ZFS filesystem can be either create in the global (non-jail) environment, or within another jail.


----------



## SirDice (Feb 14, 2012)

`# zfs create -o mountpoint=/usr/ports tank/FreeBSD/ports`
`# mount -t nullfs -o ro /usr/ports /jail/myjail/usr/ports`

You can add that line to, for example /etc/fstab.myjail:

```
/usr/ports                      /jail/myjail/usr/ports                nullfs  ro      0       0
```

And in /etc/rc.conf:

```
jail_myjail_mount_enable="YES"
```
Then it'll be automatically mounted/unmounted when the jail starts/stops.


----------



## ManBitesDog (Mar 9, 2014)

Hi,

Pardon the necrobump, but is storing a /etc/fstab.jailname on the host system still the proper way of doing mounting to it, or has that functionality been moved to /etc/jail.conf?

Thanks!


----------



## fonz (Mar 9, 2014)

ManBitesDog said:
			
		

> is storing a /etc/fstab.jailname on the host system still the proper way of doing mounting to it, or has that functionality been moved to /etc/jail.conf?


When I set 
	
	



```
jail_test_allow_mount="YES"
```
 for a test jail, it looks for a /etc/fstab.test file, but if I understand the jail(8) manual correctly, it's _also_ possible to manage the mounting through /etc/jail.conf. Moreover, I'm not entirely sure but I seem to remember that configuring jails in /etc/rc.conf is deprecated and /etc/jail.conf should be used instead.

Please note that the above applies to FreeBSD 9, things may be different in FreeBSD 10. So if you're using the latter, I suggest you just try it out.


----------

