Posted in Technology

How to set up disk sharing for Linux computers with NFS

If your home or office is powered by Linux computers, you may want to have a system for sharing files. Our small office has been using file sharing software called NFS (Network File System) for quite some time now, and we are pretty happy with it. Here is a brief how-to guide for setting up NFS file sharing for Linux computers.

NFS was developed by Sun Microsystems for the Solaris product range that was built on Unix. NFS has been around for a long time, and it is considered a solid file sharing software for Linux and Unix operating systems. As time has passed, however, NFS Windows software hasn’t kept up with. NFS is designed to provide disk sharing on a LAN (Local Area Network). It is not a cloud service that can be accessed from anywhere with any device.

If you are familiar with the native file sharing functionality in Windows or in Mac, NFS is similar with them. Other disk sharing choices for Linux are Samba and sshfs (command line file access that uses ssh).

NFS is a client-server system. You designate one or more computers as the server, and the others are clients. The server shares a specified disk to clients that can read from and write to (depending on the configuration) the shared disk. The server and clients must be connected to the same LAN.

Installing NFS

In our small office, Linux computers run Debian or a distribution built on Debian, like Ubuntu, and that is the environment where the following instructions have been tested.

Install the NFS server software

The computer that shares its disk requires the server module of NFS. In systems that have apt packaging, the command to install is:

apt-get install nfs-kernel-server

After the software has been installed, you have to tell NFS which disk you want to share. The configuration file’s name is: /etc/exports

The file features examples how to specify the disk to be shared. You can use the hostname of the server computer or its IP address in the LAN to specify the shared disk. For instance (edit names to match your system):

/media/username/SSD1TB/docs blackberry(rw,sync,no_subtree_check)
or
/media/username/SSD1TB/docs 192.168.10.0/24(rw,sync,no_subtree_check)

Run the command below to tell the NFS server about the new disk share:

exportfs -ra

You can verify that NFS server understood what you wanted to say:

exportfs -s

Install the NFS client

Computers that access the shared disk need a client software that is installed like this:

apt-get install nfs-common

Once the client has been installed, you can mount the shared disk specified on the server as a local disk for the client (here, /media/sername/nfsshare is the local name the client accesses):

mount -v -t nfs blackberry:/media/username/SSD1TB/docs  /media/username/nfsshare/

If it doesn’t work but throws error messages like:

mount.nfs: mount(2): Permission denied
mount.nfs: access denied by server while mounting

Try and specify the NFS version for the mount command:

mount -v -t nfs -o nfsvers=3 blackberry:/media/username/SSD1TB/backup /media/username/nfsshare/

Troubleshooting

If your NFS client was able access a shared NFS disk but the connection hangs up (in the worst case, your computer freezes), it may mean that the connection has broken down or the server has been shut down. Try to force disconnect from the NFS server:

umount -f /media/username/nfsshare
or
umount -l /media/username/nfsshare

You can display the mounted disks on the client:

df -h

On the server, check the status of the NFS server:

systemctl status nfs-server

And restart NFS server if needed:

systemctl restart nfs-server

Also on the server, verify what is shared:

showmount -e hostname (or ip address instead of the hostname)

This article has more tips for troubleshooting.

NFS on Windows

NFS client applications such as FreeNFS and NFSClient are available for Windows PCs, but getting them to run on recent versions of Windows seems to be tricky. We only tried them briefly and didn’t succeed, but if someone has managed to get them to work, please share your tips.

Leave a Reply

Your email address will not be published.


CAPTCHA Image