Using fstab to Mount NFS Directories

A mount command with the -a flag set causes Linux to mount all filesystems listed in /etc/fstab. Linux systems often include a mount -a command in the startup. Adding the -t nfs argument to the mount -a command limits the mount to all filesystems in fstab that have a filesystem type of NFS. The Red Hat netfs script uses the -t nfs argument to remount the NFS filesystems after a system boot.

The filesystem table, /etc/fstab, defines the devices, partitions, and remote filesystems that make up a Linux computer's complete filesystem. Each line in the table describes an individual piece of the filesystem. These pieces can be hard disk partitions, devices such as the floppy drive or the CD-ROM drive, or a filesystem from a remote NFS server. The file includes entries for the root partition, the swap partition, and even the pseudo filesystems, such as /proc. A sample fstab file from a dual-booting desktop system running Red Hat Linux 7.2 is shown in Listing 9.6.

Listing 9.6: A Sample fstab File

LABEL=/ / ext3 defaults 1 1

LABEL=/home /home ext3 defaults 1 2

/dev/fd0 /mnt/floppy auto noauto,owner 0 0

LABEL=/var /var ext3 defaults 1 2

/dev/hda1 /win vfat defaults 0 0

LABEL=/var /var ext3 defaults 1 2

/dev/hda1 /win vfat defaults 0 0





































Each line in the fstab file is composed of six fields. The first field is the filesystem name. It is the keyword none for pseudo filesystems, such as /proc. For local devices, the filesystem name field contains the name of the local device. It must be the name of a "block special device." On Linux systems, mknod can create two types of devices: character devices, which provide data one character at a time, and block devices, which provide chunks of data. Use the ls -l command to find out which type a device is:

crw-rw---- 1 root uucp 4, 64 Aug 30 2001 /dev/ttyS0

The first character in the output of the ls command shows the device type. If it is a c, the device is a character device. If it is a b, the device is a block device. All of the local devices in the fstab file are block devices, but they are not all referred to by name. The filesystem name field can contain a label if that label is mapped to a local block special device. Listing 9.6 contains three entries with label values in the filesystem name field:

LABEL=/ / ext3 defaults 1 1

LABEL=/home /home ext3 defaults 1 2

LABEL=/var /var ext3 defaults 1 2

Use the e2label command to see the label associated with a device. For example:

$ e2label /dev/hda3

$ e2label /dev/hdd1


$ e2label /dev/hdd2


The filesystem name field in an entry for an NFS filesystem is formatted in exactly the same way as the remote filesystem name on a mount command. It contains the hostname of the NFS server, separated from the filesystem pathname by a colon. For example, in crow:/export/home/craig, crow is the hostname of the NFS server, and /export/home/craig is the pathname of the remote filesystem.

The second field in each fstab entry is the mount point for the filesystem. Most of the mount points in Listing 9.6 are self-explanatory. Some are the mount points you created when partitioning the disk. Some are mount points for hardware devices, such as the floppy and the CD-ROM. A few are the mount points for pseudo filesystems. And in Listing 9.6, one is an empty directory that we created to act as a mount point for an NFS filesystem. All of these appear as directories within the root directory hierarchy. The clear exception is the swap space; it does not have a mount point, and no swap subdirectory appears below the root directory. On Linux systems, the keyword swap appears in this field for the swap partition entry.

The third field defines the filesystem type. Linux 2.4 can support more than 30 different filesystem types. Not all of them will be used on your system, and not all will have support compiled into your kernel. In Listing 9.6, eight different filesystem-type keywords are specified:

• ext3 is the most important—it is a native Linux journaling filesystem. Most Linux systems use either ext2 or ext3 as their primary filesystem.

• swap is a special format used for the swap file.

• iso9660 is the International Standards Organization (ISO) format for CD-ROMs.

• auto is not really a filesystem type. It tells mount to probe the device to determine the filesystem type. This is useful for the floppy device because Linux can read different types of floppies.

• vfat is the Microsoft FAT format with support for long names. This is a dual-booting desktop system, so it has Windows installed in one of the partitions. Linux can read these Windows files.

• The three remaining types (tmpfs, devpts, and proc) are pseudo filesystems. Unless you want to watch virtual terminals pop up in the /dev/pts directory, the only one of them that contains information of interest to a system administrator is the /proc filesystem. The /proc filesystem provides an interface into the kernel data structures that provide information about running processes.

The fourth field is a comma-separated list of options. The defaults option identifies filesystems that can do the following:

• Be mounted at boot time by the mount -a command

• Be mounted as read and write filesystems

• Allow SetUID and SetGID processes

• Support both character and block devices

In other words, they are typical Linux filesystems.

The noauto option indicates filesystems that should not be mounted by the mount -a command. In Listing 9.6, these are the floppy and CD-ROM devices. The ro option on the CD-ROM indicates that it is a read-only device, and the owner option indicates that it can be mounted and unmounted only by the device owner. The gid and mode options define the GID and file permission used to create files in the /dev/pts directory. There are many more options that can appear in the fstab file, some of which are listed in Table 9.1, and more of which can be found in Table 9.2.

Table 9.2: More mount Options




Sets the maximum cache time for directory attributes. Defaults to 60 seconds.


Sets the minimum cache time for directory attributes. Defaults to 30 seconds.


Sets the maximum cache time for file attributes. Defaults to 60 seconds.


Sets the minimum cache time for file attributes. Defaults to 3 seconds.


Sets all cache times to the same value.


Does retries in background mode.


Does retries in foreground mode.


Retries indefinitely until the server responds.


Allows a keyboard interrupt to kill a process.


Sets the name of the server running mountd.


Sets the port number of mountd.


Uses an alternate RPC program number for mountd on the remote server.


Uses an alternate RPC version number for the mountd on the remote server.


Sets the maximum length of a filename for the remote filesystem. Defaults to 255 bytes.


Uses an alternate RPC program number for nfsd on the remote server.


Uses an alternate RPC version number for nfsd on the remote server.


Disables all caching.


Does not retrieve attributes when creating a file.


Disables NFS locking for compatibility with outdated servers.


Sets the NFS server port number. 2049 is the default.




Runs in a POSIX-compatible mode.

retrans =n

Sets the number of retransmissions before a major timeout occurs. The default is 3.


Sets the amount of time to retry mount. Defaults to 10,000 minutes.


Sets the size of the read buffer. The default is 1024 bytes.


Allows the access to time out if the server doesn't respond.


Runs over TCP instead of UDP.


Sets the length of time that occurs before an access times out. Must be used with soft.


Runs over UDP. This is the default.


Sets the write buffer size. The default value is currently 1024 bytes.

The fifth field is used by the dump command to determine which filesystems should be backed up. If this field contains a 0, dump will not back up the filesystem. If it contains a 1, dump will back up the filesystem every time dump is run. The dump command, of course, has its own syntax and commands. However, marking certain filesystems in the fstab file with a 0 prevents dump from unnecessarily searching filesystems, such as /proc, that should never be backed up.

The sixth and last field in each entry is used by fsck to determine the order in which filesystems should be checked. If the sixth field contains a 0, the filesystem is not checked. The filesystem is checked first if it contains a 1, second if it contains a 2, and so on. This permits you to define the order in which the systems are checked so that critical systems are checked before less-critical ones when fsck runs during startup. The root partition is usually checked first.

fsck also allows you to specify that filesystems should be checked in parallel to speed the process. For example, assume that you have two different partitions of similar size on two different disks. If you placed a 2 in the sixth field for both of these partitions, they would both be checked second. However, if you specify parallel checking, do it only for partitions that are on different physical disks, and only for those that are of similar size. Otherwise, you get no real performance gain.

NFS entries in the fstab file are exactly like the others, except for the type field, which contains the keyword nfs and the large number of possible NFS mount options. Any of the Linux mount command-line options listed in Table 9.1, as well as all of those listed in Table 9.2, can be used in an NFS entry in the fstab file.

Most of these options are rarely used. The key options are those that can improve NFS performance, such as tuning the buffer size. The default of 1024 works well for rsize and wsize, but increasing the buffer size can improve performance.

If you have an unreliable server or network, you may want to change the hard failure setting to soft, or at least add the intr option. That way if the server fails, it will not cause your client system to hang on a hard failure; or if it does, you can escape with a keyboard interrupt.

Note All of the options mentioned here can be used on the mount command line with the -o argument. Additionally, all of the options mentioned earlier in the mount command section can also be used in the fstab file. We divided the list of options to show where certain options are most commonly used and to make the list more manageable.

Understanding what to put in the fstab file for an NFS entry can be confusing with all of these options. An easy way to learn what should be in an fstab entry is to mount the filesystem and then display its entry in the mtab file. The mtab file stores information about currently mounted filesystems. The entries in mtab are very similar to those in the fstab file. Simply mount a file and display mtab. Then you'll know what you should enter in fstab. Listing 9.7 is an example.

Listing 9.7: A Sample /etc/mtab File

# mount owl:/home/jane /home/owl

# cat /etc/mtab

/dev/hda3 / ext3 rw 0 0 none /proc proc rw 0 0 /dev/hdd1 /home ext3 rw 0 0 /dev/hdd2 /var ext3 rw 0 0 /dev/hda1 /win vfat rw 0 0 none /dev/shm tmpfs rw 0 0

none /dev/pts devpts rw,gid=5,mode=620 0 0 /dev/cdrom /mnt/cdrom iso9660 ro,nosuid,nodev 0 0 owl:/home/jane /home/owl nfs,addr= rw 0 0

Based on this, you would add the following entry to the fstab file to mount the /home/owl directory at each boot:

owl:/home/jane /home/owl nfs,addr= rw 0 0

The fstab file is used to automatically remount filesystems at boot time. The automounter automatically mounts NFS filesystems only when they are actually needed.

Continue reading here: Automounter

Was this article helpful?

+1 -1