filesystems/nfs
Contents
About
Export a filesystem
Server
1 aptitude install nfs-kernel-server
Create an entry in
/etc/exports
1 # /etc/exports: the access control list for filesystems which may be exported
2 # to NFS clients. See exports(5).
3 #
4 # Example for NFSv2 and NFSv3:
5 # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
6 #
7 # Example for NFSv4:
8 # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
9 # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
10
11 /media/space/tmp 192.168.182.0/24(rw,sync,no_subtree_check)
1 exportfs -av
Simple manual mount
Client
1 aptitude install nfs-common
Mount manually
Information about NFS mounts
Server
1 nfsstat -4 -s
Client
1 mountstat /path/to/mountpoint
showmount
Permissions
Mount options only state, who is able to mount the filesystem. Please see man 1 mount for user, group, users and owner.
Permissions like reading and writing are handled by filesystem permissions.
Please think twice, before you chown a directory recursively and destroy the remote permissions.
You may always ask yourself, if it is really necessary to mount the whole tree. Maybe a subtree is sufficient. And this subtree permissions may more likely be changed recursively.
Two systems may both write on the same filesystem one with user permissions and one of its group.
Posic-ACLs
For usage of the more flexible Posix-ACLs a additional package is necessary.
nfs4-acl-tools
This contains the
nfs4_editfacl
nfs4_getfacl
nfs4_setfacl
Tuning
Export options
Increase client read and write size (Default: 65536, 64KiB) to 1MiB
1 mount -o rsize=1048576,wsize=1048576 source:path mount/point
Network buffers
/proc/sys/net/core/ contains the tuneable for some network buffers that may optimize performance.
grep -H "" /proc/sys/net/core/*mem*
Maximum value is 2^31-1 = 2147483647 Let's try the maximum on server and client
You may persist this config across reboots with a file in /etc/sysctl.d
/etc/sysctl.d/net.conf
Other paths with info and tuneables:
/proc/fs/nfs
/proc/sys/fs/nfs
/sys/kernel/debug/tracing/events/nfs
/sys/fs/nfs
/sys/module/nfs
Show network buffers
net_buffers.sh
1 #!/bin/bash
2
3 declare -A MEMORY
4
5 while IFS="=" read -r KEY VALUE; do
6 MEMORY[$KEY]=$VALUE
7 done < <(grep -P 'mem \d+' /proc/net/sockstat \
8 |sed -r 's/^(.*): .*? mem ([0-9]+)/\1=\2/')
9
10 for KEY in "${!MEMORY[@]}"; do
11 KIB=$((${MEMORY[$KEY]} * 4))
12 BYTES=$((${MEMORY[$KEY]} * 2**12))
13 echo "$KEY: ${MEMORY[$KEY]} 4k pages, $KIB KiB, $BYTES Byte"
14 done
15
16 echo -e '\nCurrent kernel config [Byte]:'
17 sysctl -a \
18 |grep -P 'net\..*\.((udp|tcp)_)?[rw]?mem' \
19 |column -t
Example output
1 UDP: 0 4k pages, 0 KiB, 0 Byte
2 TCP: 581 4k pages, 2324 KiB, 2379776 Byte
3
4 Current kernel config [Byte]:
5 net.core.rmem_default = 212992
6 net.core.rmem_max = 212992
7 net.core.wmem_default = 212992
8 net.core.wmem_max = 212992
9 net.ipv4.tcp_mem = 45300 60400 90600
10 net.ipv4.tcp_rmem = 4096 131072 6291456
11 net.ipv4.tcp_wmem = 4096 16384 4194304
12 net.ipv4.udp_mem = 90600 120800 181200
13 net.ipv4.udp_rmem_min = 4096
14 net.ipv4.udp_wmem_min = 4096
Mount options
Soft vs Hard
Determines the recovery behavior of the NFS client after an NFS request times out.
The mount type determines how the NFS client handles a crash of a NFS server.
Hard
Default
If neither option is specified (or if the hard option is specified), NFS requests are retried indefinitely.
No error is reported by the NFS client to the application.
1 mount -o hard,intr server:/path/to/share /media/nfs/share
It is recommended to be combined with an additional flag intr to make the IO-operation interruptible. The option is obsolete after Kernel 2.6.25, as it's hardcoded into the kernel.
To stop the NFS process you need to
kill -9
Pro
- IO-operation is stalled (and the process might even freeze) until the NFS server reappears
- Data integrity ensured
Contra
- The operation is continuously tried and may impose a significant amount of traffic
Soft
If the soft option is specified, then the NFS client fails an NFS request after retrans retransmissions have been sent, causing the NFS client to return an error to the calling application.
Defaults
Option |
Value [Unit] |
retry |
2 [minutes] |
timeo |
tcp -> 600 [deciseconds] |
1 mount -o soft,timeo=5,retry=5 server:/path/to/share /media/nfs/share
Pro
- Fast response
- Preserves client responsiveness.
Contra
- Data integrity is put at risk
- Async caches are problematic.