Tuesday 16 April 2013

Mount a Directory

Mount a Directory from one Server to Another Server

The easiest way to share files or directories between linux servers is to mount a directory from one server to another server using nfs. Assuming we had 2 servers, the easiest way mount a folder from one linux machine onto another would be to export the directory you wish to share on server1, and mount it on server2.
Step 1 – Sharing the directory on server1
To export the directory, you need to add it to the
/etc/exports
file on server1, and give rights to the second server so it may mount it. On server1, open the exports file as below:
# vim /etc/exports
Then add the following to the exports file:
/path/to/shared/directory/ server2(rw)
Now save and close the file. This would give server2 read and write access to the shared folder on server1 called
/path/to/shared/directory/
.
Anytime you make changes to the
/etc/exports
file, the following command must be run on the server to update the nfs server:
# exportfs -avr
Step 2 – Mounting the directory on server2
Now you need to mount the shared folder on server2. To do this we will be editing the
/etc/fstab
file on server2.
# vim /etc/fstab
Then add the following to the fstab file:
server1:/path/to/shared/directory/ /directory/on/server2 nfs hard,intr 0 0
Now save and close the file. This will point
/directory/on/server2
on server2 to
/path/to/shared/directory/
on server1.
To remount all nfs entries in fstab and activate the mount, run the following command:
# mount -t nfs -a

1 comment:

  1. Nice to see sharing such useful and important Point related to Linux..Big Thanks!! knowledge Sharing in any form always help others ..keep it up!!

    ReplyDelete