Mounting NFS with /etc/fstab and NFS mount Options
Mounting NFS with /etc/fstab
An alternate way to mount an NFS share from another machine is to add a line to the /etc/fstab
file. The line must state the hostname of the NFS server, the directory on the server being exported, and the directory on the local machine where the NFS share is to be mounted. You must be root to modify the /etc/fstab
file.
- The general syntax for the line in
/etc/fstab
is as follows:
server:/usr/local/pub /pub nfs rsize=8192,wsize=8192,timeo=14,intr
- The mount point
/pub
must exist on the client machine before this command can be executed. After adding this line to/etc/fstab
on the client system, type the commandmount /pub
at a shell prompt, and the mount point/pub
...
- is mounted from the server.
...
- The
/etc/fstab
file is referenced by thenetfs
service at boot time, so lines referencing NFS shares have the same effect as manually typing themount
command during the boot process.
A sample sample /etc/fstab
line to mount an NFS export looks like the following example:
<server>
:</remote/export>
</local/directory>
<nfs-type>
<options>
0 0
Replace
with the hostname, IP address, or fully qualified domain name of the server exporting the file system.<server>
Replace
with the path to the exported directory.</remote/export>
Replace
with the local file system on which the exported directory is mounted. This mount point must exist before </local/directory>
/etc/fstab
is read or the mount fails.
Replace
with either <nfs-type>
nfs
for NFSv2 or NFSv3 servers, or nfs4
for NFSv4 servers.
Common NFS Mount Options
Beyond mounting a file system via NFS on a remote host, other options can be specified at the time of the mount to make it easier to use. These options can be used with manual mount commands, /etc/fstab settings, and autofs.
...
fsid=num — Forces the file handle and file attributes settings on the wire to be num, instead of a number derived from the major and minor number of the block device on the mounted file system. The value 0 has special meaning when used with NFSv4. NFSv4 has a concept of a root of the overall exported file system. The export point exported with fsid=0 is used as this root.
hard or soft — Specifies whether the program using a file via an NFS connection should stop and wait (hard) for the server to come back online, if the host serving the exported file system is unavailable, or if it should report an error (soft).
If hard is specified, the user cannot terminate the process waiting for the NFS communication to resume unless the intr option is also specified.
If soft is specified, the user can set an additional timeo=<value> option, where <value> specifies the number of seconds to pass before the error is reported.
Note
Using soft mounts is not recommended as they can generate I/O errors in very congested networks or when using a very busy server.
...