Thursday, June 30, 2011

Exporting ZFS filesystem over NFS

First you need to install nfs-kernel-server. You also need a later kernel: 2.6.35 or better

Install zfs native (or zfs-fuse):

sudo add-apt-repository ppa:dajhorn/zfs
sudo apt-get update
sudo apt-get install ubuntu-zfs 

By default NFS sharing is off. To export a zfs filesystem, say zfs/home:

#Setup shared FS
zfs create -o compression=on -o atime=off -o sharesmb=on zfs/home

#export RO
zfs set sharenfs=ro zfs/home

#stop exporting. Also for next command to take effect
zfs set sharenfs=off zfs/home  

# export RW, fsid needs to be unique per filesystem
zfs set \
 sharenfs=,fsid=100,no_subtree_check,async,no_root_squash zfs/home

# add this to /etc/rc.local
zfs share -a

#To mount from OSX use the following command. -P option is for secure (<1024) ports
mount_nfs -P${USER} /mnt/home

Later invocations override earlier, so to export RW to only one host and RO to others:

zfs set sharenfs=off zfs/backup
zfs set sharenfs=,no_subtree_check,async,no_root_squash zfs/backup
zfs set sharenfs=,no_subtree_check,async,no_root_squash zfs/backup

The host writing the backup is and will get read/write access. The rest will get read only access.

Note: Setting the mountpoint property of a ZFS dataset to anything other than the default pool/dataset will cause it to be exported with all_squash. Do not change the mountpoint if you want to NFS share a dataset

If you are getting a lot of stale NFS handles, the IO requests are timing out before they can be serviced due to heavy IO load. Mount your NFS shares using these options (example fstab entry):

server:/zfs/dataset    /mnt       nfs     defaults,timeo=20,retrans=5,rsize=8192,wsize=8192,intr    0       0

The timeo to 2 seconds from default of 0.7 seconds is the most important attribute.


sstatik said...


I have create a pool on my fileserver mounted under /storage with a zfs folder called private

If I follow your guide and enter:
sudo zfs set sharenfs=,no_subtree_check,async,no_root_squash storage/private

I get this error:
cannot set property for 'storage/private': 'sharenfs' cannot be set to invalid options

I can share /storage/private if I enter:
sudo zfs set sharenfs=on storage/private
and I can mount this share on a remote ubuntu machine but I lose this share when the fileserver is rebooted.

Any idea how I can get the share to survive a reboot?

cadaver said...

without the your share is probably exported read only. Try

To survive reboots, you need to add the following line to /etc/rc.local

zfs share -a