Network filesystems

NFS

The Network Files System (NFS) allows to access files and directories over the network on Linux (Unix) computers. The computer holding those data must have a nfs server and the computer requesting access to the data must have a nfs client.

Note

There are different major versions and therefore incompatibilities. Having everywhere the same version obviously is a good idea.

Important

A kernel with nfs features turned on is required. There are separated settings for nfs server and nfs client.

The nfs-utils package needs to be installed on all computers involved.

For Gentoo Linux check also the nfs useflags indicating the nfs version.

Finally, check if your number assignments for user and group names are consistent between the computers. cat /etc/passwd and cat /etc/group

See also: http://nfs.sourceforge.net/

Nfs server

The configuration file that has to be edited on the server is /etc/exports to define what will be available on the network. See also man exports

<server directory> <client computer name>(rw)
<other server directory> 192.168.1.33(rw)

or as example

/home/lindegur/Urs black(rw,async,no_subtree_check)

Either the clients IP address or the name of the computer have to be added. An example to give read only access to the multimedia directory:

/home/lindegur/media 192.168.1.3(ro,async,no_subtree_check)

Warning

Avoid exporting symlinks

mounting As man 5 exports tells, wildcards in ip addresses might work just per accident, so avoid to use them use a netmask instead.

No space is allowed in front of the ( character.

To give all computer in a home net access use a netmask

/home/lindegur/media 192.168.1.0/255.255.255.0(rw,async,no_subtree_check)

or in the form counting the bits in the netmask having a 1

/home/lindegur/media 192.168.1.0/24(rw,async,no_subtree_check)

To start the server:

  • OpenRC: /etc/init.d/nfs start and consider to add it to the init scripts rc-update add nfs default

  • systemd: systemctl start rpcbind nfs-server and systemctl enable rpcbind nfs-server

After editing and when the server is already running type exportfs -a

Some commands to show if the system is happy:

rpcinfo -p to see if the daemons are running

showmount -e to see what the server exports

showmount -a to see who accesses the server

Or directly from the kernel cat /proc/fs/nfs/exports

nfs does not use inetd or xinetd, however it considers the two files /etc/hosts.allow and /etc/hosts.deny from xinetd for more details.

Nfs client

The data on those computers can simply be mounted as it would be a local disk drive:

mount -t nfs <remote computer>:/<remote directory></local mounting point>

An example:

mount -t nfs 192.168.1.33:/home/lindegur/media /mnt/media

or

mount -t nfs <computername>:/home/lindegur/media /mnt/media

When done do a umount </local mounting point>

It is also possible to have it mounted without typing a lot by using a line in /etc/fstab such as:

<remote computer>:/<remote dir> </local mounting point> nfs user,auto,exec 0 0

mount -a gets everything mounted as defined in /etc/fstab . The option auto is quite important, when the server is running during boot of the client the clients mounts the network drives automatically. Otherwise they would have to be mounted manually. If the remote computer is not accessible then boot struggles with retraining to connect and finally after a long time out it continuous with its boot process.

If the nfs server is not always online noauto can be set in /etc/fstab so it will not cause delays on boot due to failures and retries to connect the unavailable nfs server.

<remote computer>:/<remote directory> </local mounting point> nfs   user,noauto,exec 0 0

If the server is up, drives can be mounted manually by mount /mnt/<mountpoint>.

The automounter autofs is a better option since it mounts the network drives just on demand when they are getting accessed.

Nfs troubles

Before jumping into deep troubleshooting check if ping -c3 <IP> works. this way routing and firewall issues will pop up.

Since time is moving and the system evolves things can happen:

Version mismatch.

Check what what the kernels support:

zcat /proc/config.gz 2>/dev/null | grep NFS | grep -E "NFS[_-]"

Check versions of the server: nfsdctl version or nfsdctl version

If getting IP6 errors when start the server then comment or uncomment IP6 stuff in /etc/netconfig.

If getting:

mount.nfs: an incorrect mount option was specified

and run nfs version 3 on a new system troubles might occur since it wants to take version 4. it can be fixed with modifying /etc/fstab to hold the nfsvers=3 parameter:

<remote computer>:<remote directory> <local mounting point> nfs   user,auto,exec,nfsvers=3 0 0

Up to version 3 users required the same uid and gid on the machines. NFS version 4 introduced /etc/idmapd.conf to allow flexibility. journalctl -xe | grep -i nfs systemctl status nfs-idmapd


Linurs startpage