Quick & Dirty NFS
By Brian Leonard on Feb 24, 2011
NFS is such as well known topic and so well documented that I hesitate to write about it. However, I find it crucial in my everyday use of Solaris, so I thought I'd at least summarize the quick steps I take to share files, if only for my own future benefit.
NFS stands for Network File System. NFS was invented by Sun years ago and it is the premier way to share files between systems (although Microsoft will argue CIFS / SMB fits that bill).
One thing I find confusing about NFS is that it provides several different utilities for creating and managing shares. This is an artifact of NFS's maturity, as it has been around well before newer file systems like ZFS. NFS is now tightly integrated with ZFS and in this entry I'm only going to focus on how NFS is configured via ZFS.
On the Server
The first step is to figure out which file system you want to share. For this exercise I'm going to create a new ZFS file system for the sole purpose of sharing files:
10.0.1.20:~$ sudo zfs create rpool/export/home/bleonard/share Password:
I'll also change the ownership and write permissions of the shared directory so anyone can write to it:
10.0.1.20:~$ sudo chown bleonard:staff share Password: 10.0.1.20:~$ sudo chmod 777 share Password:
Note, the NFS server is disabled by default:
10.0.1.20:~$ svcs nfs/server STATE STIME FMRI disabled Feb_14 svc:/network/nfs/server:default
However, setting the sharenfs property on the ZFS dataset will also start the NFS server:
10.0.1.20:~$ sudo zfs sharenfs=on rpool/export/home/bleonard/share 10.0.1.20:~$ svcs nfs/server STATE STIME FMRI online 7:38:27 svc:/network/nfs/server:default
At this point the share is ready for use. If you use an existing dataset, it only takes one command to set up.
Another useful utility is the showmount command, which will show the file systems that have been shared:
10.0.1.20:~$ showmount -e export list for solaris: /export/home/bleonard/share (everyone)
Note, sharing can also be viewed and managed via the GUI at System > Administration > Shared Folders:
On the Client
These instructions assume a Solaris client. Instructions can be easily found for other clients as well.
You can use the showmount command to list which shares are provided by a particular server:
10.0.1.24:~$ showmount -e 10.0.1.20 export list for 10.0.1.20: /export/home/bleonard/share (everyone)
My favorite way to access NFS shares is via the automounted /net directory. For example:
10.0.1.24:~$ cd /net/10.0.1.20/export/home/bleonard/share/ 10.0.1.24:/net/10.0.1.20/export/home/bleonard/share$
And that's all there is to it!
If you want to mount the share to a different location, you do so as follows (I'm using the name share again, but the directory could be anywhere and called anything):
10.0.1.24:~$ mkdir share 10.0.1.24:~$ sudo mount -F nfs 10.0.1.20:/export/home/bleonard/share ~/share Password:
To make the mount permanent (that is, survive a reboot), there are a couple of options, one of which is adding an entry to the /etc/vfstab file. That process is well documented in How to Mount a File System at Boot Time.