Chapter 14, “Managing File Systems,” described how to mount a local file system using the mount command. We’ll use the same mount command to mount a shared file system on a remote host using NFS. Here is the syntax for mounting NFS file systems:
mount -F nfs <options> <-o specific_options > <-O> <server>:<filesystem> <mount_point>
In this example, server is the name of the NFS server in which the file system is located, filesystem is the name of the shared file system on the NFS server, and mount_point is the name of the local directory that serves as the mount point.
As you can see, this is similar to mounting a local file system. The options are described in Table 22.3.
Here’s a note regarding foreground (fg) and background (bg) mounts: File systems mounted with the bg option indicate that mount is to retry in the background if the server’s mount daemon (mountd) does not respond when, for example, the NFS server is restarted. From the NFS client, mount retries the request up to the count specified in the retry=<n> option. After the file system is mounted, each NFS request made in the kernel waits a specified number of seconds for a response (specified with the timeo=<n> option). If no response arrives, the timeout is multiplied by 2 and the request is retransmitted. If the number of retransmissions has reached the number specified in the retrans=<n> option, a file system mounted with the soft option returns an error, and the file system mounted with the hard option prints a warning message and continues to retry the request.
Sun recommends that file systems mounted as read/write or those containing executable files always be mounted with the hard option. If you use soft-mounted file systems, unexpected I/O errors can occur. For example, consider a write request. If the NFS server goes down, the pending write request simply gives up, resulting in a corrupted file on the remote file system. A read/write file system should always be mounted with the specified hard and intr options. This lets users make their own decisions about killing hung processes. Use the following to mount a file system named /data located on a host named thor with the hard and intr options:
mount -F nfs -o hard,intr thor:/data /data
If a file system is mounted as hard and the intr option is not specified, the process hangs until the remote file system reappears if the NFS server goes down. For a terminal process, this can be annoying. If intr is specified, sending an interrupt signal to the process kills it. For a terminal process, this can be done by pressing Ctrl+C. For a background process, sending an INT or QUIT signal as follows usually works:
kill -QUIT 3421
Note
Sending a KILL signal (-9) does not kill a hung NFS process.
To mount a file system called /data, which is located on an NFS server called thor, issue the following command as root from the NFS client:
mount -F nfs -o ro thor:/data /thor_data
In this case, the /data file system from the server thor is mounted read-only on /thor_data on the local system. Mounting from the command line enables temporary viewing of the file system. If the umount command is issued or the system is restarted, the mount is lost. If you would like this file system to be mounted automatically at every startup, add the following line to the /etc/vfstab file:
thor:/data - /thor_data nfs - yes ro
Note
The mount and umount commands require root access. The umount command and /etc/vfstab file are described in Chapter 14.
To view resources that can be mounted on the local or remote system, use the dfmounts command, as follows:
dfmounts sparcserver
The system responds with a list of file systems currently mounted on ultra5:
RESOURCE SERVER PATHNAME CLIENTS - ultra5 /usr 192.168.1.201 ultra5 /usr/dt 192.168.1.201
Sometimes you rely on NFS mount points for critical information. If the NFS server were to go down unexpectedly, you would lose the information contained at that mount point. You can address this issue by using client-side failover. With client-side failover, you specify an alternative file system to use in case the primary file system fails. These file systems should contain equivalent directory structures and identical files. This option is available only on read-only file systems. To set up client-side failover, follow this procedure:
On the NFS client, mount the file system using the -ro option. You can do this from the command line or by adding an entry to the /etc/vfstab file that looks like the following:
zeus,thor:/data - /remote_data nfs - no -o ro
If multiple file systems are named and the first server in the list is down, failover uses the next alternative server to access files. To mount a replicated set of NFS file systems, which might have different paths to the file system, use the following mount command:
mount -F nfs -o ro zeus:/usr/local/data,thor:/home/data /usr/local/data
Replication is discussed again in the section that describes Autofs.
Logged file systems were discussed in Chapter 14. This extends that functionality to networked file systems. The daemon nfslogd provides NFS logging and is enabled using the log=<tag> option in the share command, described later. When NFS logging is enabled, all NFS operations on the file system are recorded in a buffer by the kernel. The data recorded includes a timestamp, the client IP address, the UID of the requestor, the file handle of the resource that is being accessed, and the type of operation that occurred. The nfslogd daemon converts this information into ASCII records that are stored in ASCII log files.
Exercise 22.1 Enabling NFS Server Logging
To enable NFS server logging, follow these steps:
Note
The NFS log files can become very large, so make sure that the /var file system is large enough to hold them or specify an alternate location with adequate disk space.
You can change the file configuration settings in the NFS server logging configuration file called /etc/nfs/nfslog.conf. This file defines the path, filenames, and the type of logging to be used by nfslogd. Each definition is associated with a tag. The global tag defines the default values, but you can create new tags and specify them for each file system you share. The NFS operations to be logged by nfslogd are defined in the /etc/default/nfslogd configuration file.