Difference between revisions of "NFS"
(→Using autofs: corrected link to autofs#NFS network mounts) |
|||
(30 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:File systems]] | ||
[[Category:Networking]] | [[Category:Networking]] | ||
+ | [[ar:NFS]] | ||
[[de:Network File System]] | [[de:Network File System]] | ||
− | |||
[[es:NFS]] | [[es:NFS]] | ||
[[fr:NFS]] | [[fr:NFS]] | ||
Line 10: | Line 11: | ||
{{Article summary heading|Related}} | {{Article summary heading|Related}} | ||
{{Article summary wiki|NFS Troubleshooting}} - Dedicated article for common problems and solutions. | {{Article summary wiki|NFS Troubleshooting}} - Dedicated article for common problems and solutions. | ||
− | |||
{{Article summary end}} | {{Article summary end}} | ||
From [[Wikipedia: Network File System|Wikipedia]]: | From [[Wikipedia: Network File System|Wikipedia]]: | ||
− | :''Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.'' | + | : ''Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.'' |
− | == | + | == Installation == |
− | Both client and server only require the [[ | + | |
+ | Both client and server only require the [[pacman|installation]] of the {{Pkg|nfs-utils}} package. | ||
{{Note|It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in sync. Without accurate clocks on all nodes, NFS can introduce unwanted delays! The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.}} | {{Note|It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in sync. Without accurate clocks on all nodes, NFS can introduce unwanted delays! The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.}} | ||
Line 23: | Line 24: | ||
===Server=== | ===Server=== | ||
+ | |||
==== ID mapping ==== | ==== ID mapping ==== | ||
+ | |||
Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name. | Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name. | ||
Line 38: | Line 41: | ||
Nobody-Group = nobody | Nobody-Group = nobody | ||
</nowiki>}} | </nowiki>}} | ||
+ | |||
==== File system ==== | ==== File system ==== | ||
+ | |||
{{Note|For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point only. The following example illustrates this concept.}} | {{Note|For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point only. The following example illustrates this concept.}} | ||
Define any NFS shares in {{ic|/etc/exports}} which are relative to the NFS root. In this example, the NFS root will be {{ic|/srv/nfs4}} and we will be sharing {{ic|/mnt/music}}. | Define any NFS shares in {{ic|/etc/exports}} which are relative to the NFS root. In this example, the NFS root will be {{ic|/srv/nfs4}} and we will be sharing {{ic|/mnt/music}}. | ||
− | + | # mkdir -p /srv/nfs4/music | |
Read/Write permissions must be set on the music directory so clients may write to it. | Read/Write permissions must be set on the music directory so clients may write to it. | ||
Line 49: | Line 54: | ||
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command: | Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command: | ||
− | + | # mount --bind /mnt/music /srv/nfs4/music | |
To make it stick across server reboots, add the bind mount to {{ic|fstab}}: | To make it stick across server reboots, add the bind mount to {{ic|fstab}}: | ||
Line 57: | Line 62: | ||
==== Exports ==== | ==== Exports ==== | ||
+ | |||
Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in {{ic|exports}}: | Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in {{ic|exports}}: | ||
{{hc|/etc/exports|<nowiki> | {{hc|/etc/exports|<nowiki> | ||
Line 68: | Line 74: | ||
If you modify {{ic|/etc/exports}} while the server is running, you must re-export them for changes to take effect: | If you modify {{ic|/etc/exports}} while the server is running, you must re-export them for changes to take effect: | ||
− | {{ | + | # exportfs -rav |
+ | |||
+ | ==== Starting the server ==== | ||
+ | |||
+ | [[Daemons|Start]] {{ic|rpc-idmapd}} and {{ic|rpc-mountd}} services. If you want it running at boot time, enable it. Note that these units require other services, which are launched automatically by [[systemd]]. | ||
− | ==== | + | ==== Firewall configuration ==== |
− | [[ | + | To enable access through a firewall, tcp and udp ports 111, 2049, and 20048 need to be opened. To configure this for [[iptables]], edit {{ic|/etc/iptables/iptables.rules}} to include the following lines: |
− | ===Client=== | + | {{hc|/etc/iptables/iptables.rules|<nowiki> |
− | Clients need {{Pkg|nfs-utils}} to connect, | + | -A INPUT -p tcp -m tcp --dport 111 -j ACCEPT |
+ | -A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT | ||
+ | -A INPUT -p tcp -m tcp --dport 20048 -j ACCEPT | ||
+ | -A INPUT -p udp -m udp --dport 111 -j ACCEPT | ||
+ | -A INPUT -p udp -m udp --dport 2049 -j ACCEPT | ||
+ | -A INPUT -p udp -m udp --dport 20048 -j ACCEPT | ||
+ | </nowiki>}} | ||
+ | |||
+ | To apply changes, restart {{ic|iptables}} service. | ||
+ | |||
+ | === Client === | ||
+ | |||
+ | Clients need {{Pkg|nfs-utils}} to connect, and to avoid an approx 15 seconds delay with an accompanying error in dmsg that reads, "RPC: AUTH_GSS upcall timed out," users will need to start {{ic|rpc-gssd}} service on any client. | ||
+ | |||
+ | {{Note|NFS4 servers do not need to run this service.}} | ||
+ | |||
+ | ==== Mounting from Linux ==== | ||
− | |||
Show the server's exported filesystems: | Show the server's exported filesystems: | ||
− | + | $ showmount -e servername | |
Then mount omitting the server's NFS export root: | Then mount omitting the server's NFS export root: | ||
− | + | # mount -t nfs4 servername:/music /mountpoint/on/client | |
+ | |||
+ | ===== /etc/fstab settings ===== | ||
− | |||
Using [[fstab]] is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit {{ic|/etc/fstab}} file, and add an appropriate line reflecting the setup. Again, the server's NFS export root is omitted. | Using [[fstab]] is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit {{ic|/etc/fstab}} file, and add an appropriate line reflecting the setup. Again, the server's NFS export root is omitted. | ||
+ | |||
{{hc|/etc/fstab|<nowiki> | {{hc|/etc/fstab|<nowiki> | ||
servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0 | servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0 | ||
</nowiki>}} | </nowiki>}} | ||
− | {{Note| | + | {{Note|Consult the NFS and mount man pages for more mount options.}} |
+ | |||
Some additional mount options to consider are include: | Some additional mount options to consider are include: | ||
− | + | ; rsize and wsize: The {{ic|rsize}} value is the number of bytes used when reading from the server. The {{ic|wsize}} value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput. This is not universal. It is recommended to test after making this change, see [[#Performance tuning]]. | |
− | |||
− | |||
− | |||
− | The {{ic| | + | ; timeo: The {{ic|timeo}} value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value. |
− | The {{ic| | + | ; intr: The {{ic|intr}} option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share. |
− | The {{ic| | + | ; _netdev: The {{ic|_netdev}} option tells the system to wait until the network is up before trying to mount the share. systemd assumes this for NFS, but anyway it is good practice to use it for all types of networked filesystems |
− | + | ===== Using autofs ===== | |
− | + | Using [[autofs]] is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See [[autofs#NFS network mounts]] for details. | |
− | Using [[autofs]] is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See [[autofs#NFS | ||
==== Mounting from Windows ==== | ==== Mounting from Windows ==== | ||
− | {{ | + | |
+ | {{Note|Only the Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 include "Client for NFS".}} | ||
NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default). | NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default). | ||
To install the service go to "Programs and features" in the Control Panel and click on "Turn Windows features on or off". Locate "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS"). | To install the service go to "Programs and features" in the Control Panel and click on "Turn Windows features on or off". Locate "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS"). | ||
− | Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right click on client | + | Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right click on ''client > properties''. |
{{Warning|Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}} | {{Warning|Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}} | ||
Line 123: | Line 148: | ||
==== Mounting from OS X ==== | ==== Mounting from OS X ==== | ||
− | {{ | + | |
+ | {{Note|OS X by default uses an insecure (>1024) port to mount a share.}} | ||
Either export the share with the {{ic|insecure}} flag, and mount using Finder: | Either export the share with the {{ic|insecure}} flag, and mount using Finder: | ||
Line 129: | Line 155: | ||
Or, mount the share using a secure port using the terminal: | Or, mount the share using a secure port using the terminal: | ||
− | + | # mount -t nfs -o resvport servername:/srv/nfs4 /Volumes/servername | |
+ | |||
+ | == Tips and tricks == | ||
+ | |||
+ | === Performance tuning === | ||
+ | |||
+ | In order to get the most out of NFS, it is necessary to tune the {{ic|rsize}} and {{ic|wsize}} mount options to meet the requirements of the network configuration. | ||
+ | |||
+ | === Automatic mount handling === | ||
+ | |||
+ | This trick is useful for laptops that require nfs shares from a local wireless network. If the nfs host becomes unreachable, the nfs share will be unmounted to hopefully prevent system hangs when using the hard mount option. See https://bbs.archlinux.org/viewtopic.php?pid=1260240#p1260240 | ||
+ | |||
+ | Make sure that the NFS mount points are correctly indicated in {{ic|/etc/fstab}}: | ||
+ | |||
+ | {{hc|$ cat /etc/fstab|<nowiki> | ||
+ | lithium:/mnt/data /mnt/data nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0 | ||
+ | lithium:/var/cache/pacman /var/cache/pacman nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0</nowiki> | ||
+ | }} | ||
+ | |||
+ | The {{ic|noauto}} mount option tells systemd not to automatically mount the shares at boot. systemd would otherwise attempt to mount the nfs shares that may or may not exist on the network causing the boot process to appear to stall on a blank screen. | ||
+ | |||
+ | In order to mount NFS share by non-root user {{ic|user}} may be required to be added to fstab entry. Also enable rpc-statd.service. | ||
+ | |||
+ | Create the {{ic|auto_share}} script that will be used by ''cron'' to check if the NFS host is reachable, | ||
+ | |||
+ | {{hc|/root/bin/auto_share|<nowiki> | ||
+ | #!/bin/bash | ||
+ | |||
+ | SERVER="YOUR_NFS_HOST" | ||
+ | |||
+ | MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ") | ||
+ | |||
+ | ping -c 1 "${SERVER}" &>/dev/null | ||
+ | |||
+ | if [ $? -ne 0 ]; then | ||
+ | # The server could not be reached, unmount the shares | ||
+ | for umntpnt in ${MOUNT_POINTS}; do | ||
+ | umount -l -f $umntpnt &>/dev/null | ||
+ | done | ||
+ | else | ||
+ | # The server is up, make sure the shares are mounted | ||
+ | for mntpnt in ${MOUNT_POINTS}; do | ||
+ | mountpoint -q $mntpnt || mount $mntpnt | ||
+ | done | ||
+ | fi | ||
+ | </nowiki>}} | ||
+ | |||
+ | # chmod +x /root/bin/auto_share | ||
+ | |||
+ | Create the root cron entry to run {{ic|auto_share}} every minute: | ||
+ | |||
+ | {{hc|# crontab -e|<nowiki> | ||
+ | * * * * * /root/bin/auto_share | ||
+ | </nowiki>}} | ||
+ | |||
+ | A systemd unit file can also be used to mount the NFS shares at startup. The unit file is not necessary if NetworkManager is installed and configured on the client system. See [[#NetworkManger dispatch]]. | ||
+ | |||
+ | {{hc|/etc/systemd/system/auto_share.service|<nowiki> | ||
+ | [Unit] | ||
+ | Description=NFS automount | ||
+ | |||
+ | [Service] | ||
+ | Type=oneshot | ||
+ | RemainAfterExit=yes | ||
+ | ExecStart=/root/bin/auto_share | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=multi-user.target | ||
+ | </nowiki>}} | ||
+ | |||
+ | Now enable {{ic|auto_share}}. | ||
+ | |||
+ | ==== NetworkManger dispatcher ==== | ||
+ | |||
+ | In addition to the method described previously, NetworkManager can also be configured to run a script on network status change. | ||
+ | |||
+ | Enable and start the {{ic|NetworkManager-dispatcher}} service. | ||
+ | |||
+ | The easiest method for mount shares on network status change is to just symlink to the {{ic|auto_share}} script: | ||
+ | |||
+ | # ln -s /root/bin/auto_share /etc/NetworkManager/dispatcher.d/30_nfs.sh | ||
+ | |||
+ | Or use the following mounting script that checks for network availability: | ||
+ | |||
+ | {{hc|/etc/NetworkManager/dispatcher.d/30_nfs.sh|<nowiki> | ||
+ | #!/bin/bash | ||
+ | |||
+ | SSID="CHANGE_ME" | ||
+ | |||
+ | MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ") | ||
+ | |||
+ | ISNETUP=$(nmcli dev wifi | \grep $SSID | tr -s ' ' | cut -f 10 -d ' ') 2>/dev/null | ||
+ | |||
+ | # echo "$ISNETUP" >> /tmp/nm_dispatch_log | ||
+ | |||
+ | if [[ "$ISNETUP" == "yes" ]]; then | ||
+ | for mntpnt in ${MOUNT_POINTS}; do | ||
+ | mountpoint -q $mntpnt || mount $mntpnt | ||
+ | done | ||
+ | else | ||
+ | for srvexp in ${MOUNT_POINTS}; do | ||
+ | umount -l -f $srvexp &>/dev/null | ||
+ | done | ||
+ | fi | ||
+ | </nowiki>}} | ||
+ | |||
+ | Now when the wireless SSID "CHANGE_ME" goes up or down, the {{ic|nfs.sh}} script will be called to mount or unmount the shares as soon as possible. | ||
+ | |||
+ | === Configure NFS fixed ports === | ||
+ | |||
+ | {{Out of date|This section was originally refered to NFS version 3.}} | ||
+ | If you have a port-based [[firewall]], you might want to set up a fixed ports. For rpc.statd and rpc.mountd you should set following settings in {{ic|/etc/conf.d/nfs-common}} and {{ic|/etc/conf.d/nfs-server}} (ports can be different): | ||
+ | |||
+ | {{hc|/etc/conf.d/nfs-common|2=STATD_OPTS="-p 4000 -o 4003"}} | ||
+ | {{hc|/etc/conf.d/nfs-server|2=MOUNTD_OPTS="--no-nfs-version 2 -p 4002"}} | ||
+ | {{hc|/etc/modprobe.d/lockd.conf|2=# Static ports for NFS lockd | ||
+ | options lockd nlm_udpport=4001 nlm_tcpport=4001}} | ||
+ | |||
+ | After restart {{ic|nfs-common}} {{ic|nfs-server}} daemons and reload {{ic|lockd}} modules you can check used ports with following command: | ||
+ | {{hc|$ rpcinfo -p| | ||
+ | program vers proto port service | ||
+ | 100000 4 tcp 111 portmapper | ||
+ | 100000 3 tcp 111 portmapper | ||
+ | 100000 2 tcp 111 portmapper | ||
+ | 100000 4 udp 111 portmapper | ||
+ | 100000 3 udp 111 portmapper | ||
+ | 100000 2 udp 111 portmapper | ||
+ | 100024 1 udp 4000 status | ||
+ | 100024 1 tcp 4000 status | ||
+ | 100021 1 udp 4001 nlockmgr | ||
+ | 100021 3 udp 4001 nlockmgr | ||
+ | 100021 4 udp 4001 nlockmgr | ||
+ | 100021 1 tcp 4001 nlockmgr | ||
+ | 100021 3 tcp 4001 nlockmgr | ||
+ | 100021 4 tcp 4001 nlockmgr | ||
+ | 100003 2 tcp 2049 nfs | ||
+ | 100003 3 tcp 2049 nfs | ||
+ | 100003 4 tcp 2049 nfs | ||
+ | 100003 2 udp 2049 nfs | ||
+ | 100003 3 udp 2049 nfs | ||
+ | 100003 4 udp 2049 nfs | ||
+ | 100005 3 udp 4002 mountd | ||
+ | 100005 3 tcp 4002 mountd | ||
+ | }} | ||
+ | |||
+ | Then, you need to open the ports 111-2049-4000-4001-4002-4003 TCP and UDP. | ||
== Troubleshooting == | == Troubleshooting == | ||
− | + | ||
+ | There is a dedicated article [[NFS Troubleshooting]]. | ||
+ | |||
+ | == See also == | ||
+ | |||
+ | * See also [[Avahi]], a Zeroconf implementation which allows automatic discovery of NFS shares. | ||
+ | * HOWTO: [[Diskless network boot NFS root]] | ||
+ | * [http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/nfs_perf.htm Very helpful] | ||
+ | * If you are setting up the Arch Linux NFS server for use by Windows clients through Microsoft's SFU, you will save a lot of time and hair-scratching by looking at [https://bbs.archlinux.org/viewtopic.php?pid=523934#p523934 this forum post] first ! | ||
+ | * [http://blogs.msdn.com/sfu/archive/2008/04/14/all-well-almost-about-client-for-nfs-configuration-and-performance.aspx Microsoft Services for Unix NFS Client info] | ||
+ | * [http://blogs.msdn.com/sfu/archive/2007/05/01/unix-interoperability-and-windows-vista.aspx Unix interoperability and Windows Vista] Prerequisites to connect to NFS with Vista |
Revision as of 19:13, 28 September 2013
zh-CN:NFS Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki - Dedicated article for common problems and solutions. Template:Article summary end From Wikipedia:
- Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.
Installation
Both client and server only require the installation of the nfs-utils package.
Configuration
Server
ID mapping
Edit /etc/idmapd.conf
and set the Domain
field to your domain name.
/etc/idmapd.conf
[General] Verbosity = 1 Pipefs-Directory = /var/lib/nfs/rpc_pipefs Domain = atomic [Mapping] Nobody-User = nobody Nobody-Group = nobody
File system
Define any NFS shares in /etc/exports
which are relative to the NFS root. In this example, the NFS root will be /srv/nfs4
and we will be sharing /mnt/music
.
# mkdir -p /srv/nfs4/music
Read/Write permissions must be set on the music directory so clients may write to it.
Now mount the actual target share, /mnt/music
to the NFS share via the mount command:
# mount --bind /mnt/music /srv/nfs4/music
To make it stick across server reboots, add the bind mount to fstab
:
/etc/fstab
/mnt/music /srv/nfs4/music none bind 0 0
Exports
Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in exports
:
/etc/exports
/srv/nfs4/ 192.168.0.1/24(rw,fsid=root,no_subtree_check) /srv/nfs4/music 192.168.0.1/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the file system.
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.
For more information about all available options see man 5 exports
.
If you modify /etc/exports
while the server is running, you must re-export them for changes to take effect:
# exportfs -rav
Starting the server
Start rpc-idmapd
and rpc-mountd
services. If you want it running at boot time, enable it. Note that these units require other services, which are launched automatically by systemd.
Firewall configuration
To enable access through a firewall, tcp and udp ports 111, 2049, and 20048 need to be opened. To configure this for iptables, edit /etc/iptables/iptables.rules
to include the following lines:
/etc/iptables/iptables.rules
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT -A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT -A INPUT -p tcp -m tcp --dport 20048 -j ACCEPT -A INPUT -p udp -m udp --dport 111 -j ACCEPT -A INPUT -p udp -m udp --dport 2049 -j ACCEPT -A INPUT -p udp -m udp --dport 20048 -j ACCEPT
To apply changes, restart iptables
service.
Client
Clients need nfs-utils to connect, and to avoid an approx 15 seconds delay with an accompanying error in dmsg that reads, "RPC: AUTH_GSS upcall timed out," users will need to start rpc-gssd
service on any client.
Mounting from Linux
Show the server's exported filesystems:
$ showmount -e servername
Then mount omitting the server's NFS export root:
# mount -t nfs4 servername:/music /mountpoint/on/client
/etc/fstab settings
Using fstab is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit /etc/fstab
file, and add an appropriate line reflecting the setup. Again, the server's NFS export root is omitted.
/etc/fstab
servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
Some additional mount options to consider are include:
- rsize and wsize
- The
rsize
value is the number of bytes used when reading from the server. Thewsize
value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput. This is not universal. It is recommended to test after making this change, see #Performance tuning.
- timeo
- The
timeo
value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value.
- intr
- The
intr
option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.
- _netdev
- The
_netdev
option tells the system to wait until the network is up before trying to mount the share. systemd assumes this for NFS, but anyway it is good practice to use it for all types of networked filesystems
Using autofs
Using autofs is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See autofs#NFS network mounts for details.
Mounting from Windows
NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default). To install the service go to "Programs and features" in the Control Panel and click on "Turn Windows features on or off". Locate "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").
Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right click on client > properties.
To mount a share using Explorer:
Computer
> Map network drive
> servername:/srv/nfs4/music
Mounting from OS X
Either export the share with the insecure
flag, and mount using Finder:
Go
> Connect to Server
> nfs://servername/
Or, mount the share using a secure port using the terminal:
# mount -t nfs -o resvport servername:/srv/nfs4 /Volumes/servername
Tips and tricks
Performance tuning
In order to get the most out of NFS, it is necessary to tune the rsize
and wsize
mount options to meet the requirements of the network configuration.
Automatic mount handling
This trick is useful for laptops that require nfs shares from a local wireless network. If the nfs host becomes unreachable, the nfs share will be unmounted to hopefully prevent system hangs when using the hard mount option. See https://bbs.archlinux.org/viewtopic.php?pid=1260240#p1260240
Make sure that the NFS mount points are correctly indicated in /etc/fstab
:
$ cat /etc/fstab
lithium:/mnt/data /mnt/data nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0 lithium:/var/cache/pacman /var/cache/pacman nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0
The noauto
mount option tells systemd not to automatically mount the shares at boot. systemd would otherwise attempt to mount the nfs shares that may or may not exist on the network causing the boot process to appear to stall on a blank screen.
In order to mount NFS share by non-root user user
may be required to be added to fstab entry. Also enable rpc-statd.service.
Create the auto_share
script that will be used by cron to check if the NFS host is reachable,
/root/bin/auto_share
#!/bin/bash SERVER="YOUR_NFS_HOST" MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ") ping -c 1 "${SERVER}" &>/dev/null if [ $? -ne 0 ]; then # The server could not be reached, unmount the shares for umntpnt in ${MOUNT_POINTS}; do umount -l -f $umntpnt &>/dev/null done else # The server is up, make sure the shares are mounted for mntpnt in ${MOUNT_POINTS}; do mountpoint -q $mntpnt || mount $mntpnt done fi
# chmod +x /root/bin/auto_share
Create the root cron entry to run auto_share
every minute:
# crontab -e
* * * * * /root/bin/auto_share
A systemd unit file can also be used to mount the NFS shares at startup. The unit file is not necessary if NetworkManager is installed and configured on the client system. See #NetworkManger dispatch.
/etc/systemd/system/auto_share.service
[Unit] Description=NFS automount [Service] Type=oneshot RemainAfterExit=yes ExecStart=/root/bin/auto_share [Install] WantedBy=multi-user.target
Now enable auto_share
.
NetworkManger dispatcher
In addition to the method described previously, NetworkManager can also be configured to run a script on network status change.
Enable and start the NetworkManager-dispatcher
service.
The easiest method for mount shares on network status change is to just symlink to the auto_share
script:
# ln -s /root/bin/auto_share /etc/NetworkManager/dispatcher.d/30_nfs.sh
Or use the following mounting script that checks for network availability:
/etc/NetworkManager/dispatcher.d/30_nfs.sh
#!/bin/bash SSID="CHANGE_ME" MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ") ISNETUP=$(nmcli dev wifi | \grep $SSID | tr -s ' ' | cut -f 10 -d ' ') 2>/dev/null # echo "$ISNETUP" >> /tmp/nm_dispatch_log if [[ "$ISNETUP" == "yes" ]]; then for mntpnt in ${MOUNT_POINTS}; do mountpoint -q $mntpnt || mount $mntpnt done else for srvexp in ${MOUNT_POINTS}; do umount -l -f $srvexp &>/dev/null done fi
Now when the wireless SSID "CHANGE_ME" goes up or down, the nfs.sh
script will be called to mount or unmount the shares as soon as possible.
Configure NFS fixed ports
If you have a port-based firewall, you might want to set up a fixed ports. For rpc.statd and rpc.mountd you should set following settings in /etc/conf.d/nfs-common
and /etc/conf.d/nfs-server
(ports can be different):
/etc/conf.d/nfs-common
STATD_OPTS="-p 4000 -o 4003"
/etc/conf.d/nfs-server
MOUNTD_OPTS="--no-nfs-version 2 -p 4002"
/etc/modprobe.d/lockd.conf
# Static ports for NFS lockd options lockd nlm_udpport=4001 nlm_tcpport=4001
After restart nfs-common
nfs-server
daemons and reload lockd
modules you can check used ports with following command:
$ rpcinfo -p
program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 4000 status 100024 1 tcp 4000 status 100021 1 udp 4001 nlockmgr 100021 3 udp 4001 nlockmgr 100021 4 udp 4001 nlockmgr 100021 1 tcp 4001 nlockmgr 100021 3 tcp 4001 nlockmgr 100021 4 tcp 4001 nlockmgr 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100005 3 udp 4002 mountd 100005 3 tcp 4002 mountd
Then, you need to open the ports 111-2049-4000-4001-4002-4003 TCP and UDP.
Troubleshooting
There is a dedicated article NFS Troubleshooting.
See also
- See also Avahi, a Zeroconf implementation which allows automatic discovery of NFS shares.
- HOWTO: Diskless network boot NFS root
- Very helpful
- If you are setting up the Arch Linux NFS server for use by Windows clients through Microsoft's SFU, you will save a lot of time and hair-scratching by looking at this forum post first !
- Microsoft Services for Unix NFS Client info
- Unix interoperability and Windows Vista Prerequisites to connect to NFS with Vista