If your FreeBSD machine will be mounting NFS shares from other servers, you will need to configure it as a client. Technically this isn't really necessaryyou can mount an NFS share in a rudimentary fashion right out of the box. However, configuring the system as an NFS client gives you a few features that ensure speedy and reliable performance, such as the nfsiod dispatcher. To set up an NFS client machine, simply enable the following line in /etc/rc.conf: nfs_client_enable="YES" This setting enables the NFS Input/Output Daemon, nfsiod, which helps to streamline NFS client requests and tunes a few kernel settings to improve access time. This is all handled automatically in the /etc/rc.network script at boot time, along with the NFS server settings (which you saw earlier). NFS Input/Output Daemon (nfsiod)The nfsiod daemon isn't required for proper NFS client operation, but it helps to speed things up. The nfsiod daemon operates by allowing NFS read and write operations to be done in an asynchronous manner, with "read-ahead" and "write-behind" operations occurring in the background, rather than having to wait for each sequential step in the process to complete. Just as with nfsd, there should be as many nfsiod processes running as there are mounted NFS shares on the client machine. You can tune the number of processes with the nfs_client_flags setting in /etc/rc.conf, which uses the n option to create four processes by default: nfs_client_flags="-n 4" There aren't any other settable options for nfsiod. To start it without rebooting the machine, simply run the appropriate rc script: # /etc/rc.d/nfsclient start Mounting Remote FilesystemsMounting an NFS share is done with the mount_nfs command, which is a shorthand command for mount -t nfs (as you learned in Chapter 12). In its most common form, you would pass to it two arguments: the host and share names in a combined string, and the local mount point: # mount_nfs spots:/home /home2 A successful mount will result in no output. You can check whether the mount was successful with the df command: # df Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/ad0s1a 992239 54353 858507 6% / /dev/ad0s1f 26704179 4872963 19694882 20% /home /dev/ad0s1e 9924475 1642343 7488174 18% /usr procfs 4 4 0 100% /proc spots:/home 9924475 1642343 7488174 18% /home2 If you go into the /home2 directory, you'll see all the directories within /home on the NFS server, with each file's ownership mapped based on UID, as discussed earlier. The filesystem will remain mounted until you explicitly unmount it with the umount command: # umount /home2 Caution Remember to leave any NFS-mounted directory before you try to unmount it with umount! You will get a "device busy" error if you try to unmount a filesystem while you're still inside it. NFS shares can be mounted in a great variety of ways, and the options are laid out in the man mount_nfs page. Some of the more useful ones are the -T option, which forces TCP transport rather than UDP (useful for mounts done over WAN links), and the -s and -x seconds flags, which allow the mount to time out and disappear after a specified period and then fail (a "soft" mount). Here's an example: # mount_nfs -s -x 60 spots:/home /home2 Tip Another useful option is -i, which enables interruptibility. Normally, if you have mounted an NFS share and the server becomes unresponsive or unreachable, any filesystem calls you make (commands that deal with the shared files, such as ls) can hang in such a way that even pressing Ctrl+C (the termination signal) won't stop them. The -i option makes it so that Ctrl+C will force the command to fail, returning control to you. As with other filesystem types, you can add NFS mounts to /etc/fstab to set up predefined mount points, thus simplifying the mount process. Place any options you would otherwise pass to mount_nfs in the Options column, separated by commas, as shown here: # Device Mountpoint FStype Options Dump Pass# spots:/home /home2 nfs rw,-T,-i,noauto 0 0 With a table entry like this, you can mount an NFS filesystem with a much simplified mount command: # mount /home2 Mounting Remote Filesystems Automatically at System BootAll filesystems in /etc/fstab are automatically mounted at boot time, unless the noauto option is present. You can specify that remote NFS shares should be mounted at startup by simply adding them to /etc/fstab, as you just saw. However, there are a few things to watch out for. Most notably, NFS has an extremely long default timeout period, and the phase during startup when filesystems are mounted is a synchronous, blocking process. If your NFS server or servers cannot be foundfor instance, if the server machine isn't running, or if your own machine's network connection is not configured properlythe boot process can hang for an intolerably long period before NFS gives up and allows the system to finish the boot procedure. You can solve this problem by placing the noauto option in /etc/fstab, as you saw in the earlier example. However, this means that you have to mount each NFS share manually after the system is fully booted. There's a better way to handle thisthe -b option. Here's an example: # Device Mountpoint FStype Options Dump Pass# spots:/home /home2 nfs rw,-b 0 0 The -b option tells mount to make a quick attempt to contact the server, and if it can't, to fork off a child process to continue trying to connect while the boot process continues on. Similarly, if you mount a share from the command line using -b, the process forks into the background and returns you to the command prompt. The following is the output you would get when trying to mount the share specified in the preceding sample /etc/fstab line, after trying for 60 seconds: # mount /home2 spots:/home: nfsd: RPCPROG_NFS: RPC: Port mapper failure - RPC: Timed out nfs: Cannot immediately mount spots:/home, backgrounding The background mount_nfs process will keep trying to mount the share until it's successful. This method is particularly useful in computing clusters or labs in which NFS-mounted resources are nice to have but not required for correct operationfor example, a cluster in which an NFS mount contains popular user programs or games, but all critical system functions are available on disks on the local system. |