Mounting NFS Filesystems

Use the mount command to mount an NFS filesystem from another machine:

mount shadowman:/mnt/export /mnt/local

NoteDirectory Must Exist

The mount point directory on local machine (/mnt/local in the above example) must exist.

In this command, shadowman is the hostname of the NFS fileserver, /mnt/export is the filesystem that shadowman is exporting, and /mnt/local is a directory on the local machine where we want to mount the filesystem. After the mount command runs (and if we have the proper permissions from shadowman) we can enter ls /mnt/local and get a listing of the files in /mnt/export on shadowman.

Mounting NFS Filesystems using /etc/fstab

An alternate way to mount an NFS share from another machine is to add a line to your /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 you want to mount the filesystem. 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 your machine. After adding this line to /etc/fstab, you can type the command mount /pub at a shell prompt, and the mount point /pub will be mounted from the server.

Mounting NFS Filesystems using autofs

A third option for mounting an NFS share is the use of autofs. Autofs uses the automount daemon to manage your mount points by only mounting them dynamically when they are accessed.

Autofs consults the master map configuration file /etc/auto.master to determine which mount points are defined. It then starts an automount process with the appropriate parameters for each mount point. Each line in the master map defines a mount point and a separate map file that defines the filesystems to be mounted under this mount point. For example, the /etc/auto.mnt file might define mount points in the /mnt directory; this relationship would be defined in the /etc/auto.master file.

Each entry in auto.master has three fields. The first field is the mount point. The second field is the location of the map file, and the third field is optional. The third field can contain information such as a timeout value.

For example, to mount the directory /project52 on the remote machine at the mount point /mnt/myproject on your machine, add the following line to auto.master:

/mnt   /etc/auto.mnt --timeout 60

Add the following line to /etc/auto.mnt:

myproject  -rw,soft,intr,rsize=8192,wsize=8192

The first field in /etc/auto.mnt is the name of the /mnt subdirectory. This directory is created dynamically by automount. It should not actually exist on the client machine. The second field contains mount options such as rw for read and write access. The third field is the location of the NFS export including the hostname and directory.


The directory /mnt must exist on the local filesystem. There should be no subdirectories to /mnt on the local filesystem.

Autofs is a service. To start the service, at a shell prompt, type the following commands:

service autofs restart

To view the active mount points, type the following command at a shell prompt:

service autofs status

If you modify the /etc/auto.master configuration file while autofs is running, you must tell the automount daemon(s) to reload by typing the following command at a shell prompt:

service autofs reload

To learn how to configure autofs to start at boot time, refer to Chapter 5 for information on managing services.