NFS stands for ‘Network File System’. This mechanism allows Unix machines to share files and directories over the network. Using this feature, a Linux machine can mount a remote directory (residing in a NFS server machine) just like a local directory and can access files from it.
An NFS share can be mounted on a machine by adding a line to the /etc/fstab file. In this guide, we learn about NFS mount entry in the fstab file. Check what options fstab has to mount to NFS for better performance.
NFS fstab
The default syntax for fstab entry of NFS mounts is as follows.
Server:/path/to/export /local_mountpoint nfs <options> 0 0
Server: This should be replaced with the exact hostname or IP address of the NFS server where the exported directory resides.
/path/to/export: This should be replaced with the exact shared directory (exported folder) path.
/local_mountpoint: This should be replaced with an existing directory in the server where you want to mount the NFS share.
Fstab NFS options
You can specify a number of options that you want to set on the NFS mount. We will go through the important mount options which you may consider while mounting a NFS share.
1. Soft/hard
When the mount option ‘hard’ is set, if the NFS server crashes or becomes unresponsive, the NFS requests will be retried indefinitely. You can set the mount option ‘intr’, so that the process can be interrupted. When the NFS server comes back online, the process can be continued from where it was while the server became unresponsive.
When the option ‘soft’ is set, the process will be reported an error when the NFS server is unresponsive after waiting for a period of time (defined by the ‘timeo’ option). In certain cases ‘soft’ option can cause data corruption and loss of data. So, it is recommended to use hard and intr options.
2. timeo=n
This option defines the time (in tenths of a second) the NFS client waits for a response before it retries an NFS request.
3. intr
This allows NFS requests to be interrupted if the server goes down or cannot be reached. Using the intr option is preferred to using the soft option because it is significantly less likely to result in data corruption.
4. rsize=num and wsize=num
This defines the maximum number of bytes in each READ/WRITE request that the NFS client can receive/send when communicating with a NFS server. The rsize/wsize value is a positive integral multiple of 1024. Specified rsize values lower than 1024 are replaced with 4096; values larger than 1048576 are replaced with 1048576. If a specified value is within the supported range but not a multiple of 1024, it is rounded down to the nearest multiple of 1024.
5. retrans=n
The number of times the NFS client retries a request before it attempts further recovery action. If the retrans option is not specified, the NFS client tries each request three times. The NFS client generates a "server not responding" message after retrans retries, then attempts further recovery (depending on whether the hard mount option is in effect).
6. noexec
Prevents execution of binaries on mounted file systems. This is useful if the system is mounting a non-Linux file system via NFS containing incompatible binaries.
7. nosuid
Disables set-user-identifier or set-group-identifier bits. This prevents remote users from gaining higher privileges by running a setuid program.
8. tcp
This specifies the NFS mount to use the TCP protocol.
9. udp
This specifies the NFS mount to use the UDP protocol.
Example NFS fstab entry
A sample fstab entry for NFS share is as follows.
host.myserver.com:/home /mnt/home nfs rw,hard,intr,rsize=8192,wsize=8192,timeo=14 0 0
This will make the export directory “/home” to be available on the NFS client machine. You can mount the NFS share just like you mount a local folder.
mount /mnt/home
Conclusion
In this guide, we learn about NFS mount entry in the fstab file with example.
Thanks for reading, please leave your feedback and suggestions in the below comment section.
Comments