NFS v4 (without Kerberos)

https://help.ubuntu.com/community/NFSv4Howto
http://www.cyberciti.biz/faq/how-to-ubuntu-nfs-server-configuration-howto/
new: http://notes.setvisual.de/NFSv4%20mit%20Ubuntu (German, not yet taken into account for the following information)

NFSv4 client

sudo apt-get install nfs-common

NFSv4 server

sudo apt-get install nfs-kernel-server

NFS v4 Server

NFSv4 exports exist in a single pseudo filesystem, where the real directories are mounted with the --bind option. Here is some additional information regarding this fact.

Let's say we want to export our users' home directories in /home/users. First we create the export filesystem:

sudo mkdir /export
sudo mkdir /export/users

and mount the real users directory with:

sudo mount --bind /home/users /export/users

To save us from retyping this after every reboot we add the following line to /etc/fstab

/home/users    /export/users   none    bind  0  0

In /etc/default/nfs-kernel-server we set:

NEED_SVCGSSD=no

because we are not activating NFSv4 security this time.

In /etc/default/nfs-common we set:

NEED_IDMAPD=yes
NEED_GSSD=no

To export our directories to a local network 192.198.1.0/24
we add the following two lines to /etc/exports

/export       192.168.1.0/24(rw,fsid=0,insecure,no_subtree_check,async)
/export/users 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)

Restart the service

sudo /etc/init.d/nfs-kernel-server restart

NFSv4 Client

On the client we can mount the complete export tree with one command:

sudo mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/ /mnt

We can also mount an exported subtree with:

sudo mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/users /home/users

To save us from retyping this after every reboot we add the following line to /etc/fstab:

nfs-server:/   /mnt   nfs4    _netdev,auto  0  0

where the auto option mounts on startup and the _netdev option waits until network devices are loaded. If you have a slow network connection and are not establishing mount at reboot, you can change the line in etc/fstab:

nfs-server:/    /mnt   nfs4    noauto  0  0

and execute this mount after a short pause once all devices are loaded. Add the following lines to /etc/rc.local

sleep 5
mount /mnt

If you experience Problems like this:

Warning: rpc.idmapd appears not to be running.
 All uids will be mapped to the nobody uid.
 mount: unknown filesystem type 'nfs4'

then you need to set in /etc/default/nfs-common:

NEED_IDMAPD=yes

and restart nfs-common

sudo /etc/init.d/nfs-common restart

The "unknown Filesystem" Error will disappear as well.

Resources

Comments