# using nullfs in /etc/fstab



## kusanagiyang (Dec 23, 2016)

Hello,

I can do these through shell
`mount -t nfs 192.168.9.60:/mnt/nas60/oc /mnt`
`mount -t nullfs /mnt/120 /usr/jails/120/mnt`
When I tried to do this at boot time through /etc/fstab, this line works

```
192.168.9.60:/mnt/nas60/oc        /mnt      nfs    rw    0    0
```
But this line,

```
/mnt/120       /usr/jails/120/mnt     nullfs    rw     0      0
```
boot message stated:

```
mounting local filesystems: mount_nullfs: /mnt/120: No such file or directory
```
then it went to single user mode....

I cannot figure out why...  help please


----------



## tobik@ (Dec 23, 2016)

Local filesystems are mounted first, then remote filesystems. When FreeBSD tries to mount /mnt/120192.168.9.60:/mnt/nas60/oc isn't mounted on /mnt yet. Add the late option to the nullfs entry in /etc/fstab to mount it later in the boot sequence after networking is up and all remote filesystems have been mounted:

```
/mnt/120 /usr/jails/120/mnt nullfs rw,late 0 0
```


----------



## SirDice (Dec 23, 2016)

Don't add it to /etc/fstab if it's specific for this jail. Make use of /etc/fstab.<jailname> to mount it "on-the-fly" when the jail starts.


----------



## al mello (Aug 19, 2017)

Folks,



SirDice said:


> Don't add it to /etc/fstab if it's specific for this jail. Make use of /etc/fstab.<jailname> to mount it "on-the-fly" when the jail starts.


Trying to do the above for my nextcloud jail and if I mount on the host fstab works:

```
# Device        Mountpoint      FStype  Options Dump    Pass#
/dev/ada0s1a    /               ufs     rw      1       1
/dev/ada0s1b    none            swap    sw      0       0
/raid/data/cloud /raid/jails/nextcloud/mnt/data nullfs rw,late 0 0
```
But if instead I create a /etc/fstab.nextcloud as:

```
# Device        Mountpoint      FStype  Options Dump    Pass#
/raid/data/cloud /raid/jails/nextcloud/mnt/data nullfs rw,late 0 0
```
Removing the nullfs 
	
	



```
/raid/data/cloud /raid/jails/nextcloud/mnt/data nullfs rw,late 0 0
```
 from /etc/fstab, it won't mount to: 
	
	



```
/raid/jails/nextcloud/mnt/data
```
 In fact:

It mounted to itself:

```
root@bsdlab:~ # df
Filesystem                          1K-blocks     Used      Avail Capacity  Mounted on
/dev/ada0s1a                        223440536  2698920  202866376     1%    /
devfs                                       1        1          0   100%    /dev
raid/iohyve                        1765163361       19 1765163342     0%    /iohyve
raid/iohyve/Firmware               1765163361       19 1765163342     0%    /iohyve/Firmware
raid/iohyve/ISO                    1765163361       19 1765163342     0%    /iohyve/ISO
raid/iohyve/ISO/freebsd111boot.iso 1765469612   306270 1765163342     0%    /iohyve/ISO/freebsd111boot.iso
raid/iohyve/ISO/pfsense234.iso     1765805713   642371 1765163342     0%    /iohyve/ISO/pfsense234.iso
raid                               1765163363       21 1765163342     0%    /raid
raid/data                          1765163361       19 1765163342     0%    /raid/data
raid/data/cloud                    1765163362       19 1765163342     0%    /raid/data/cloud
```
And the jail is auto starting.

What I'm missing here?


----------



## ShelLuser (Aug 19, 2017)

al mello said:


> Trying to do the above for my nextcloud jail and if I mount on the host fstab works:


A few things... why use the late option in the jail fstab? There's no need for that, remove it.

I also don't quite understand what you meant to say with 'removing the nullfs'.

When using the jail fstab did you remove the line from the main fstab? To my knowledge that shouldn't interfere but it's always good to be safe. Also: did you set up mount.fstab in /etc/jail.conf? I assume as much but I just want to make sure. The fstab file is not something which will automatically work unless you specify its use in your jail configuration.


----------



## al mello (Aug 19, 2017)

ShelLuser said:


> A few things... why use the late option in the jail fstab? There's no need for that, remove it.


Just following the yellow brick road above, will remove.


> I also don't quite understand what you meant to say with 'removing the nullfs'.


From /etc/fstab when added to /etc/fstab.jail.


> When using the jail fstab did you remove the line from the main fstab? To my knowledge that shouldn't interfere but it's always good to be safe.


Yeap.


> Also: did you set up mount.fstab in /etc/jail.conf? I assume as much but I just want to make sure. The fstab file is not something which will automatically work unless you specify its use in your jail configuration.


That is probably what I've missed. Will add that to jail.conf under that jail section and test.
Thanks!


----------



## al mello (Aug 19, 2017)

*For future reference*

1 - Create mount point inside the jail tree (i.e.:_* /raid/jails/nextcloud/mnt/data*_) and the directory to be mounted from the host (i.e.: _*/raid/data/cloud*_);
2 - Create a /etc/fstab.<jail_name> (i.e.: _*/etc/fstab.nextcloud*_);

```
# Device        Mountpoint      FStype  Options Dump    Pass#
/raid/data/cloud /raid/jails/nextcloud/mnt/data nullfs rw,late 0 0
```
3 - Add _*mount.fstab = "/etc/fstab.${name}";*_ to /etc/jail.conf;


```
# Common configs for all jails
mount.fstab = "/etc/fstab.${name}";
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
host.hostname = "$name.mydomain.com";
mount.devfs;
path = "/raid/jails/$name";
# nextcloud jail
nextcloud {
ip4.addr = "10.10.10.31";
interface = em0;
}
```
You won't see the mount inside the jail if using df:

```
root@nextcloud:/ # df
Filesystem            1K-blocks    Used      Avail Capacity  Mounted on
raid/jails/nextcloud 1766666242 1502557 1765163684     0%    /
```
But is mounted ...

```
root@nextcloud:/ # exit
exit
root@bsdlab:~ # echo this_is_a_test > /raid/data/cloud/new_file
root@bsdlab:~ # ll /raid/data/cloud/
total 2
-rw-r--r--  1 root  wheel   2 Aug 19 03:51 b
-rw-r--r--  1 root  wheel  15 Aug 19 13:50 new_file
root@bsdlab:~ # jexec 1
You have mail.
root@nextcloud:/ # ll /mnt/data
total 2
-rw-r--r--  1 root  wheel   2 Aug 19 03:51 b
-rw-r--r--  1 root  wheel  15 Aug 19 13:50 new_file
root@nextcloud:/ # cat /mnt/data/new_file
this_is_a_test
root@nextcloud:/ #
```


----------



## ShelLuser (Aug 19, 2017)

al mello said:


> You won't see the mount inside the jail if using df:


Keep in mind though that this is fully configurable, see jails(8) for more information on that. In specific: enforce_statfs is responsible for this behavior. Its default value of 2 basically prevents the Jails system calls to detect other mounts other than the root. When set to 1 only mounts below the root directory become visible and when set to 0 everything becomes visible.

I seriously suggest to go over that manualpage because there's a lot which you can finetune (though the default settings are pretty solid too of course).


----------

