Networking - NFS

Sun's NFS protocol provides transparent remote access to shared file systems across networks. The NFS protocol is deigned to be machine, operating system, network architecture, and transport protocol independent. This independence is achieved through the use of Remote Procedure Call (RPC) primitives built on top of an eXternal Data Representation (XDR).

The Supporting MOUNT protocol performs the operating system-specific functions that allow clients to attach remote folder trees to a point within the local file system. The mount process also allows the server to grant remote access privileges to a restricted set of clients via export control.

The Lock Manager provides support for file locking when used in the NFS environment. The Network Lock Manager (NLM) protocol isolates the inherently statfull aspects of file locking into a separate protocol.

To Setup Network File System Server (NFS)

We can share any file from one computer to another through network by NFS server. The working processes are given below but first we will talk about the main configuration files of NFS and the rules to export a file,

To configure the /etc/exports file and others:

The file /etc/exports serves as the access control list for file systems which may be exported to NFS clients. It is used by exportfs to give information to mountd and to the kernel based NFS file server daemon nfsd.

Blank lines are ignored. A pound sign ("#") introduces a comment to the end of the line. Entries may be continued across newlines using a backslash. If an export name contains spaces it should be quoted using double quotes. You can also specify spaces or other unusual character in the export name using a backslash followed by the character code as three octal digits.

When identifying the file systems to export, keep in mind the following three rules that restrict how file system can be exported:

Rule 1: You can export only local file systems and their subdirectories. You can not export a file system that is itself already an NFS mount.

Rule 2: A subdirectory of an exported file system cannot be exported unless the subdirectory resides on a different physical disk than its parent. Example, by /etc/fstab:

/dev/sda1 /usr/local ext3 defaults 1 2

ð If you export /usr/local, you cannot also export /usr/local/devtools because /usr/local/devtools is on the same disk as /usr/local.

Again, if however, /etc/fstab showed the following disk configuration:

/dev/sda1 /usr/local ext3 defaults 1 2

/dev/sda2 /usr/local/devtools ext3 defaults 1 2

ð Now you could export both /usr/local and /usr/local/devtools because they reside on different physical disks.

Rule 3: Conversely, the parent directory of an exported subdirectory cannot be exported unless the parent directory resides on a different physical disk.

Example of a sample /etc/exports file

[root@localhost root]# vi /etc/exports

/ master(rw) trusty(rw,no_root_squash)

/projects proj*.local.domain(rw)

/usr *.local.domain(ro) @trusted(rw)

/home/joe pc001(rw,all_squash,anonuid=150,anongid=100)

/pub (ro,insecure,all_squash)

NFS clients may be specified in a number of ways,

Way

Description

single host

We can specify a host either by an abbreviated name recognized be the resolver, the fully qualified domain name, or an IP address.

netgroups

NIS netgroups may be given as @group. Only the host part of each netgroup members is consider in checking for membership.

wildcards

Machine names may contain the wildcard characters * and ?. For instance, *.cs.foo.edu matches all hosts in the domain cs.foo.edu.

IP networks

This is done by specifying an IP address and netmask pair as address/netmask where the netmask can be specified in dotted-decimal format, or as a contiguous mask length .Wildcard characters generally do not work on IP addresses, though they may work by accident when reverse DNS lookups fail.

exportfs understands the following export options,

Option

Description

secure

This option requires that requests originate on an internet port less than IPPORT_RESERVED (1024).

insecure

Unprivileged ports numbered 1024 and higher.

ro

Exports the file system read-only.

rw

Exports the file system read-write.

async

Allows the server to cache disk writes to improve performance.

sync

Forces the server to perform a disk write before the request is considered complete.

subtree_check

If only part of a file system, such as a subdirectory, is exported, subtree checking make sure that the file requests apply to files in the exported portion of the file system.

no_subtree_check

Disable subtree_check.

wdelay

Allows the server to delay a disk write if it believes another related disk write may be requested soon or if one is in progress, improving overall performance.

no_wdelay

Disable wdelay (must be used with the sync option).

root_squash

Maps all requests from a UID or GID of 0 to the UID or GID respectively of the anonymous user.

No_root_squash

Disables root_squash.

all_squash

Maps all requests from a UID or GID to the UID or GID respectively of the anonymous user.

No_all_squash

Disables all_squash.

anonuid=uid

Sets the UID of the anonymous account to uid.

anonguid=gid

Sets the GID of the anonymous account to gid.

Two additional files store status information about NFS exports, /var/lib/nfs/rmtab and /var/lib/nfs/xtab.

[root@localhost root]# vi /var/lib/nfs/rmtab

[root@localhost root]# vi /var/lib/nfs/xtab

Tasks for Server Side:

I). First, our computer should have a network with other computer or computers.

II). We have to setup "nfs-utils" package on our computer. We can check whether the package is installed or not on system by executing the following command

[root@localhost root]# rpm -qa nfs-utils

nfs-utils-1.0.6-20

ð If it is installed, we will go to next statement. On the other hand if it is not installed then we should setup the rpm from Linux installation CD because the rpm comes with this CD.

III). Now, we shall choose which directory or files shall be shared. Consider the directory "/home/dir1" will be shared.

IV). Now open the file called "/etc/exports" which contains all the information of NSF. After opening the file we have to edit the path of shared directory or file and the client name with sharable permission option.

[root@localhost root]# vi /etc/exports

/home/var 192.168.10.1(wo)

/root 192.168.10.*(ro)

/dev/cdrom *(rw)

Here "192.168.10.1" and "192.168.10.*" are nothing but the IP address of the clients and”*" means all the clients in that network (192.168.10.) can share the given directory or file. Next we have to give the permission type to clients to share. Note: there is no space between the client's name and permission type. We can use three types of permission.

(ro) The client can read only the file or directory.

(wo) The client can write only the file or directory

(rw) The client can both read and write the file or directory.

Now we shall write the new sharing directory path, client's name and the permission type in the "exports" file.

[root@localhost root]# cat >> /etc/exports

/home/newdir 192.168.10.7(rw)

[root@localhost root]# vi /etc/exports

/home/var 192.168.10.2(wo)

/root 192.168.10.*(ro)

/dev/cdrom *(rw)

/home/newdir 192.168.10.34(rw)

The picture shows that which clients can share which directories of server (192.168.10.1) on depending of export file.

V). Now we shall start the NFS service, but first we have to initiate portmap service.

[root@localhost root]# service portmap start

Starting portmapper: [ OK ]

ð It is necessary because NFS server have no port number.

[root@localhost root]# service nfs start

Starting NFS services: [ OK ]

Starting NFS quotas: [ OK ]

Starting NFS daemon: [ OK ]

Starting NFS mountd: [ OK ]

ð It takes some times and shows the configuration.

Tasks for Client Side:

VI). Now client can share the directory "/home/dir1". If client don't know which directories we give them to share then they can use showmount command. About the command is explained in below.

showmount queries the mount daemon on a remote host for information about the state of the NFS server on that machine. With no options showmount lists the set of clients who are mounting from that host. Some important options are given in below.

-a List both the client hostname and mounted directory in host:dir format.

-d List only the directories mounted by some client.

-e Show the NFS server’s export list.

Example, following showmount command is used by client to check out which directory of server (192.168.10.34) can be shared.

[root@localhost root]# showmount -e 192.168.10.34

Export list for 192.168.10.34:

/home/var

/root

/dev/cdrom

/home/newdir

VII). To share all above directories the client have to mount first to a mounting point on local hard dish. For mounting he needs following syntax,

mount :

Example,

[root@localhost root]# mount 192.168.10.20:/home/newdir /opt

[root@localhost root]# cd /opt

[root@localhost root]# ll

ð It shows all the files and subdirectories of "/home/newdir".

Linux Installation through NFS Server

If there is a computer without CD-Rom in network, then also we can install Linux on that computer from server computer of same network through NFS. The steps to install Linux in client are given below,

Task for Server Side:

I). If server computer has no directory named "pub" in “/var/ftp/” directory, then we should create first this directory and have to take a back up of all Linux installation CD’s files in the “pub” directory.

[root@localhost root]# mkdir -p /var/ftp/pub

ð It creates pub directory.

[root@localhost root]# cp -r /mnt/cdrom/* /var/ftp/pub/

ð It takes a back up of all files and directories from Linux installation CD. If there are more Installation CDs then we can use same above command to copy all CDs in “pub” directory.

II). Now, we have to create one boot floppy and one driver floppy. The image files of both drivers are stored in 1st Linux installation CD.

For creating boot floppy, we go to first "images" directory in Linux installation CD and give the command as:

[root@localhost root]# cd /mnt/cdrom/images

[root@localhost images]# cat bootdisk.img > /dev/fd0

Or

[root@localhost images]# dd if=bootdisk.img of=/dev/fd0

ð Here if means input files and of means output files. Now it creates bootdisk. Remove the bootdisk floppy from floppy driver and put another new floppy into the drive and give the command to make a driver floppy as below,

[root@localhost images]# cat drvnet.img > /dev/fd0

Or

[root@localhost images]# dd if=drvnet.img of=/dev/fd0

ð It creates a driver disk.

Note: You should use a new floppy or format the floppy first to create both boot disk and driver disk. To format a floppy disk we can use a command which is given below,

[root@localhost root]# fdformat /dev/fd0

Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.

Formatting ... 25

ð It formats floppy disk.

III). Check the IP address of server computer by the command

[root@localhost root]# ifconfig

Now open the "/etc/exports" file and write the path of the Linux Backup directory along with client’s name and read write permission. Example,

[root@localhost root]# cat >> /etc/exports

/var/ftp/pub *(rw)

Note: For new client, there is no IP address given. For this reason, we should give the permission to all clients by using wildcard "*".

After editing the “exports” file we have to restart the nfs service.

[root@localhost root]# service nfs start

Task for Client’s Side:

IV). Now, go to client computer and boot form floppy drive by inserting the bootdisk.

V). After some times it asks us that which type of installation method do we want (text mode or graphic mode). We can choose either text mode or graphic mode. But it is better to select text mode than graphic mode for fast performance. To take text mode we shall type "linux text" in installation command prompt and press “enter”.

Boot] linux text

ð It is initiating to install by text mode.

VI). After waiting few minutes, it will ask us how Linux will be installed through NFS or other services. We shall select NFS. Again it will ask how it will link with source files through driver disk or others. Now we shall select driver disk and insert the driver floppy and press "Ok".

VII). Now a dialog box will open and want for entering an IP address of client computer and server computer and the source directory's path (/var/ftp/pub).

VIII). After entering all those information, it will start the installation of Linux.

Kickstart Through NfS Server

Kickstart is used to send hardware, network, NFS, IP address etc all configure to "anaconda-ks.cfg" file for installing Linux. It is an easiest installation way and it takes short time to install Linux on many computers (but all computers should have same hardware configuration) in network. And all the information of kickstart is stored in a file called "ks.cfg". To make this file we can give the command as,

[root@localhost root]# redhat-config-kichstart

ð It opens the kickstart program in GUI (Graphic User Interface) mode. After configuring we save the configuration in the "ks.cfg" file. Now we have to copy this file in the "bootdisk".

Now while we shall go to install Linux in client computer then first we boot the system by “bootdisk”. In the booting time of system it will open a command prompt, where we have to type the command as below,

Boot] linux ks=floppy