Persistent NFS with FSTab

If you want to mount a Samba network file share persistently in linux, you will want to use fstab. With fstab, the share will be remounted when the system boots, so services that depend on the share will be able to function.

Test First!

Before adding the network file share to fstab, test it with mount. For my environment the resulting mount command was:

sudo mount -t cifs //<NFS server>/<NFS path> /mnt/nfs_downloads/ -o username=<username>,password=<password>,uid=$(id -u),gid=$(id -g),context="system_u:object_r:container_file_t:s0"

Notice the context in the options section to provide an SELinux context to the file share. This will be important to you in Fedora, Centos, RHEL or any other environment using SELinux. In my case, the files here needed to be accessed by a containerized application, so I set the container_file_t context.

Finally, with a working mount, unmount the share:

sudo umount /mnt/nfs_downloads

Configure fstab

Configuring fstab to correspond to the above mount, we add a line to /etc/fstab which looks like the following:

//<NFS server>/<NFS path> /mnt/nfs_downloads/ cifs username=<username>,password=<password>,uid=<uid number>,gid=<gid number>,context="system_u:object_r:container_file_t:s0" 0 0

Notice that uid and gid have been changed from $(id -u) and $(id -g) to the numbers corresponding to a user directly. This is because fstab is not running in your interactive shell but at startup, and the uid and gid will not yet be set to the expected values. Reload fstab

Reloading fstab can be done by restarting the machine. However, this is not always convenient. Alternatively you can reload fstab using mount -a:

sudo mount -av

In conclusion

You now have a remote network filesystem mounted persistently to the host using fstab. Optionally, you’ve configured the share with an SELinux context that will allow access to a containerized application.