Setup NFS Server

From RidgeRun Developer Wiki

Introduction

This wiki explains the process of setting up a A network file system (NFS) server in a target board. NFS allows a user in a client computer to access files over a network just like a local storage. It is a server/client protocol in which the owner of the folder (server) shares it with the client making possible that both the server and the client see the shared content in their respective machines as any other local folder.

NFS makes file sharing as simple as moving files between directories in your local machine making it a very useful tool.


In the next sections you'll see the steps to set up a NFS file system in both the server and the client side.

Kernel Configuration

Enable kernel NFS server support

-> Kernel configuration                                                                                                                               
   -> File systems                                                                                                                                    
      -> Network File Systems (NETWORK_FILESYSTEMS [=y])
         -> NFS server support (NFSD [=y])  

Suboptions to support NFS version 3 and NFS version 4 can be selected

-> Kernel configuration                                                                                                                               
   -> File systems                                                                                                                                    
      -> Network File Systems (NETWORK_FILESYSTEMS [=y])
         -> NFS server support (NFSD [=y])  
            -> NFS server support for NFS version 3 
-> Kernel configuration                                                                                                                               
   -> File systems                                                                                                                                    
      -> Network File Systems (NETWORK_FILESYSTEMS [=y])
         -> NFS server support (NFSD [=y])  
            -> NFS server support for NFS version 4 

Required Packages

nfs-utils

The NFS Utilities package contains the userspace server and client tools necessary to use the kernel's NFS abilities (http://www.linuxfromscratch.org/blfs/view/svn/basicnet/nfs-utils.html_).


rpcbind

The rpcbind program is a replacement for portmap. It is an Open Network Computing Remote Procedure Call (ONC RPC) service that runs on network nodes that provide other ONC RPC services. It is required for import or export of Network File System (NFS) shared directories. (http://www.linuxfromscratch.org/blfs/view/svn/basicnet/rpcbind.html)

libtirpc

The libtirpc package contains libraries that support programs that use the Remote Procedure Call (RPC) API. It replaces the RPC, but not the NIS library entries that used to be in glibc. It is required for rpcbind. (http://www.linuxfromscratch.org/blfs/view/svn/basicnet/libtirpc.html).


File system configuration

Enable nfs-utils

-> File System Configuration                                                                                                                                
     -> Select target's file system software
          -> nfs-utils-1.2.9  

Server bring up

rpcbind

Starting rpcbind:

#/ rpcbind

Then we can check the registered RPC programs:

/ # rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111
    100000    3   tcp    111
    100000    2   tcp    111
    100000    4   udp    111
    100000    3   udp    111
    100000    2   udp    111

NFS server

Starting NFS statd:

/ # /usr/sbin/rpc.statd

Starting NFS nfsd:

/ # /usr/sbin/rpc.nfsd -p 2049 1

Starting NFS mountd:

/ # /usr/sbin/rpc.mountd

Exporting NFS Filesystems:

/ # /usr/sbin/exportfs -ra

Note: make sure you have the file /etc/exports with the appropriate content. This is an example:

#eg. /etc/exports
/nfs/ *(rw,insecure,no_root_squash,no_subtree_check)

And you should be able to see the NFS server's export list on your PC:


$ NFS_SERVER_IP=10.251.101.200
$ showmount -e $NFS_SERVER_IP
Export list for 10.251.101.200:
/nfs *

The rpcinfo now shows:

/ # rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111
    100000    3   tcp    111
    100000    2   tcp    111
    100000    4   udp    111
    100000    3   udp    111
    100000    2   udp    111
    100024    1   udp  39361
    100024    1   tcp  33835
    100021    1   udp  56493
    100021    3   udp  56493
    100021    4   udp  56493
    100021    1   tcp  37521
    100021    3   tcp  37521
    100021    4   tcp  37521
    100005    1   udp  46372
    100005    1   tcp  49449
    100005    2   udp  46372
    100005    2   tcp  49449
    100005    3   udp  46372
    100005    3   tcp  49449

Mounting NFS file system

If you successfully enabled Kernel NFS server support and installed nfs-utils, the steps described in Server bring up are going to be executed automatically at start up so all you have to do is to make sure your file system is in the exports list:

Server side

  • Create the directory you want to export
mkdir /nfs
  • Edit the file /etc/exports so it contains your folder
#eg. /etc/exports
/nfs/ *(rw,insecure,no_root_squash,no_subtree_check)
  • Export your NFS file system
/ # /usr/sbin/exportfs -ra

Client side

In the client side all you have to do is to mount an already exported NFS file system:

  • Create a folder to mount the nfs file system:
mkdir mnt
  • Mount the server NFS file system in your previously created folder:
$ NFS_SERVER_IP=<server ip address>
$ sudo mount -t nfs $NFS_SERVER_IP:/nfs mnt