This article will demonstrate how to mount an NFS share on Linux. The instructions will work for both Redhat and Ubuntu Operating Systems.
First, let’s define NFS. NFS stands for Network File System, which is a distributed file system protocol that allows you to share a directory over the network. These shares can be mounted on a file system and act the same as a local drive on the OS.
Install NFS Packages
First, you will need to install any required nfs packages.
apt update apt install nfs-common
dnf install nfs-utils
Manual NFS mount
The steps assume root privileges.
- Create a directory for the location of the mount for the NFS share
- Mount the NFS share to the directory created in the previous step
mount -t nfs 10.10.0.0:/mountA /mount/mountA
A few things to note:
- -t nfs means “type” nfs. While mount can usually detect the type, we recommend explicitly stating it.
- 10.10.0.0:/mountA is the NFS server and and name of the share or directory the NFS server is exporting. You can also use the FQDN hostname instead of the IP address.
- /mount/mountA is the mount point on the local server.
- Verify the mount was successful. The output should show the mount.
For more uses of the df command, we have written another article you may find useful.
Note: Remember this is a temporary mount that will NOT persist after a reboot. To create a persistent mount, proceed to the next section on using /etc/fstab.
Persistent NFS mount
While a temporary mount may be useful, a persistent mount that automatically mounts after a reboot will be the most common. For this we will be modifying the /etc/fstab directory to define the persistence.
The format of the /etc/fstab file is as follows:
<file system> <dir> <type> <options> <dump> <pass>
- file system – NFS server IP address or FQDN hostname and exported directory
- dir – The local mounting point
- type – Type of mount, in this case will be nfs
- options – defaults is okay for this example
- dump – 1 means backup with the dump utility, 0 means disable.
- pass – 0 to disable checking
To play on the manual mount example in the previous section, the fstab line should look like the following.
10.10.0.0:/mountA /mount/mountA nfs defaults 0 0
Now by running the
mount command the mount will go into affect, and we subsequently be mounted on each reboot.
Unmount NFS mount on Linux
Now that you have learned how to mount an NFS share on Linux, lets dive into how to unmount it.
First, to unmount an NFS share that was manually mounted, run the following command.
If the mount was defined in /etc/fstab it will be re-mounted on the next reboot. So if you want the mount to be permanently removed, remove the line in the fstab file.
If the file is in use when trying to unmount the share, you will have to kill the process accessing the NFS share. The path given in the command is the local mount point. Additionally
-f can be used to force the unmount.
fuser -m /mount/mountA
Conclusion – How to mount NFS share on Linux
This article has demonstrated how to mount an NFS share on Linux. Leave us a comment with any questions or let us know if you would like to see more examples of how to mount or manage mounts for NFS on Linux.
Read more of our articles on Linux.
Leave a Reply