NFS How-To

NFS How-To

2012-05-11. Category & Tags: Soft&Skills Soft&Skills, NFS, NFSD

Update: 2017-01-06
Warn 1: for non-English, use samba/sshfs instead. unless win has NFS v4 or above which can solve non-UTF8 problems.
Warn 2: svchost consumes 1.5GB ram, don’t know why.

See Also Links


Combining simlink (ln -s) with NFS may cause weird file path problems. We tried to have a link at NFS to Dropbox in nfs, also tried to have a link at home to mount point at /mnt. Both caused some minor path and file issues, but no series problems.


sudo -s
apt-get install -y nfs-kernel-server && \
mkdir /nfs && \
chmod -R 777 /nfs && \
chown -R nobody /nfs && \
vim /etc/exports
# e.g.:
/nfs *(fsid=0,rw,async,no_subtree_check,no_root_squash,no_all_squash)

Tip: fsid=x may be needed. This ID (0~255) must be unique for each shared directory, otherwise the later dir with repeated ID is recognized as an nickname of the previous dir with the same ID [ref].

WARN: it is, NOT 192.168.1.*

To run:

#sudo -s
sudo /usr/sbin/exportfs -af && \
sudo service nfs-kernel-server restart && \
sudo service nfs-kernel-server status

-f to flush & fresh.

To change UID/GID when exporting, use all_squash,anonuid=xxx,anongid=yyy. [serverfault]

(deprecated) To use usernames instead of IDs, use echo N > /sys/module/nfs/parameters/nfs4_disable_idmapping. [serverfault]

For Synology NAS, see the official tutorial and my notes.


temporarily #

sudo -s

sudo -s
apt-get -q install -y nfs-common && mkdir -p /mnt/nfsMountPoint && \
mount -t nfs serverIpOrDomain:/absolute/path /mnt/nfsMountPoint -o nolock
  1. Option -o nolock can be used for mount, which disables file locking. This setting is occasionally required when connecting to older NFS servers. ref.
  2. Use umount to unmount.

permanently #

sudo -s
apt-get -q install -y nfs-common && mkdir -p /local/nfsMountPoint && \
echo 'nfsServerOrIp:/absolute/path/    /local/nfsMountPoint   nfs    defaults  0  0' >> /etc/fstab

(yum install nfs-utils for CentOS/RedHat/Fedora)

defaults could be replaced by some of auto,nofail,noatime,nolock,intr,tcp,actimeo=1800. [ ref1, ref2 ]


set permission #

To have write permission, we need to set userId:groupId the same as server side.
Check server’s /etc/passwd for server side folder’s owner, it is usually 1000:1000 (in decimal base) for the 1st non-root ubuntu user, or 65534:65534 for nobody:nogroup.
Modify window regedit (the win sys service should be started once to have this reg key):

Windows Registry Editor Version 5.00


(if the .reg is used after enabling win NFS feature, restart the windows service or reboot, then remount.)

enable #

Enable the windows feature “Client for NFS”. ref

mount #

Run in cmd (NOT powerShell !!!)

mount <serverIpOrDomain>:<absolutePathFolderToShare> Z:
# e.g.:
mount Z:

To unmount: use umount, (ref)
Note: Persistent NFS mount (after reboot) is not an option with NFS. Also this scenario is not recommended and does not guarantee a sure shot solution (ref).


encoding problem (only in win???) #

Description: files created in win with non-ASCII chars will become question marks ‘?’ in linux, also when read again in win.
Solution: no way to solve, unless NFS v4. see super.user

To check nfs versions on server: nfsstat
To check on linux clinet: mount -v; nfsstat -m ref
To check on win client: ???


service nfs-kernel-server restart


The right side drive (Z:) is NFS, which shows wrong space usage, and display speed is much slower than SMB (left side, Y:) when mounted in windows. For space usage, by default, ext2/3/4 filesystems reserve 5% of the space to be useable only by root, see ref.