Posted on March 21, 2023 by nexonhost
How To Mount An NFS Share.
In this tutorial, we will show you how to manually and automatically mount an NFS share on Linux machines.
On Linux and UNIX operating systems, you can use the mount command to mount a shared NFS directory on a particular mount point in the local directory tree.
Network File System (NFS) is a distributed file system protocol that allows you to share remote directories over a network. With NFS, you can mount remote directories on your system and work with the remote files as if they were local files.
Installing NFS Client Packages
To mount an NFS share on a Linux system first you’ll need to install the NFS client package. The package name differs between Linux distributions.
Installing NFS client on Ubuntu and Debian:
sudo apt updatesudo apt install nfs-common
Installing NFS client on CentOS and Fedora:
sudo yum install nfs-utils
Manually Mounting an NFS File Systems
Mounting a remote NFS share is the same as mounting regular file systems.
To mount an NFS file system on a given mount point, use the mount command in the following form:
mount [OPTION...] NFS_SERVER:EXPORTED_DIRECTORY MOUNT_POINT
Use the steps below to manually mount a remote NFS share on your Linux system:
First, create a directory to serve as the mount point for the remote NFS share:
sudo mkdir /var/backups
Mount point is a directory on the local machine where the NFS share is to be mounted.
Mount the NFS share by running the following command as root or user with sudo privileges:
sudo mount -t nfs 10.10.0.10:/backups /var/backups
Where 10.10.0.10 is the IP address of the NFS server, /backup is the directory that the server is exporting and /var/backups is the local mount point.
On success, no output is produced.
If you want to specify additional mount options , use the -o option. Multiple options can be provided as a comma-separated list. To get a list of all mount options type man mount in your terminal.
To verify that the remote NFS volume is successfully mounted use either the mount or df -h command.
Once the share is mounted, the mount point becomes the root directory of the mounted file system.
When you are manually mounting the share, the NFS share mount does not persist after a reboot.
Automatically Mounting NFS File Systems with /etc/fstab
Generally, you will want to mount the remote NFS directory automatically when the system boots.
The /etc/fstab file contains a list of entries that define where how and what filesystem will be mounted on system startup.
To automatically mount an NFS share when your Linux system starts up add a line to the /etc/fstab file. The line must include the hostname or the IP address of the NFS server, the exported directory, and the mount point on the local machine.
Use the following procedure to automatically mount an NFS share on Linux systems:
Set up a mount point for the remote NFS share:
sudo mkdir /var/backups
Open the /etc/fstab file with your text editor :
sudo nano /etc/fstab
Add the following line to the file:
# <file system> <dir> <type> <options> <dump> <pass> 10.10.0.10:/backups /var/backups nfs defaults 0 0
Where 10.10.0.10 the NFS server IP address, /backup is the exported directory and /var/backups is the local mount point.
Run the mount command in one of the following forms to mount the NFS share:
mount /var/backups mount 10.10.0.10:/backups
The mount command, will read the content of the /etc/fstab and mount the share.
Next time you reboot the system the NFS share will be mounted automatically.
Unmounting NFS File Systems
The umount command detaches (unmounts) the mounted file system from the directory tree.
To detach a mounted NFS share, use the umount command followed by either the directory where it has been mounted or remote share:
umount 10.10.0.10:/backups umount /var/backups
If the NFS mount have an entry in the fstab file, remove it.
The umount command will fail to detach the share when the mounted volume is in use. To find out which processes are accessing the NFS share, use the fuser command:
fuser -m MOUNT_POINT
Once you find the processes you can stop them with the kill command and unmount the NFS share.
If you still have problems unmounting the share use the -l (–lazy) option which allows you to unmount a busy file system as soon as it is not busy anymore.
umount -l MOUNT_POINT
If the remote NFS system is unreachable, use the -f (–force) option to force an unmount.
umount -f MOUNT_POINT
Generally not a good idea to use the force option as it may corrupt the data on the file system.
We have shown you how to mount and unmount a remote NFS share. The same commands apply for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian and Linux Mint.