How to Automate NFS Share Mounting on Boot in Linux Using /etc/fstab

When managing multiple Linux servers or a home lab environment, you will frequently need to share files between machines. The Network File System (NFS) is one of the most robust and traditional ways to share directories across a network. While mounting an NFS share manually using the terminal is straightforward, that mount will disappear the moment your server reboots.

To ensure that your shared directories are always available, you must configure your system to mount the NFS share automatically upon boot. In Linux, this is achieved by adding a specific entry to the /etc/fstab file. This file acts as the master configuration document for all your disk drives and network mounts.

Why Use /etc/fstab for NFS Mounts?

The /etc/fstab (file systems table) file tells the Linux kernel exactly which file systems to mount, where to mount them, and what specific options to apply during the boot process. By adding your NFS share to this file, you eliminate the need for manual intervention after a system restart or a power failure. This is absolutely critical for automated servers, backup targets, or applications that rely on persistent network storage.

Prerequisites for Automating an NFS Mount

Before modifying your system configuration files, you must ensure that your machine is ready to communicate with the NFS server. You will need:

  • The IP address of the remote NFS server (for example, 192.168.1.50).
  • The exact path of the exported directory on the server (for example, /mnt/shared_data).
  • The nfs-common package installed on your local machine. If you are using Ubuntu or Debian, you can install this by running sudo apt install nfs-common.

How to Mount an NFS Share on Boot

Follow these steps to safely edit your configuration and automate the mounting process.

Step 1: Create a Local Mount Point

Your Linux system needs an empty directory to serve as the gateway to the remote files. This is called the mount point.

  1. Open your terminal.
  2. Create the directory by running: sudo mkdir -p /mnt/nfs_share

You can name the folder nfs_share anything you like, but placing it within the /mnt or /media directories is the standard Linux convention.

Step 2: Test the Mount Manually

Before committing any changes to your boot configuration, it is highly recommended to test the mount manually. If there is a network issue or a permission error, it is much easier to diagnose it now rather than during a system boot.

  1. Run the standard mount command: sudo mount 192.168.1.50:/mnt/shared_data /mnt/nfs_share
  2. Verify the files are accessible by running: ls /mnt/nfs_share

If you can see the remote files, the connection is successful. You should now unmount the share before proceeding by running: sudo umount /mnt/nfs_share

Step 3: Edit the /etc/fstab File

Now that you have confirmed the connection works, you can add the persistent entry.

  1. Open the file using a text editor with root privileges. We will use nano: sudo nano /etc/fstab
  2. Use your arrow keys to navigate to the very bottom of the file.
  3. Add a new line with the following syntax: 192.168.1.50:/mnt/shared_data /mnt/nfs_share nfs defaults,_netdev 0 0

Let’s break down exactly what this entry means:

  • 192.168.1.50:/mnt/shared_data: The location of the remote server and the folder it is sharing.
  • /mnt/nfs_share: The local folder you created in Step 1.
  • nfs: The type of file system being used.
  • defaults,_netdev: The mounting options. The _netdev option is incredibly important; it tells the operating system to wait until the network is fully online before attempting to mount this share, preventing boot delays or errors.
  • 0 0: These numbers tell the system to skip backing up this specific drive using the dump utility and to skip checking it for disk errors during boot.

Step 4: Save and Apply the Changes

  1. If you are using nano, save the file by pressing Ctrl + O, then press Enter.
  2. Exit the editor by pressing Ctrl + X.
  3. To force the system to read the new configuration and mount the share immediately without rebooting, run: sudo mount -a

If the command returns no errors, your configuration is correct. The NFS share will now automatically mount every time your Linux machine boots up.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.