Tag Archives: NFS

NFS server/client setup

As always, first thing is first ;)  Make sure you have the correct kernel options enabled.

File systems --->
  [*] Dnotify support
  [*] Network File Systems --->
        <*>   NFS client support
        <*>     NFS client support for NFS version 4
        [*]   NFS client support for NFSv4.1
        <*>   NFS server support
        [*]     NFS server support for NFS version 4
        [*]       NFSv4.1 server support for Parallel NFS (pNFS)

Depending on other options enabled in the kernel, version 3 may be auto selected and non-optional.

Once compiled and built.  We can install the required apps.  Make sure you enable to required USE flags.

emerge -av net-fs/nfs-utils

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild R ~] net-fs/nfs-utils-2.1.1::gentoo USE="libmount nfsidmap nfsv4 nfsv41 tcpd uuid -caps -ipv6 -kerberos -nfsdcld (-selinux)"

SERVER:

Now we'll create the directory structure.  The first line is the virtual root followed by each filesystem.

mkdir /export
mkdir /export/videos
mkdir /export/music

Now to add the fstab entries.  I've set the ro option as I only want the local server to write.

/NAS/Videos /export/videos none bind,ro 0 0
/NAS/Music /export/music none bind,ro 0 0

Then mount them.

mount -a

On to the exports config.

vi /etc/exports
# /etc/exports: NFS file systems being exported. See exports(5).

/export <client hostname>(insecure,rw,sync,no_subtree_check,crossmnt,fsid=0)
/export/videos <client hostname>(insecure,ro,sync,no_subtree_check,crossmnt)
/export/music <client hostname>(insecure,ro,sync,no_subtree_check,crossmnt)

Just one more little tweak.  Cat the following file.

# cat /proc/fs/nfsd/nfsv4recoverydir
/var/lib/nfs/v4recovery

Now create the directory.

mkdir /var/lib/nfs/v4recovery

Without this, there will be errors in the syslog and potentially erratic performance on the client(s).

We're using systemd for this, so let's start the daemons.

systemctl start rpcbind nfs-server

And enable at boot.

systemctl enable rpcbind nfs-server

CLIENT:

For systemd, the nfs-client service will be started automatically when systemd detects that exported directories are being mounted.

So let's mount!

mount <server hostname>:/music /music
mount <server hostname>:/videos /videos

To make persistent, add the following:

<server hostname>:/videos /mnt/videos nfs4 ro,auto,_netdev,noexec 0 0
<server hostname>:/music/ /mnt/music nfs4 ro,auto,_netdev,noexec 0 0