Oct 10, 2023 5 min read

How to Mount an NFS Share on Linux

Mount an NFS Share on Linux with our step-by-step tutorial. It is a widely used protocol that allows files to be shared over a network.

Mount an NFS Share on Linux
Table of Contents

Introduction

Before we begin talking about how to mount an NFS Share on Linux, let's briefly understand – What is NFS ?

NFS, which stands for Network File System, is a widely used protocol that allows files to be shared over a network. It enables multiple computers to access and use the same files simultaneously, making it efficient for collaborative work and data storage.

NFS simplifies file sharing by eliminating the need for physical storage devices and providing a seamless network experience. The mount command allows you to attach a remote NFS filesystem to a local filesystem at a specified mount point. Discover more about NFS and its benefits for smooth file access and improved productivity.

In this tutorial, you will mount an NFS Share on Linux. We will also address a few FAQs on how to mount an NFS Share on Linux.

Advantages of NFS

  1. Simplicity: NFS offers a straightforward method to share files without the need for complex configurations.
  2. Collaboration: Multiple users can access and modify files simultaneously, facilitating seamless teamwork.
  3. Remote Access: Users can access files remotely, opening up opportunities for flexible and remote work environments.
  4. Data Centralization: NFS allows files to be stored in one central location, simplifying data management and backup processes.
  5. Efficiency: With NFS, files can be accessed and transferred quickly, resulting in improved productivity.

Installing NFS Client Packages

To mount an NFS share on a Linux machine, the NFS client package must be installed first. Each Linux distribution has its unique name for the package.

  • Installing the NFS client on Ubuntu and Debian:
sudo apt update
sudo apt install nfs-common
  • NFS client installation on CentOS and Fedora:
sudo yum install nfs-utils

Manually Mounting an NFS File Systems

Mounting normal file systems is the same as mounting a remote NFS share.

Use the mount command in the format shown below to mount an NFS file system on a specified mount point:

mount [OPTION...] NFS_SERVER:EXPORTED_DIRECTORY MOUNT_POINT

To manually mount a remote NFS share on your Linux machine, follow the instructions below:

  1. First, create a directory that will act as the remote NFS share's mount point:
sudo mkdir /var/backups

If you want to access an NFS share on your local system, you'll need to provide a mount point, which is a directory on your machine.

2. The NFS share may be mounted by using the following command as root (or a user with sudo privileges):

sudo mount -t nfs 10.10.0.10:/backups /var/backups

Where /backup is the directory that the server is exporting, 10.10.0.10 is the NFS server's IP address, and /var/backups is the local mount point.

If the operation completes successfully, no output is generated.

The -o option may be used to provide mount options. You may provide several choices by entering them as a comma-separated list. Enter "man mount" into the terminal to get a complete rundown of the mount options.

3. Either the mount or df -h command may be used to check whether the remote NFS storage was mounted successfully.

When a shared folder is mounted, the mount point is used as the starting point for all files in that folder.

When the share is mounted manually, the NFS mount is temporary and will be removed when the computer is rebooted.

Automatically Mounting NFS File Systems with /etc/fstab

In most cases, having the remote NFS directory mounted immediately at system startup is the best course of action.

When the system boots up, it reads the /etc/fstab file, which includes a series of entries that specify where, how, and which filesystems will be mounted.

You may have Linux automatically mount an NFS share at system startup by adding a line to the /etc/fstab file. Specify the NFS server's hostname or IP address, the exported directory, and the local mount point on the line.

To automatically mount an NFS share on a Linux machine, perform these steps:

  1. For the remote NFS share, create a mount point:
sudo mkdir /var/backups

2. Open your text editor and the /etc/fstab file:

sudo nano /etc/fstab

3. 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 /backup is the exported directory, 10.10.0.10 is the NFS server's IP address, and /var/backups is the local mount point.

4. To mount the NFS share, use the mount command in one of the following formats:

mount /var/backups
mount 10.10.0.10:/backups

When you run the mount command, it will check to see whether the share is listed in /etc/fstab and if so, it will mount it.

Restarting the machine will cause the NFS share to be automatically mounted.

Unmounting NFS File Systems

The umount command removes a file system from a file system mount point.

The umount command, followed by the directory where the NFS share is mounted or the name of the remote share, will unmount the share.

umount 10.10.0.10:/backups 
umount /var/backups

If there is already an item for the NFS mount in the fstab file, delete it.

If the mounted volume is in use, the umount command will fail to disconnect the share. The fuser command may be used to determine which processes are using the NFS share.

fuser -m MOUNT_POINT

Once the processes have been located, they may be terminated using the kill command, and the NFS share can be unmounted.

If you are still having trouble unmounting the share, try using the -l (—lazy) option, which will enable you to unmount a busy file system as soon as it is no longer in use.

umount -l MOUNT_POINT

Use the -f (—force) option to compel an unmount if the remote NFS system is not accessible.

umount -f MOUNT_POINT

Generally, it's not a good idea to utilize the force option since it might damage the file system's contents.

FAQs to Mount an NFS Share on Linux

What permissions are required to mount an NFS share? 

You need root privileges or be a sudoer to mount an NFS share on Linux.

How can I check if NFS is installed on my Linux system? 

Type the command showmount -e localhost to see if NFS is installed. If it is, it will display the available exported shares.

What if I receive a "Permission Denied" error when mounting an NFS share? 

Ensure that the NFS server's export configuration allows access to your client's IP or network range, and check that the permissions on the shared directory are properly set.

Can I mount more than one NFS share on a single Linux system? 

Yes, you can mount multiple NFS shares by specifying different mount points for each share.

How do I make NFS mounts persistent across system reboots? 

Edit the /etc/fstab file and add an entry for each NFS mount, specifying the server, share, local mount point, and desired mount options.

Is it necessary to restart the system after modifying /etc/fstab? 

No, you don't need to reboot. Instead, you can remount all the filesystems listed in /etc/fstab by running mount -a as root or using sudo.

Can I specify a username and password when mounting an NFS share? 

NFS doesn't directly support username/password authentication. However, you can set up NFS with Kerberos or use alternative solutions like SSHFS to mount remote directories securely.

Conclusion

We've shown how to connect to and disconnect from a remote NFS server. Any Linux distribution, such as Ubuntu, CentOS, RHEL, Debian, or Linux Mint, may use the same commands.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.