Simple NFSv4 configuration for Debian and Ubuntu

NFSv4 offers a lot of advantages (speed, security, ...) to NFSv3, but clear documentation online on how to set it all up is a bit hard to find. Especially if you're not interested in specific features like kerberos, and just want to upgrade your simple local-network NFSv3 setup to NFSv4. Here's an example of how I've installed it.

One difference between NFSv3 and NFSv4 you have to grasp if you want to use NFSv4, and know how NFSv3 works, is that with NFSv4 you export only one filesystem tree. This means you probably have to setup a new tree with bind mounts in it to the real directories.

But the first thing you have to do, is install nfs-kernel-server on both the NFS client and the NFS server. This contains the idmapd daemon which they both need.

Server setup

In my setup, I want to export the /home, /etc and /var directories to my backup server. I've created an '/export' directory, with empty directories 'home', 'etc' and 'var' in it:

mkdir -p /export/home
mkdir /export/etc
mkdir /export/var

On top of those empty 'home', 'etc' and 'var' directories, I make a bind mount to the real /home, /etc and /var directories. Here's what I added to /etc/fstab:

/etc            /export/etc     none    ro,bind         0       0
/home           /export/home    none    ro,bind         0       0
/var            /export/var     none    ro,bind         0       0

Now, let's setup /etc/exports:

/export                 192.168.1.5(ro,sync,fsid=0,nohide,no_subtree_check,no_root_squash)
/export/home            192.168.1.5(ro,sync,nohide,no_subtree_check,no_root_squash)
/export/etc             192.168.1.5(ro,sync,nohide,no_subtree_check,no_root_squash)
/export/var             192.168.1.5(ro,sync,nohide,no_subtree_check,no_root_squash)

Mental note: the top-directory (/export in this case) needs the 'fsid=0' argument.

Now, restart nfs-kernel-server:

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

Client setup

Create a directory where the NFS share can be mounted. I just created an /nfs directory, and below that is the hostname of the NFS server (in my case 'ninja'). So:

mkdir -p /nfs/ninja

Add a line to /etc/fstab on the NFS client:

192.168.1.25:/    /nfs/ninja   nfs4        ro      0       0

Since NFSv4 only exports one filesystem tree, you can refer to it as '/'. (Because I use the NFS mount for backup purposes, I mount it read-only, as specified by the 'ro' option)

Now, restart nfs-kernel-server on the NFS client (this will start the necessary idmapd daemon):

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

Almost done. You should now be able to mount the share on the client:

mount /nfs/ninja

Done. Beer!

 
blog comments powered by Disqus