What’s NFS
Network File System (NFS) is a protocol which allows file systems on one system to be made available on a remote system on the network. NFS works on the server-client model with server sharing the resource and client mounting it.
NFS versions
The 3 major versions of NFS are :
NFSv2 (very rarely used today. Allows maximum file size of 2GB)
NFSv3 (used in solaris 8 and 9)
NFSv4 (was introduced in solaris 10 )
All three versions utilizes a collection of RPC protocols and daemons as specified below.
Solaris Daemons | RPC Service Name | S10/S11 SMF service | Description |
---|---|---|---|
rpcbind | rpcbind / portmap | svc:/network/rpc/bind:default | RPC “portmapper” |
mountd | mountd | svc:/network/nfs/server:default | MOUNT protocol server |
nfsd | nfs | svc:/network/nfs/server:default | NFS server |
lockd | nlockmgr | svc:/network/nfs/nlockmgr:default | network lock manager (aka NLM) |
statd | status | svc:/network/nfs/status:default | RPC status monitor |
nfs4cbd | N/A | svc:/network/nfs/cbd:default | NFSv4 callback daemon |
nfsmapid | N/A | svc:/network/nfs/mapid:default | NFs4v user/group id mapping |
Another service present on NFS clients is – svc:/network/nfs/client:default used to mount NFS file systems from /etc/vfstab on boot
NFS sharing
There are many different ways to share a file system or directory on remote system. Below are few basic examples of sharing a file system as NFS.
1. The general way
The general syntax for solaris 8, 9 and 10 is :
share -F nfs -o [options] [pathname]
For example : sharing /data mount point as read/write to hosts system1 and system2 only. Here rw=options is a Access control list. (IPs can be specified instead of hostnames here)
# share -F nfs -o rw=system1:system2 /data
2. Solaris 10 ZFS way
Similar example as above for solaris 10 ZFS file system would be :
# zfs set sharenfs='rw=system1:system2' datapool/data
To un-share the file system we shared :
# zfs unshare datapool/data
3. Solaris 11 ZFS way
In case of solaris 11 the syntax differs completely from solaris 10. Here we need to name the share while sharing it.
# zfs set sharenfs=on datapool/data # zfs set share=name=datashare,path=/data,prot=nfs,rw=system1,system1 datapool/data
– For ZFS as NFS shares we do not need to add any entry to any file as SMF services will take care of sharing it across reboots.
Mounting NFS share at NFS client
Manual Mount
To mount the NFS share manually at the NFS client, the syntax is :
mount -F nfs -o [options] [NFS_server]:[mountpoint]
For the NFS mount point to mount automatically across reboots, use the /etc/vfstab and add below entry :
#device device mount FS fsck mount mount #to mount to fsck point type pass at boot options 192.168.10.23:/data - /mnt nfs - yes ro,bg,vers=3
Note the bg option in the last column. It stands for background and allow the boot process to proceed should the NFS server not be available at boot time.
Gathering info
There are many commands to get information of NFS shares.
1. share
Use the share command on NFS server to display the current shares with all the options :
# share - /data rw=system1 "" - /home/john rw=system1,system2 ""
2. showmount -e
The showmount -e command contacts the mountd daemon and lists all the shares with options.
# showmount -e
3. dfshares
The dfshare command displays the same information as showmount -e but in a different format.
#dfshares
Sharing using dfstab
The NFS shares, shared using the share command won’t persist across reboots. The solution to this is using the /etc/dfs/dfstab file. The general format of a NFS entry in dfstab file is:
share -F nfs -o rw=system1 -d "Home Dir" /export/home
After adding the entries to the dfstab we need to use the shareall command to share the entities mentioned in the dfstab
# shareall
Now, similar to shareall, to un-share all the NFS shares in one go use :
# unshareall
Now, similar to /etc/vfstab, all the NFS shares that are currently shares are listed in the /etd/dfs/sharetab file.
NFS server/client Start/Stop
Before you can start sharing NFS shares and mounting them on remote server, you must start the NFS server and NFS client.
For Solaris 8,9 :
# /etc/init.d/nfs.server start # /etc/init.d/nfs.server stop
For Solaris 10 :
# svcadm enable svc:/network/nfs/server:default # svcadm disable svc:/network/nfs/server:default