Linux Help

NFS Setup Guide   
Printable Version

x2xtreme's NFS Setup Guide
Created on February 19th, 2000.
Last updated on February 27th, 2000

NFS stands for Network File System, and it is used to share an entire filesystem via a network. First in order to setup NFS, you will need to have your network already up and running. See ToXic_MYsT's Network_Basics-HOWTO for information on that. You will also need to know how to recompile your kernel. For that see Joey's Kernel Compile/Upgrade Guide. You also might want to take a peek at the NFS-HOWTO and finally, you will need to have root access to the box you are setting up nfs on.

Kernel Configuration

After you run make menuconfig or whatever it is that you use to configure the kernel, you will need to include the following items:

Under the "Code maturity level options --->" you need to have the following enabled:

[*] Prompt for development and/or incomplete code/drivers

Under the "Filesystems --->" menu, go into the "Network File Systems --->" submenu at the bottom of the screen. In here you need the following:

<*> Coda filesystem support (advanced network fs)
<*> NFS filesystem support
<*> NFS server support

In the "Networking options --->" menu you must have this enabled:

[*] IP: kernel level autoconfiguration
[*]       BOOTP support (NEW)

Configuration Files

The Exports file (/etc/exports) is one of the most important files in nfs. It will tell the nfs client what pc is allowed to see what on your box and what permissions that particular box will have to that directory. Here is a a line from my /etc/exports file.

 /  192.168.0.0/24(rw). 

That line is saying that everything on my 192.168 network can mount my root directory with write permissions. You can specify that box you want to have access to a directory by using it's ip, the entire network's submask, or it's host name. For example:

/  192.168.0.2(rw)

or 

/  yourclientshostname(rw)

If you use your clients hostname, you must put it in /etc/hosts. Everytime you make a change to /etc/exports you must run the following command to update nfs:

/usr/sbin/exportfs -a 

How to mount a nfs drive. Fstab or Console command. I recommend putting it in /etc/fstab it's alot easier when you got alot of nfs mounts. A typical nfs entry looks like this.

192.168.0.1:/   /x2xtreme        nfs rsize=1024,wsize=1024,noauto 0 0
192.168.0.1:/tmp  /x2xtreme    nfs rsize=1024,wsize=1024,noauto 0 0

If you have subdir different partitions, you must add those to /etc/exports and /etc/fstab. Like if /usr is on a different partition then it must be add added as another entry in to /etc/exports and to /etc/fstab. To mount a nfs drive from console without using fstab. You would type mount -o rw,(or ro) servername:/exportedirectory /dirtomountonyourlocalbox. You don't have to add a /etc/fstab entry, buts it's cool for a shortcut because you can specify the mount dir and options, and only have to type mount /boxhostname or whatever.

The NFS demonds reside in /etc/rc.d/init.d on Red Hat Linux and in /etc/init.d/ on Debian GNU/Linux. You need to make sure that portmap and NFS are both running and that they startup without any errors. To restart NFS just run /etc/rc.d/init.d/nfs restart (in Red Hat) or /etc/init.d/nfs restart (in Debian). To restart portmap just execute /etc/rc.d/init.d/portmap restart (Red Hat) or /etc/init.d/portmap restart (Debian). Please note that you have to start portmap before NFS.

Example Files

[x2xtreme@x2xtreme x2xtreme]$ cat /etc/hosts
127.0.0.1       localhost.localdomain   localhost
192.168.0.1     x2xtreme.dynip.com      x2xtreme.dynip.com server
192.168.0.2     x2x
192.168.0.3 kimy
192.168.0.4   xwin 

[x2xtreme@x2xtreme x2xtreme]$ cat /etc/fstab
/dev/hda1               /                       ext2    defaults         1 1
/dev/hda2               swap                    swap    defaults         0 0
/dev/fd0                /mnt/floppy             vfat    noauto           0 0
/dev/hdb1               /backup                 ext2    defaults         0 0
/dev/cdrom              /mnt/cdrom              iso9660 noauto,ro        0 0
none                    /proc                   proc    defaults         0 0
none                    /dev/pts                devpts  mode=0622        0 0
192.168.0.2:/   /x2x                nfs rsize=1024,wsize=1024,noauto     0 0
192.168.0.2:/mnt/cdrom /x2x/mnt/cdrom nfs rsize=1024,wsize=1024,noauto   0 0
192.168.0.2:/usr /x2x/usr nfs rsize=1024,wsize=1024,noauto   	         0 0
192.168.0.2:/home /x2x/home nfs rsize=1024,wsize=1024,noauto             0 0
192.168.0.2:/mnt/floppy /x2x/mnt/floppy nfs rsize=1024,wsize=1024,noauto 0 0
192.168.0.2:/fat   /x2x/fat          nfs rsize=1024,wsize=1024,noauto    0 0
192.168.0.2:/downloads /x2x/downloads nfs rsize=1024,wsize=1024,noauto   0 0
192.168.0.2:/mnt/mp3s /x2x/mnt/mp3s nfs rsize=1024,wsize=1024,noauto     0 0
192.168.0.2:/mnt/fat   /x2x/mnt/fat  nfs rsize=1024,wsize=1024,noauto    0 0
192.168.0.2:/backup /x2x/backup nfs rsize=1024,wsize=1024,noauto         0 0
192.168.0.2:/mnt/fat2 /x2x/mnt/fat2 nfs rsize=1024,wsize=1024,noauto     0 0
192.168.0.2:/mnt/cdrom2 /x2x/mnt/cdrom2 nfs rsize=1024,wsize=1024,noauto 0 0
[x2xtreme@x2xtreme x2xtreme]$ 

[x2xtreme@x2xtreme x2xtreme]$ cat /etc/exports
/  192.168.0.0/24(rw)
/mnt/cdrom 192.168.0.0/24(ro)
/mnt/floppy 192.168.0.0/24(rw)
/backup  192.168.0.0/24(rw)
/mp3s  192.168.0.0/24(rw)
[x2xtreme@x2xtreme x2xtreme]$

TroubleShooting

If you are getting permission denied when you try to mount the nfs export, check to make sure that that machine is in /etc/hosts on the box that you are trying to mount it from.

If you are getting a error saying function not inplemented when running /usr/sbin/exportfs -a, then you are missing something in your kernel in the nfs part. You should build the NFS options as links (*) in your kernel and not as modules (M).

If the machine you are trying to mount crashes when you try to mount the root directory then you're missing something that should have been compiled into your kernel.

Please note that the exports file is very sensitive in regards to syntax/formatting. If you have a space between the allowed host(s) or IPs like this:

/nfs/dir  somehost.box.com (rw)

You will not be able to access the resource in read write mode. The only access you will get is read. Make sure there is no space there so that the entries look like this:

/nfs/dir  somehost.box.com(rw)

This will save you money on rogaine.


Having trouble? Got questions? Require further assistance? If so please feel free to visit our Help Forums and ask the experts!


Copyright © 1997 - 2008 Private World Domination Inc. All rights reserved.
Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
| Contact Us | Link to Us | RSS Feed | Staff |

DNS Hosting by easyDNS