NFS (Network File System) is mode of connection basically developed for sharing of files and folders between Linux/Unix systems that was developed by Sun Microsystems in the 1980s. With the help of NFS, file sharing is possible between Unix to Linux system and Linux to Unix system or a Linux server to a Linux client.
Benefits of NFS
- NFS allows local access to remote files.
- It uses standard client/server architecture for file sharing between all *nix based machines.
- With NFS it is not necessary that both machines run on the same OS.
- With the help of NFS we can configure centralized storage solutions.
- Users get their data irrespective of physical location.
- No manual refresh needed for new files.
- Newer version of NFS also supports acl, pseudo root mounts.
- Can be secured with Firewalls and Kerberos.
Mounting a linux partition on a Linux server
NFS (Network File System) allows you to mount your local file systems over a network and remote hosts just as you may mount it on a local system to enable files and directory sharing.
Setup and Configure Linux Mounts on Linux Server
NFS packages are needed on the NFS Server as well as on NFS Client machine.
[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib [root@nfsserver ~]# yum install portmap (not required with NFSv4) [root@nfsserver ~]# apt-get install nfs-utils nfs-utils-lib
Now start the services on both machines.
[root@nfsserver ~]# /etc/init.d/portmap start [root@nfsserver ~]# /etc/init.d/nfs start [root@nfsserver ~]# chkconfig --level 35 portmap on [root@nfsserver ~]# chkconfig --level 35 nfs on
Complete the installation and prepare the two systems, server and client machine for file sharing. Create afterwards an export directory and edit the /etc/exports file. An export directory is the directory we intend to share files within
# mkdir /nfsshare
Now we need to make an entry in “/etc/exports” and restart the services to make our
directory shareable in the network.
# vi /etc/exports /nfsshare 192.168.0.101(rw,sync,no_root_squash)
In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP “192.168.0.101” with read and write (rw) privilege, you can also use hostname of the client in the place of IP in above example.
Mount Shared Directories on NFS Client
Now at the NFS client end, we need to mount that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.
# showmount -e 192.168.0.100 Export list for 192.168.0.100: /nfsshare 192.168.0.101
Above command shows that a directory named “nfsshare” is available at “192.168.0.100” to share with your server.
Mount Shared NFS Directory
To mount that shared NFS directory we can use following mount command.
# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare
The above command will mount that shared directory in “/mnt/nfsshare” on the client server.
You can verify it the following command.
[root@nfsclient ~]# mount | grep nfs sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) nfsd on /proc/fs/nfsd type nfsd (rw) 192.168.0.100:/nfsshare on /mnt type nfs (rw,addr=192.168.0.100)
The above mount command mounted the nfs shared directory on to nfs client temporarily, to mount an NFS directory permanently on your system across the reboots, make an entry in “/etc/fstab“.
# vi /etc/fstab
Add the following new line as shown below.
192.168.0.100:/nfsshare /mnt nfs defaults 0 0
Important commands for NFS
Some more important commands for NFS.
- showmount -e : Shows the available shares on your local machine
- showmount -e <server-ip or hostname>: Lists the available shares at the remote server
- showmount -d : Lists all the sub directories
- exportfs -v : Displays a list of shares files and options on a server
- exportfs -a : Exports all shares listed in /etc/exports, or given name
- exportfs -u : Unexports all shares listed in /etc/exports, or given name
- exportfs -r : Refresh the server’s list after modifying /etc/exports
Mounting windows on the linux system
1. Required packages for mounting a windows partition on the linux server
# yum install samba-client samba-common cifs-utils.
2. Create a local mount point:
# mkdir /mnt/win
Edit the /etc/fstab file and add the following line:
\\windows\mydir /mnt/win cifs user,uid=500,rw,suid,username=james,password=fred 0 0
Automount comes in handy when we want to avoid problems resulting from resources
on an unavailable mounted partition. We can set automount option as follows;
# mkdir /mymount
Then add the directory to auto.master file
# Sudo vim /etc/auto.master /mymount /etc/auto.mymount
Then edit the /etc/auto.mymount file you just entered:
# Sudo vim /etc/auto.mymount windows -fstype=cifs,rw,noperm,user=james,pass=fred ://windows/mydir