- Table of Contents
- Copyright
- About the Lead Authors
- About the Contributing Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- I. Red Hat Linux Installation and User Services
- Chapter 1. Introduction to Red Hat Linux
- Chapter 2. Installation of Your Red Hat System
- Chapter 3. LILO and Other Boot Managers
- Chapter 4. Configuring the X Window System, Version 11
- Chapter 5. Window Managers
- Chapter 6. Connecting to the Internet
- Chapter 7. IRC, ICQ, and Chat Clients
- Chapter 8. Using Multimedia and Graphics Clients
- II. Configuring Services
- Chapter 9. System Startup and Shutdown
- Chapter 10. SMTP and Protocols
- Chapter 11. FTP
- Chapter 12. Apache Server
- Chapter 13. Internet News
- Chapter 14. Domain Name Service and Dynamic Host Configuration Protocol
- Chapter 15. NIS: Network Information Service
- Chapter 16. NFS: Network Filesystem
- Installing NFS
- Starting and Stopping the NFS Daemons
- Configuring NFS Servers and Clients
- Exporting Filesystems with linuxconf
- Complete Sample Configuration Files
- Summary
- Chapter 17. Samba
- III. System Administration and Management
- Chapter 18. Linux Filesystems, Disks, and Other Devices
- Chapter 19. Printing with Linux
- Chapter 20. TCP/IP Network Management
- Chapter 21. Linux System Administration
- Chapter 22. Backup and Restore
- Chapter 23. System Security
- IV. Red Hat Development and Productivity
- Chapter 24. Linux C/C++ Programming Tools
- Chapter 25. Shell Scripting
- Chapter 26. Automating Tasks
- Chapter 27. Configuring and Building Kernels
- Chapter 28. Emulators, Tools, and Window Clients
- V. Appendixes
- A. The Linux Documentation Project
- B. Top Linux Commands and Utilities
- C. The GNU General Public License
- D. Red Hat Linux RPM Package Listings
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:
- Their direct hostname.
- Using @ group, where group is the specific netgroup. Wildcard hosts in the group are ignored.
- Wildcards in the hostname. The asterisk (*) can match an entire network. For example, *.engr.widgets.com matches all hosts that end in .engr.widgets.com.
- IP subnets can be matched with address/netmask combinations. For example, to match everything in the 192.168.42.0 network where the netmask is 255.255.255.0, you use 192.168.42.0/24 (that is, IP/netmask bits).
Each host is given a set of access permissions. The most significant ones are
- rw—Read and write access.
- ro—Read-only access.
- sync—This option requests that all file writes be committed to disk before the write request completes. The data is safer with this option because it is written to the disk more often; however, it does put more of a strain on the system's resources. By default this option is turned off and the server writes the data whenever it deems necessary.
- no_subtree_check—This option disables subtree checking. Subtree checking can improve reliability on directories that are exported as read-only or directories where files aren't often renamed. A good example of this is /usr. Subtree checking should be disabled on directories where files are frequently renamed. Home directories should have subtree checking disabled. Subtree checking is enabled by default.
- no_root_squash—Acknowledge and trust the client's root account.
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:
- Use the lsof program (available at ftp://vic.cc.purdue.edu/pub/tools/unix/lsof) to list the users and their open files on a given filesystem. Then, either wait until they are done, beg and plead for them to leave, or kill their processes. Then you can unmount the filesystem. This isn't the most desirable way to achieve an unmount, but you'll find that this is often the path you need to take.
- Use umount with the -f option to force the filesystem to unmount. This is often a bad idea because it confuses the programs (and users) who are accessing the filesystem. Files in memory that have not been committed to disk might be lost.
- Bring the system to single-user mode and then unmount the filesystem. Although this is the greatest inconvenience of the three, it is the safest way because no one loses any work. Unfortunately, on a large server, you'll have some angry users to contend with. (Welcome to system administration!)
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:
- /dev/device—The device to be mounted. In the case of mounting NFS filesystems, this comes in the form of servername:/dir/exported, where servername is the name of the NFS server and /dir/exported is the directory that is exported from the NFS server. For example, denon:/export/home, where denon is the hostname of your NFS server and /export/home is the directory that is specified in the /etc/exports directory as being shared.
- /dir/to/mount—The location at which the filesystem should be mounted on your directory tree.
- ftype—The filesystem type. Usually, this is ext2 for your local filesystems. However, NFS mounts should use the NFS filesystem type.
- parameters—These are the parameters you passed to mount using the -o option. They follow the same comma-delimited format. A sample entry looks like rw,intr,bg.
- fs_freq—This is used by dump to determine whether a filesystem needs to be dumped.
- fs_passno—This is used by the fsck program to determine the order to check disks at boot time. The root filesystem should be set to 1, and other filesystems should have a 2. Filesystems on the same drive will be checked sequentially, but filesystems on different drives will be checked at the same time.
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.
Exporting Filesystems with linuxconf | Next Section

Account Sign In
View your cart