# NFS sharing using ZFS and/or /etc/exports



## fitz (Nov 30, 2014)

Hello,

Being very new to FreeBSD, and moving from Linux, I am getting a bit confused as to how it is best to create a NFS share on my FreeBSD server. I am running FreeBSD 10.1 on ZFS and have created a dataset that I want to share called zroot/Media. I set a mountpoint for my dataset: `# zfs set mountpoint=/mnt/Media zroot/Media`. I have (hopefully) shared my ZFS dataset using: `# zfs set sharenfs=on zroot/Media`.

I had continuous problems mounting this share (they were erratic, and hard to pin down being new to FreeBSD and making too many changes at once before testing. Too eager.)

However, from a Linux client, `showmount -e 192.168.1.10` pointed me in the direction of RPC errors. To remedy this, I added the following to /etc/rc.conf of my FreeBSD server. 
	
	



```
rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_flags="-r"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
```
At this point, I was starting to find myself a little overwhelmed at the differing advice that I found searching via Google for information.

The above helped remove my RPC errors when performing a manual mount from a Linux client: `mount 192.168.1.10:/mnt/Media /mnt/Media`

Coming from Linux, I thought that it may be necessary to add an /etc/exports file, but, I decided to stop and ask before everything became a huge mess.

What I would like to achieve is a NFS share of my zfsroot/Media dataset, which is picked up by Linux clients in "Browse Network" (as my FreeNAS server is) and able to mount via /etc/fstab and/or `mount 192.168.1.10:/mnt/Media /mnt/Media` on a Linux client, the former /mnt/Media being a directory on my Linux client.

Many thanks everyone.

[I hope that my post is not too confusing?  Perhaps I should have asked earlier/documented my steps a little more clearly - being new to FreeBSD I got a little carried away!]


----------



## getopt (Nov 30, 2014)

fitz said:


> Coming from Linux, I thought that it may be necessary to add an /etc/exports
> file, but, I decided to stop and ask before everything became a huge mess.....


Without /etc/exports nfsd(8) does not know what should be served. See exports(5).


----------



## fitz (Nov 30, 2014)

Thanks for that reply getopt.

I did use an /etc/exports originally, out of habit, but then commented it out and re-booted - my confusion was over what parameters were needed with FreeBSD for a browse-able r/w NFS share.

[I am still managing to access the share without this file, but, it is 'flaky' - it takes at least 30 seconds to mount using 
	
	



```
mount 192.168.1.10:/mnt/Media /mnt/Media
```
 - however, just to add further confusion, I have seen that there is currently a reported bug with my Fedora Client OS (Fedora 21 beta) using `mount` with NFS shares.]

I am very happy to go ahead with your suggestion, but, please could you expand a little? 

I am looking for a generally accepted 'best practice guide' when it comes to configuring ZFS NFS shares on FreeBSD - as - I have read too many conflicting articles! 

Therefore, please could someone let me know what exactly I should be doing, and, in reference to /etc/exports , which commands should I use for FreeBSD to enable my read/write NFS share to be browse-able and which entries are needed within /etc/rc.conf please?

Many thanks.


----------



## getopt (Nov 30, 2014)

You can mount ZFS filesystems on startup by using the zfs(8) option mountpoint. In this case you must not use /etc/fstab for that.

The other way is setting 
	
	



```
mountpoint=legacy
```
 Doing so you have to use /etc/fstab or do the mounting manually.


----------



## fitz (Nov 30, 2014)

Hi getopt,

However, I need to mount my NFS share on Linux clients - is this still what you mean, or have I got your reply confused?

Many thanks.


----------



## getopt (Nov 30, 2014)

As far as I know Linux has no ZFS. As this is a FreeBSD forum my advice is strictly related to FreeBSD only. 

IMHO you should be able to mount NFS on any OS that makes use of it. The difference, if any, can be found reading the manpages of the distro used.

Just to add some confusion , there are different NFS versions. Make sure you use the same on the clients as on the server. The latest version is NFSv4 which should be used if security is a concern. Anyway I’d first starting with NFSv3.

Have a look in the log files. They tell you if you are doing right or give hints otherwise. This is true for any OS.


----------



## fitz (Nov 30, 2014)

Hi getopt,

Ah no, I have no interest in any advice re:Linux clients thanks  I just want to know what the recommended configuration advice is for a FreeBSD server to share a ZFS dataset via NFS. I can't find any documentation that summarises the requirements. From what I have gleaned from various documentation, I have used the following configuration:



fitz said:


> I set a mountpoint for my dataset:  # zfs set mountpoint=/mnt/Media zroot/Media. I have (hopefully) shared my ZFS dataset using: # zfs set sharenfs=on zroot/Media.





fitz said:


> I added the following to /etc/rc.conf of my FreeBSD server.
> 
> 
> 
> ...





fitz said:


> I thought that it may be necessary to add an /etc/exports file





fitz said:


> What I would like to achieve is a NFS share of my zfsroot/Media dataset, which is picked up by Linux clients in "Browse Network" (as my FreeNAS server is) and able to mount via /etc/fstab and/or  mount 192.168.1.10:/mnt/Media /mnt/Media on a Linux client, the former /mnt/Media being a directory on my Linux client.



Ideally a checklist of recommended steps?

Thanks again.


----------



## getopt (Nov 30, 2014)

fitz said:


> I thought that it may be necessary to add an /etc/exports file.


I should have pointed more clearly to zfs(8):



> sharenfs=on | off | opts
> 
> Controls whether the file system is shared via NFS, and what options are used. A file system with a sharenfs property of off is managed the traditional way via exports(5).  Otherwise, the file system is automatically shared and unshared with the "zfs share" and "zfs unshare" commands. If the property is set to on no NFS export options are used. *Otherwise, NFS export options are equivalent to the contents of this property. The export options may be comma-separated. See exports(5) for a list of valid options.*
> 
> ...



Which means you could do either the exports(5) *or* the 
	
	



```
sharenfs=on
```
 method.

Have a look on this: http://lists.freebsd.org/pipermail/freebsd-current/2008-March/084102.html

If you use the ZFS method the mount options you would set in /etc/exports are set like this: 
	
	



```
zfs sharenfs="-maproot=root -alldir -network 10.0.0.3 -mask
255.255.255.255" myzpool/test2
```
And there is a /etc/zfs/exports which you could use also instead.


----------



## fitz (Nov 30, 2014)

Thank you 

I missed those vital paragraphs - I really appreciate you highlighting them


----------



## Oko (Dec 1, 2014)

getopt said:


> As far as I know Linux has no ZFS. As this is a FreeBSD forum my advice is strictly related to FreeBSD only.


You are wrong about that. ZFS is available for example on Red Hat 6.6 as a kernel module. While personally I don't run ZFS on Linux in production at the moment I have collegues who swear by ZFS on Linux.


----------



## fitz (Dec 1, 2014)

Hi Oko,

ZFS is not native to the Linux kernel (as yet), but is available as a package/repo from ZFSonLinux.org, and not available through Red Hat/Fedora Repositories.  I have used it many times myself, but, not being integrated, it is rather fragile and I have run into recovery problems due to this in the past. 

However, this is a separate issue from my question.  but thanks 



fitz said:


> how it is best to create a NFS share on my FreeBSD server. I am running FreeBSD 10.1 on ZFS and have created a dataset that I want to share called zroot/Media





fitz said:


> Ah no, I have no interest in any advice re:Linux clients thanks


----------



## fitz (Dec 1, 2014)

So, in summary, what out of the following would be best included in /etc/rc.conf to ensure reliable connection to my FreeBSD server by [Linux] clients please?



fitz said:


> /etc/rc.conf of my FreeBSD server.
> 
> 
> 
> ...


----------



## phoenix (Dec 1, 2014)

Ignore the ZFS side of things completely.

Set up NFS on FreeBSD the same way you normally would for a non-ZFS system:

Edit /etc/rc.conf to enable all the NFS, mountd, statd, lockd, etc daemons needed,
Edit /etc/exports to export the filesystems you want,
Mount the filesystems over NFS from the clients
The sharenfs property in ZFS is only useful for Solaris-based OSes where they have an NFS server built-into the storage stack and manageable via the ZFS tools.  On FreeBSD, the sharenfs property gets dumped into /etc/zfs/exports and mountd(8) loads it the same as it load /etc/exports; you still have to do all the NFS management the same as for non-ZFS setups.  On other OSes, sharenfs isn't even supported.


----------



## fitz (Dec 2, 2014)

Hi phoenix,

Thanks for your reply.

However, please could you (or someone?) be specific as to which daemons/entries are needed in /etc/rc.conf?



phoenix said:


> Edit /etc/rc.conf to enable all the NFS, mountd, statd, lockd, *etc* daemons needed



Many thanks everyone!


----------



## getopt (Dec 2, 2014)

If I were to find out which is the minimum to configure in /etc/rc.conf, I’d look at the script starting a service. Those scripts can been found in /etc/rc.d. For ntpd one could do `less /etc/rc.d/ntpd` and look what it does. (Surprisingly) it starts two other services which are needed. At this point one can consider looking at the two other scripts too, just for extending the experience.

For rounding this up: /etc/rc.conf only does customizing what already has been set by default in /etc/defaults/rc.conf. If curious do `grep nfs /etc/defaults/rc.conf`. You can see that by default some flags are set for nfsd. These flags can be changed in /etc/rc.conf if there is a need to do so.


----------



## SirDice (Dec 2, 2014)

At the very least you need to have rpcbind(8), mountd(8) and nfsd(8) running. You can start them individually but the simplest solution is just to add 
	
	



```
nfsv4_server_enable="YES"
```
 to rc.conf. The script will take care of everything else.


----------



## fitz (Dec 4, 2014)

getopt said:


> If I were to find out which is the minimum to configure in /etc/rc.conf, I’d look at the script starting a service. Those scripts can been found in /etc/rc.d. For ntpd one could do `less /etc/rc.d/ntpd` and look what it does. (Surprisingly) it starts two other services which are needed. At this point one can consider looking at the two other scripts too, just for extending the experience.



Such a great insight for me - this is terrific!

What a great bit of advice - thank you @getopt


----------



## fitz (Dec 4, 2014)

Finally, please could someone advise how I could make the NFS share show up under 'browse network' / a network explorer ?

I'm guessing that it is a property added to the /etc/exports entry - but I would love to hear any advice?

Thanks everyone.


----------



## SirDice (Dec 4, 2014)

fitz said:


> Finally, please could someone advise how I could make the NFS share show up under 'browse network' / a network explorer?


That's usually SMB/CIFS (Windows file and printer sharing) not NFS.



> I'm guessing that it is a property added to the /etc/exports entry - but I would love to hear any advice?


There's no setting for this.  On some Unix Desktop Environments you may be able to get it to show up using net/avahi. It's not something that's build into NFS as it is with Windows' Network neighborhood.


----------



## fitz (Dec 4, 2014)

Thank you SirDice - what I am trying to achieve is the same presence that I (used to) get from my FreeNAS box within a Linux network browser.

However, this doesn't appear to be happening anymore, so, I had better go away and scratch my head a bit whilst looking bemused...

I'll look into your notes 

OK - edit - I'm not crazy - after 10 minutes live, my FreeNAS server appears in 'Browse Network' as "freenas" and is browsable - I did not need to manually mount it - and I have only set up NFS shares on it.

It would be a very nice facility to have - then no need for Samba.

EDIT:  OK - apologies - further investigation has shown it to be a Windows Share that  I wasn't aware of (setting up?) - it was tempting to remove this post - but - shamefully I will leave it on in the hope that it might help someone from making my mistake - ho ho.


----------



## fitz (Dec 14, 2014)

Hi all,

I'm honestly not trying to add confusion to this thread. However, this is what I have just read from the handbook, so, I have been left confused again...



> *29.3 Network File System (NFS)*
> 
> These daemons must be running on the server:
> 
> ...





> *29.3.1 Configuring the Server*
> 
> To enable the processes required by the NFS server at boot time, add these options to /etc/rc.conf:
> 
> ...





> *29.3.3. Locking*
> Some applications require file locking to operate correctly. To enable locking, add these lines to /etc/rc.conf on both the client and server:
> 
> 
> ...



As I am currently re-building my FreeBSD server, I am trying a process of elimination, but, I thought that I would add to this thread what I have found in case it helps anyone/promotes discussion


----------



## fitz (Dec 14, 2014)

Just to 'add to the mix' - which should I use?


```
nfs_server_enable="YES"
nfsv4_server_enable="YES"
```
 or both?

I ask, as, (I'm aware of my incorrect syntax!) the error from my FreeBSD server is as follows:


```
root@backup5:/usr/home/fitz # service nfsd restart
Cannot 'restart' nfsd. Set nfs_server_enable to YES in /etc/rc.conf or use 'onerestart' instead of 'restart'.
```

Thanks everyone


----------



## getopt (Dec 14, 2014)

You can look up the answer in the manual for rc.conf(5). There is a description how to use the option nfsv4_server_enable.


----------



## fitz (Dec 14, 2014)

Thanks yet again getopt. 

Shamefully I wasn't referring to these links - read the manual Fitz!


----------

