Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Configuring NFS Servers and Clients

The two key files to NFS are /etc/exports and /etc/fstab. The exports file is configured on the server side and specifies which directories are to be shared with which clients and each client's access rights. The fstab file is configured on the client side and specifies which servers to contact for certain directories, as well as where to place them in the directory tree.

Setting Up the /etc/exports File

The /etc/exports file specifies which directories to share with which hosts on the network. You only need to set up this file on your NFS servers.

The /etc/exports file follows this format:


   /directory/to/export    host1(permissions) host2(permissions) host3(permissions) host4(permissions)
#
# Comments begin with the pound sign and must be at the start of
# the line
#
/another/dir/to/export    host2(permissions) host5(permissions)

In this example, /directory/to/export is the directory you want to make available to other machines on the network. You must supply the absolute pathname for this entry. On the same line, you list the hosts and which permissions they have to access. If the list is longer than the line size permits, you can use the standard backslash (\) continuation character to continue on the next line.

You specify the names of the hosts in four ways:

Each host is given a set of access permissions. The most significant ones are

If you are familiar with the export file configurations of other flavors of UNIX, you know that this process is not similar. Whether one is better than the other is a holy war discussion best left to Usenet newsgroups.

After you set up your /etc/exports file, run the exportfs command with the -r option:


   exportfs -r

This sends the appropriate signals to the rpc.nfsd and rpc.mountd daemons to reread the /etc/exports file and update their internal tables.

Using mount to Mount an Exported Filesystem

To mount a filesystem, use the mount command:


   mount servername:/exported/dir /dir/to/mount
   

servername is the name of the server from which you want to mount a filesystem, /exported/dir is the directory listed in its /etc/exports file, and /dir/to/mount is the location on your local machine where you want to mount the filesystem. For example, to mount /export/home from the NFS server denon to the directory /home, use


   mount denon:/export/home /home

Remember that the directory must exist in your local filesystem before anything can be mounted there.

You can pass options to the mount command. The most important characteristics are specified in the -o options. These characteristics are listed in Table 16.1.

Table 16.1. Arguments to mount

Characteristic Description
rw Read/write.
ro Read-only.
bg Background mount. Should the mount initially fail (the server is down, for instance), the mount process will place itself in the background and continue trying until it is successful. This is useful for filesystems mounted at boot time because it keeps the system from hanging at that mount if the server is down.
intr Interruptible mount. If a process is pending I/O on a mounted partition, it will allow the process to be interrupted and the I/O call to be dropped.
soft By default, NFS operations are hard, meaning that they require the server to acknowledge completion before returning to the calling process. The soft option allows the NFS client to return a failure to the calling process after retrans number of retries.
retrans Specifies the maximum number of retried transmissions to a soft-mounted filesystem.
wsize Specifies the number of bytes to be written across the network at once. The default is 8192 (for example, wsize=2048). You shouldn't change this value unless you are sure of what you are doing. Setting this value too low or too high can have a negative impact on your system's performance.
rsize Specifies the number of bytes to be read across the network at once. Like wsize, the default is 8,192 bytes. The same warning applies as well: Changing the value without understanding its effect can have a negative impact on your system's performance.

Here's an example of these parameters in use:


   mount -o rw,bg,intr,soft,retrans=6 denon:/export/home /home

Unmounting a Filesystem

To unmount the filesystem, use the umount command:


   umount /home

This will unmount the /home filesystem.

There is a caveat, of course. If users are using files on a mounted filesystem, you cannot unmount it. All files must be closed before the unmount can happen, which can be tricky on a large system, to say the least. There are three ways to handle this:

Configuring the /etc/fstab File to Mount Filesystems Automatically

At boot time, the system will automatically mount the root filesystem with read-only privileges. This allows it to load the kernel and read critical startup files. However, after the system has bootstrapped itself, it will need guidance. Although it is possible for you to jump in and mount all the filesystems, it isn't realistic because you then have to finish bootstrapping the machine yourself. Even worse, the system might not come back online by itself.

To get around this, Linux uses a special file called /etc/fstab. This file lists all the partitions that need to be mounted at boot time and the directory where they need to be mounted. Along with that information, you can pass parameters to the mount command.

Each filesystem to be mounted is listed in the fstab file in the following format:


   /dev/device        /dir/to/mount      ftype parameters fs_freq fs_passno

An example would look like this:


   server:/usr/local/pub    /pub    nfs    rsize=8192,wsize=8192,timeo=14,intr

The following items make up this line:

Any lines in the fstab file that start with the pound symbol (#) are considered comments and are ignored.

If you need to mount a new filesystem while the machine is live, you must perform the mount by hand. If you want this mount to be active automatically the next time the system is rebooted, you should add it to the fstab file.

There are two notable partitions that don't follow the same set of rules as normal partitions. They are the swap partition and /proc, which use filesystem types swap and proc, respectively.

You do not mount the swap partition using the mount command. It is instead managed by the swapon command. For a swap partition to be mounted, you must list it in the fstab file. Once it is there, use swapon with the -a parameter. The /proc filesystem is even stranger because it really isn't a filesystem. It is an interface to the kernel abstracted into a filesystem format. Take a peek into it for a large amount of useful information regarding the inner workings of the kernel.

Share ThisShare This

Informit Network