---------------------------------------------------------------------------- The Florida SunFlash Introduction To NFS SunFLASH Vol 24 #6 December 1990 ---------------------------------------------------------------------------- I have received a number of technical articles from Tony Brooks, a Sun engineer. Some articles were written by Tony and others he has collected from other engineers. I will be posting these articles to SunFlash over the next few weeks. I hope that you enjoy them and find them useful. If you have any comments on them, please send them to me and I'll give them to Tony. -johnj ---------------------------------------------------------------------------- I. What is NFS? NFS is an RPC (Remote Procedure Call) service that enables machines to share files across a network. The access of those remote files and hierarchies are transparent to the user, as if they were local to the user's machine. II. Things to Remember 1) When talking about NFS mounting files you have the option of being a NFS Server or a NFS Client. In this schema the server is any machine that is exporting filesystems to the rest of the net in other words sharing all or part of its disk with the others on the net. In the case of a client that is any machine that is mounting those aforementioned filesystems from the NFS Server. It doesn't take much to be a NFS Server or NFS client unless your machine is a diskless client - you have no disk to serve. III. Setting up a NFS Server or NFS Client 1) Check to see if your kernel is configured to support NFS. The quickest way to determine what kernel* you're running is to look at the /etc/motd file (motd - "message of the day"). The next step is to check the kernel configuration file for the following entries (see below): ------------------------------------------------ % more /etc/motd SunOS Release 4.1 (GENERIC) #1: Wed Mar 7 10:59:35 PST % cd /usr/kvm/sys/[arch]/conf % more /usr/kvm/sys/sun4c/conf/GENERIC . . . options NFSCLIENT # NFS client side code options NFSSERVER # NFS server side code . . ------------------------------------------------ In the example above we looked at the /etc/motd file and found that the name of the kernel is called "GENERIC" - the kernel name is always in the parentheses. Then we changed directories to where the kernel configuration files reside. Note that [arch] refers to the particular architechture of your own machine in the above example the machine type was a sun4c. If you do not have the above entries you will need to reconfigure your kernel to add those entries (System & Networking administration manual, chp 9, pg 242, 4.1 documentation). * In the case of a NFS client machine the only entry that's required in the kernel is "options NFSCLIENT", both options are included to provide the flexibility of being a NFS Server or NFS Client machine 2) Now in case of becoming a NFS Server you need to: 2.1 make sure that the appropriate daemons are running on the machine and they are rpc.mountd, nfsd and inetd: ------------------------------------------------ % ps ax | more PID TT STAT TIME COMMAND . . . 97 ? IW 0:01 rpc.mountd -n . . . 101 ? I 0:00 (nfsd) 102 ? I 0:00 (nfsd) 103 ? I 0:00 (nfsd) 104 ? I 0:00 (nfsd) 105 ? I 0:00 (nfsd) 106 ? I 0:00 (nfsd) 107 ? I 0:00 (nfsd) . . . 131 ? IW 0:08 inetd ------------------------------------------------ you can start these daemons manually if they are not running e.g.: ------------------------------------------------ % su # /usr/etc/inetd & # /usr/etc/nfsd 8 & # /usr/etc/rpc.mountd & ------------------------------------------------ for more information on any of the above daemons consult the manual i.e. mountd(8C), nfsd(8) and inetd(8C). If your machine has not been set up to be on a network, please consult the manual(System & Networking manual, chp 13, pg. 361, 4.1 documentation). 2.2 You now need to edit the /etc/exports file and add the filesystems that you would like to share with the rest of the network, the final step is to run `exportfs -a` e.g.: ------------------------------------------------ % su # vi /etc/exports /usr/share # exportfs -a # showmount -e expor list for [machine_name]: /usr/share (everyone) ------------------------------------------------ `export -a` will update pertinent NFS tables in the kernel. The `showmount -e` will display exported filesytems. For additional information on editing the /etc/exports file consult the manual (System & Network Administration, chp 14, pg. 401, 4.1 documentation). 3) Now in case of becoming a NFS Client you need to: 3.1 (Same as step 2.1 above) 3.2 Now you can remote mount a filesystem - lets assume that we have a machine on the net called "cte". We need to first check to see if "cte" has exported a filesystem that we can access. Then create a directory for test purposes. We execute the mount command to NFS mount the filesytem and finally we issue the `ls` command to see if something did get mounted ( also see df(1V) ): ------------------------------------------------ # showmount -e cte /home # mkdir /usr/tmp/nfs_test # /etc/mount cte:/home /usr/tmp/nfs_test # cd /usr/tmp/nfs_test # ls ------------------------------------------------ In order to permanently have that filesystem mounted via NFS you should edit your /etc/fstab file as root and add the following (otherwise when you reboot the machine the NFS mounted filesystem will automatically be unmounted): ------------------------------------------------ # vi /etc/fstab cte:/home /home/cte nfs rw,hard,intr,bg 0 0 ------------------------------------------------ for additional information on mounting filesystem consult with the manuals (System & Network Administration, chp 14, pg. 406, 4.1 documentation) IV. Automounting 1. What is the automounter? There is yet another way to NFS mount filesytems and that is via the automounter. The automount program enables users to mount and unmount remote directories on an as-needed basis. Whenever a user on a client machine running the automounter invokes a command that needs to access a remote file or directory, such as opening a file with an editor, the hierarchy to which that file or directory belongs is mounted and remains mounted for as long as it is needed. And whenever a certain amount of time has elapsed without the hierarchy being accessed, it is automatically unmounted. 2. Things to Remember 2.1 No mounting is done at boot-time 2.2 The user no longer has to know the superuser password to mount a directory or even use the `mount` and `umount` commands. It is done automatically and transparently. 2.3 Unlike `mount`, `automount` does not consult the file /etc/fstab for a list of hierarchies to mount. Rather, it consults a series of maps, which can be either direct or indirect. 2.4 When `automount` is started, either from the command line or from /etc/rc.local, it forks a daemon to serve the mount points specified in the maps and makes the kernel believe that the mount has taken place. The daemon sleeps until a request is made to access the corresponding file hierarchy. 2.5 A diskless machine must `mount` /, /usr and /usr/kvm through the mount command and the /etc/fstab file. The automounter should not be used to mount /usr/share. 3. Preparation for starting the automounter 3.1 Create the following files in /etc, you must be superuser(these are just example files for demonstration purposes only, the remote machine and filesytem that you choose to use will be different): -------------------------------------------- # vi /etc/auto.home scooby scooby:/home/scooby cte cte:/home/cte # vi /etc/auto.direct /usr/games cte:/usr/games /usr/demo cte:/usr/demo -------------------------------------------- In the case of auto.home map the first column consists of just the remote machine name and the second column specifies where on that machine the home directories reside. In the case of the auto.direct map the first colomn specifies the mount point on your machine where the automounter will transparently NFS mount the remote filesystem on, which is specified in the second column. You can also specify mount options but chose not to do so in this example. For more information on creating maps (Systems & Network Administration, chp 15, pg 440, 4.1 documentation). 3.2 Now, as superuser edit your /etc/rc.local file and modify the existing `automount` line to add the following(make sure that the you remove the pound signs `#` i.e., which is used to comment out the execution of that intended line): -------------------------------------------- # vi /etc/rc.local if [ /usr/etc/automount ]; then /usr/etc/automount /home /etc/auto.home /usr/etc/automount /- /etc/auto.direct /usr/etc/automount /net -hosts -intr (echo " automounter") > /dev/console fi -------------------------------------------- The important thing to understand in the above /etc/rc.local entry is that the very next parameter after the /usr/etc/automount command is the actual mount point where the NFS filesystem will get mounted on your machine. I know that earlier I had said that in the /etc/auto.direct file the first column specifies where the mount point would be on the local machine and that still remains true. So the " /- " is a special filler that tells the automounter to use the mount points that are specified in the /etc/auto.direct file. So, the mount points in this example will be: -------------------------------------------- # vi /etc/auto.direct /usr/games cte:/usr/games /usr/demo cte:/usr/demo -------------------------------------------- `/usr/games` and `/usr/demo`. For the `/usr/etc/automount /home /etc/auto.home` entry the mount point will be /home and the files that will get mounted are: -------------------------------------------- # vi /etc/auto.home scooby scooby:/home/scooby cte cte:/home/cte -------------------------------------------- `/home/scooby` and `/home/cte` from remote machines scooby and cte. The `/usr/etc/automount /net -hosts -intr` entry in the /etc/rc.local file is a special entry. Sun has provided a built-in map called `-host` which does not use any external files except the hosts database (/etc/hosts or the NIS map hosts.byname if NIS is running). This means that after rebooting the you will be able to change directories to /net/machinename and access and files that they have exported to the net .e.g: -------------------------------------------- % cd /net/scooby % pwd /tmp_mnt/net/scooby % ls /home -------------------------------------------- The thing to note in the above example is the information that is reported back to you when you do the `pwd`. It reported back that the working directory was "/tmp_mnt/net/scooby". The automounter creates mount points in the /tmp_mnt directory. 3.3. For test purposes make sure that you comment any mounts in the /etc/fstab that are the as ones that you want to automount e.g.: -------------------------------------------- # vi /etc/fstab cte:/home/cte /home/cte nfs rw,soft 0 0 scooby:/home/scooby /home/scooby nfs rw,soft 0 0 cte:/usr/games /usr/games nfs rw,soft 0 0 cte:/usr/demo /usr/demo nfs rw,soft 0 0 -------------------------------------------- In the above example I would need to comment out those particular mounts e.g.: -------------------------------------------- # vi /etc/fstab #cte:/home/cte /home/cte nfs rw,soft 0 0 #scooby:/home/scooby /home/scooby nfs rw,soft 0 0 #cte:/usr/games /usr/games nfs rw,soft 0 0 #cte:/usr/demo /usr/demo nfs rw,soft 0 0 -------------------------------------------- 4. Reboot your machine 4.1 As superuser you should reboot your machine: -------------------------------------------- # /etc/reboot -------------------------------------------- You should now be using the automounter. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ For information send mail to info-sunflash@sunvice.East.Sun.COM. Subscription requests should be sent to sunflash-request@sunvice.East.Sun.COM. All prices, availability, and other statements relating to Sun or third party products are valid in the U.S. only. Please contact your local Sales Representative for details of pricing and product availability in your region. Descriptions of, or references to products or publications within SunFlash does not imply an endorsement of that product or publication by Sun Microsystems. John McLaughlin, SunFlash editor, flash@sunvice.East.Sun.COM. (305) 776-7770.