Saturday, December 13, 2008

Setting up NFS share on Ubuntu

This post summarizes steps I've done to setup a NFS share on Ubuntu 8.10 VM host and mount it on an another Linux machine (Debian Linux running on embedded arm in my case).

Host machine: Ubuntu, 192.168.1.110
Client machine: Debian, 192.168.1.175

1. Install NFS package by either going to Synaptic Package Manager (System->Administration->...) and searching for nfs-kernel-server or typing the following on the command line:
$ sudo apt-get install nfs-kernel-server

This will download and install all the required dependencies.

2. Add the directory desired to be shared, permissions and other information to /etc/exports file.
$ vi /etc/exports
Add without quotes: "/path/to/nfsshare 192.168.1.110/255.255.255.0(rw,no_root_squash,insecure)"

Here, 192.168.1.110 is the IP of the host. The mask allows NFS connections from the following IP addresses: 192.168.1.0-255. This can be modified to suit the needs.

3. Restart NFS and update the exports list.
$ sudo /etc/init.d/nfs-kernel-server restart
$ sudo exportfs -a

4. To mount NFS root, run on the client:
$ portmap &

5. Mount NFS shared directory on the client machine.
$ mkdir /mnt
$ mount -t nfs 192.168.1.110:/path/to/nfsshare /mnt

6. Now the files placed into /path/to/nfsshare/ on the host are accessible from the client!

Notes
1. Mounted devices can be found here:
$ cat /proc/mounts
or just run
$ mount

2. For automatic mounts after restart of the client, I added the following line to ~/.bashrc file:
mount -t nfs 192.168.1.110:/path/to/nfsshare /mnt

3. To check the IP addresses of the Linux machines, run 'ifconfig'.
To check the connection between the machines, use the ping command:
-from client: 'ping 192.168.1.110'
-from host: 'ping 192.168.1.175'

References:
[1] Enabling NFS in Ubuntu
[2] Easy-Peasy Ubuntu Linux NFS File Sharing

No comments: