NFS in Unix & Linux

If your computer is on a LAN, the computer is probably set up to share files with other computers. Quite a few different schemes enable computers to use files on other machines. These schemes are named mostly with TLAs (Three Letter Acronyms) such as AFS, RFS, and NFS. Here, you find out about NFS (you’ll never find your stuff) because that’s the most commonly used scheme, even though it works, in many ways, the worst.

What’s NFS?

The NFS (Network File System) program enables you to treat files on another computer in more or less the same way you treat files on your own computer.

You may want to use NFS for several reasons:

Ignoring NFS

Except when NFS screws up, you don’t have to worry about using it. Your system administrator did all the hard work when she installed it.

Files passed over the network act almost exactly like those on the local machine; in most cases, you can treat them the same. The primary difference is that access to files through NFS is about twice as slow as access to files on the local machine. This problem usually isn’t a big one because, for most of the stuff you do, the machine doesn’t spend much time waiting for the disk anyway.

Wnen you do something really big and slow (such as repaginate a 500-page document), seeing whether you can log in to the machine on which the files reside and run the program there may be worth the time.

Where are those files, anyway?

NFS works by mounting remote directories. Mounting means pretending that a directory on another disk or even on another computer is actually part of the directory system on your disk. Files that are stored in lots of different places can then appear to be nicely organized into one tree-structure directory.

Whenever UNIX sees the name of a directory — /stars/elvis, for example — it checks to see whether any names in the directory are mount points, which are directories in which one disk is logically attached to another.

Your system may have the directory /stars mounted from some other machine, for example, and then the directory elvis and all the files in it reside on the other machine.

The easiest way to tell which files are where is with the df (Disk Free space) command. It prints the amount of free space on every disk and tells you where the disks are. Here’s a typical piece of df output:

Filesystem kbytes used avail capacity Mounted on
/dev/sd0a 30383 6587 20758 24% /
/dev/sd0g 157658 124254 17639 88% /usr
/dev/sd0h 364378 261795 66146 80% /home
/dev/sd3a 15671 1030 13074 7% /tmp
/dev/sd3g 1175742 758508 299660 72% /mnt
server-sys:/usr/spool/mail
300481 190865 79567 71% /var/spool/mail
server-sys:/usr/lib/news
300481 190865 79567 71% /usr/lib/news
server-sys:/usr/spool/news
298068 243877 24384 91% /var/spool/news

In this example, the directory / resides on a local disk (a disk on your own computer) named /dev/sd0a; /usr resides on /dev/sd0g; /home resides on /dev/sd0h; and so on. The directory /var/spool/mail is really the directory /usr/spool/mail on machine server-sys, /usr/lib/news is really /usr/lib/news on machine server-sys, and so on.

Some of the local directory names are the same as the remote machine’s directory names — and some aren’t. This situation can and often does cause considerable confusion; unfortunately, it’s usually unavoidable. A system administrator with any sense at least mounts each directory with a consistent name wherever it’s mounted so that /var/documents/bigproject is the same no matter which computer you’re working on.

A database known as NIS (Network Information System) makes keeping straight the naming process easier. Don’t worry about it unless your system administrator messes up.

NFS and system crashes

What happens if you’re working with NFS, your files are stored on a server, and the server crashes? The answer is, you wait. Eventually, when the server comes back, you continue from where you left off. If the crash is severe, you may wait a long time.

The worst practical problem is that, if a program stalls while it is waiting for a dead NFS server, you have no way to stop or kill the program, short of rebooting your UNIX computer.

Recent versions of NFS have features called soft and hard mounts that make stopping a program that has stalled while waiting for a dead server possible. The problem is that, if a server is merely slow and not dead, a client may assume that the server is dead and stop a program. Had the client been a little more patient, the server would have responded, and the program could have completed its task.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • YahooMyWeb
  • Yigg

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)