# mfs (tmp) inside a jail?



## mamalos (Mar 17, 2010)

Hi everybody,

could anybody tell me how I could mount /tmp on a memory filesystem inside my jails? My jail's /etc/rc.conf reads:


```
tmpmfs="YES"            # Set to YES to always create an mfs /tmp, NO to never
tmpsize="128m"          # Size of mfs /tmp if created
tmpmfs_flags="-S"       # Extra mdmfs options for the mfs /tmp
```
but it won't start. If I jexec in that jail, and use dd and mdconfig to create a vnode of the filesize I wish, and then execute:


```
# mount /dev/md4 /tmp
mount: /dev/md4 : Operation not permitted
```
I get the aforementioned error. My /etc/devfs.rules in jail 0 (host) unhides md* devices, hence I am able to create the vnode, and security.jail.mount_allowed=1 in jail 0 as well.

If for some reason this "type of" mount is not allowed inside the jail, I wouldn't have a problem to do it via jail 0, as long as the tmp filesystem gets mounted before the jail scripts are executed.

Thank you all in advance.


----------



## SirDice (Mar 17, 2010)

The answer is in the jail(8) man page:



> *Jails and File Systems*
> It is not possible to mount(8) or umount(8) any file system inside a jail unless the file system is marked jail-friendly and the jail's allow.mount parameter is set.


----------



## mamalos (Mar 17, 2010)

Thanks SirDice,

this means that since lsvfs does not return mfs, this type of filesystem cannot be mounted inside the jail (I assumed that since my sysctl variable security.jail.mount_allowed=1, the second limitation is out). On the other hand, I see that tmpfs is supported, which is also a memory filesystem, but is considered experimental (at least that's what my logs complain about when I use it); does this mean I could use tmpfs instead of mfs by adding it to the jail's fstab (ok, I could add it to jail's 0 fstab too)?

And, finally, is there a way I could use rc.conf's (of jail 0) tmpmfs directives (so as to diverge from tmpfs if experimental) to mount the mfs filesystem in another path (the jail's path, and maybe in more than one jail)?

Thanx again.


----------



## mamalos (Mar 17, 2010)

...and one more thing:

man tmpfs says that the size option could be used to configure the filesystem's size. When I put size=12m in fstab and mount the tmpfs, the mounted filesystem has the size of my total memory. Where should I put the size option for it to work properly?


----------



## SirDice (Mar 17, 2010)

mamalos said:
			
		

> man tmpfs says that the size option could be used to configure the filesystem's size. When I put size=12m in fstab and mount the tmpfs, the mounted filesystem has the size of my total memory. Where should I put the size option for it to work properly?


Try using the actual number of bytes i.e. 12582912 (12*1024*1024).


----------



## SirDice (Mar 17, 2010)

mamalos said:
			
		

> does this mean I could use tmpfs instead of mfs by adding it to the jail's fstab (ok, I could add it to jail's 0 fstab too)?


I would add it to the jail's fstab.

Host's /etc/rc.conf:

```
jail_myjail_mount_enable="YES"
```

Then add the filesystems to /etc/fstab.myjail on the host. These will get mounted/unmounted when the jail starts/stops. AFAIK mount_allowed isn't needed for that.


----------



## mamalos (Mar 17, 2010)

thanx SirDice, it worked that way,

any comments/solutions on my forelast post (mfs isntead of tmpfs which is considered experimental)? I am working on a production system, hence my worries.


----------



## fronclynne (Mar 17, 2010)

I've been using tmpfs(5) for a couple of months on an old laptop without any problems (including while building world & kernel).

If http://wiki.freebsd.org/TMPFS is to be believed (it was last updated 2008-06-17) it's missing a couple of features and hasn't been as heavily tested on SMP systems, but again, I have had exactly zero stability issues and it reads & writes about twice as fast as mdmfs(8) on i386.


----------

