Equations

Wednesday, July 10, 2013

Network Mounting of Directories For Ubuntu Machines

In this post, I'm going to discuss how to mount a directory from a master machine in a network of machines running Ubuntu. 

1. In the master station, edit the hosts file (/etc/hosts) to include IP addresses of all hosts. Here is an example for 4 machines:
127.0.0.1     localhost
192.168.1.50  m0
192.168.1.51  m1
192.168.1.52  m2
192.168.1.53  m3
I will assume that the master machine is m0. So, in each of the slave machines you also need to include the master IP address,
127.0.0.1     localhost
192.168.1.50  m0
2. Install NFS (Network File System) which allows the sharing and sync of folders between a set of network connected hosts. You can do this by installing the nfs-server on the master machine,
sudo apt-get install nfs-server
And install the nfs-client on each slave machine,
sudo apt-get install nfs-client
3. Now, we will start the mounting process. You first should locate the folder you need to mount. Let's say that the folder is /helala. We first will ask the master machine to share this folder by editing the /etc/exports file and adding the following line
/helala *(rw,sync)
You can do this in one statement by issuing,
sudo echo  /mirror *(rw,sync) >> /etc/exports
4. We will go now to the other hosts and finalize the mounting by first creating a folder to host the remote shared directory (in my case /helala). Then, we can issue the following command on each slave host,
sudo mount m0:/helala /helala
Unfortunately, we need to run this command on every boot. A better approach is to edit the /etc/fstab file and add the following line,
m0:/helala     /helala    nfs
In this way, the mount will be performed on every boot. Now, you can issue the following command to remount all shared directories,
sudo mount -a