-->

Previous | Table of Contents | Next

Page 284

continued

/export, thereby creating /export/usr/local. Because the server itself will need access to the /export/usr/local directory, a symbolic link from /usr/local should be created pointing to the real location, /export/usr/local.

Using mount to Mount an Exported Filesystem

To mount a filesystem, use the mount command


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

where 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, you would use


mount denon:/export/home /home

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

There are options that can be passed to the mount command. The most important characteristics are specified in the -o options. These characteristics are as follows:

ro bg intr soft retrans
rw Read/write.
Read-only.
Background mount. Should the mount initially fail (the server is down, for instance), the mount process will background itself 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 should the server be down.
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.
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.
Specifies the maximum number of retried transmissions to a soft-mounted filesystem.

Here's an example of these parameters in use:


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

Page 285

To unmount the filesystem, use the umount command—for example,


umount /home

This will unmount the /home filesystem.

There is, of course, a caveat. If users are using files on a mounted filesystem, you cannot unmount it. All files must be closed before this can happen, which on a large system can be tricky, 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 will allow 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 would then have to finish bootstrapping the machine yourself and worse, the system could not come back online by itself. (Of course, if you enjoy coming into work at 2 a.m. to bring a system back up…)

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.

NOTE
NFS servers can also be NFS clients. For example, a Web server that exports part of its archive to, say, an FTP server, can NFS mount from the server containing home directories at the same time.

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

Page 286

The following make up this line:

/dir/to/mount ftype parameters fs_freq fs_passno
/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 it specified in the /etc/exports directory as being shared.
The location at which the filesystem should be mounted on your directory tree.
ext2 for your local filesystems; however, NFS mounts should use the nfs filesystem type.
These are the parameters you passed to mount by using the -o option. They follow the same comma-delimited format. An example entry would look like rw,intr,bg.
This is used by dump to determine whether a filesystem needs to be dumped.
This is used by the fsck program to determine the order to check disks at boot time.

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

If you need to mount a new filesystem while the machine is live, you will need to perform the mount by hand. If you want to have this mount automatically active the next time the system is rebooted, you should be sure to 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.

Mounting the swap partition is not done using the mount command. It is instead managed by the swapon command. In order for a swap partition to be mounted, it needs to be listed in the fstab file. Once there, use swapon with the -a parameter, followed by the partition on which you've allocated swap space.

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.

Previous | Table of Contents | Next