https://wiki.archlinux.org/api.php?action=feedcontributions&user=Tiziano88&feedformat=atomArchWiki - User contributions [en]2024-03-29T10:52:45ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=NFS&diff=307662NFS2014-03-30T10:22:42Z<p>Tiziano88: Adding mounting options for OS X, otherwise browsing in Finder is almost completely unusable.</p>
<hr />
<div>[[Category:File systems]]<br />
[[Category:Networking]]<br />
[[ar:NFS]]<br />
[[de:Network File System]]<br />
[[es:NFS]]<br />
[[fr:NFS]]<br />
[[it:NFSv4]]<br />
[[zh-CN:NFS]]<br />
{{Related articles start}}<br />
{{Related|NFS Troubleshooting}}<br />
{{Related articles end}}<br />
From [[Wikipedia: Network File System|Wikipedia]]: <br />
: ''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.''<br />
<br />
== Installation ==<br />
<br />
Both client and server only require the [[pacman|installation]] of the {{Pkg|nfs-utils}} package.<br />
<br />
{{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.}}<br />
<br />
==Configuration==<br />
<br />
===Server===<br />
<br />
==== ID mapping ====<br />
<br />
Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name.<br />
<br />
{{hc|/etc/idmapd.conf|<nowiki><br />
[General]<br />
<br />
Verbosity = 1<br />
Pipefs-Directory = /var/lib/nfs/rpc_pipefs<br />
Domain = atomic<br />
<br />
[Mapping]<br />
<br />
Nobody-User = nobody<br />
Nobody-Group = nobody<br />
</nowiki>}}<br />
<br />
==== File system ====<br />
<br />
{{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.}}<br />
<br />
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}}.<br />
<br />
# mkdir -p /srv/nfs4/music<br />
<br />
Read/Write permissions must be set on the music directory so clients may write to it. <br />
<br />
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command:<br />
<br />
# mount --bind /mnt/music /srv/nfs4/music<br />
<br />
To make it stick across server reboots, add the bind mount to {{ic|fstab}}:<br />
{{hc|/etc/fstab|<br />
/mnt/music /srv/nfs4/music none bind 0 0<br />
}}<br />
<br />
==== Exports ====<br />
<br />
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}}:<br />
{{hc|/etc/exports|<nowiki><br />
/srv/nfs4/ 192.168.0.1/24(rw,fsid=root,no_subtree_check)<br />
/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.<br />
</nowiki>}}<br />
<br />
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.<br />
<br />
For more information about all available options see {{ic|man 5 exports}}.<br />
<br />
If you modify {{ic|/etc/exports}} while the server is running, you must re-export them for changes to take effect:<br />
# exportfs -rav<br />
<br />
==== Starting the server ====<br />
<br />
Start {{ic|rpc-idmapd.service}} and {{ic|rpc-mountd.service}} [[systemd#Using units|using systemd]]. If you want them running at boot time, enable them. Note that these units require other services, which are launched automatically by [[systemd]].<br />
<br />
==== Firewall configuration ====<br />
<br />
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:<br />
<br />
{{hc|/etc/iptables/iptables.rules|<nowiki><br />
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 20048 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 111 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 2049 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 20048 -j ACCEPT<br />
</nowiki>}}<br />
<br />
To apply changes, restart {{ic|iptables}} service.<br />
<br />
=== Client ===<br />
<br />
Clients with a kernel version prior to 3.12.7-2 need to start {{ic|rpc-gssd.service}} to avoid an approx 15 seconds delay with an accompanying error in dmesg that reads, "RPC: AUTH_GSS upcall timed out" due to a kernel bug.<br />
<br />
{{Note|The server does not need to run this service.}}<br />
{{Warning|Starting this service without having it configured properly will result in error messages like:<br />
rpc.gssd[30473]: ERROR: Key table file '/etc/krb5.keytab' not found while beginning keytab scan for keytab 'FILE:/etc/krb5.keytab'<br />
rpc.gssd[30473]: ERROR: gssd_refresh_krb5_machine_credential: no usable keytab entry found in keytab /etc/krb5.keytab for connection with host server.domain<br />
rpc.gssd[30473]: ERROR: No credentials found for connection to server server.domain<br />
and might lock up any NFS mount on the system when mounting and unmounting some mounts very often.<br />
}}<br />
An alternative is to blacklist the module {{ic|rpcsec_gss_krb5}} and rebooting afterwards:<br />
# echo "blacklist rpcsec_gss_krb5" > /etc/modprobe.d/rpcsec_gss_krb5-blacklist.conf<br />
# reboot<br />
as described [https://bugzilla.redhat.com/show_bug.cgi?id=1001934 on Red Hat's Bugzilla].<br />
<br />
==== Mounting from Linux ====<br />
<br />
Show the server's exported file systems:<br />
$ showmount -e servername<br />
<br />
Then mount omitting the server's NFS export root: <br />
# mount -t nfs4 servername:/music /mountpoint/on/client<br />
<br />
{{Note|Server name needs to be a valid hostname (not just IP address). Otherwise mounting of remote share will hang.}}<br />
<br />
===== using /etc/fstab =====<br />
<br />
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.<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0<br />
</nowiki>}}<br />
<br />
{{Note|Consult the ''NFS'' and ''mount'' man pages for more mount options.}}<br />
<br />
Some additional mount options to consider are include:<br />
<br />
; 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]].<br />
<br />
; 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. <br />
<br />
; intr: The {{ic|intr}} option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.<br />
<br />
; _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 file systems<br />
<br />
{{Note|Setting the sixth field (fs_passno) to a nonzero value may lead to unexpected behaviour, e.g. hangs when the systemd automount waits for a check which will never happen.}}<br />
<br />
===== Using autofs =====<br />
<br />
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.<br />
<br />
==== Mounting from Windows ====<br />
<br />
{{Note|Only the Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 include "Client for NFS".}}<br />
NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default).<br />
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").<br />
<br />
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''.<br />
<br />
{{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]}}<br />
<br />
To mount a share using Explorer:<br />
<br />
{{ic|Computer}} > {{ic|Map network drive}} > {{ic|servername:/srv/nfs4/music}}<br />
<br />
==== Mounting from OS X ====<br />
<br />
{{Note|OS X by default uses an insecure (>1024) port to mount a share.}}<br />
Either export the share with the {{ic|insecure}} flag, and mount using Finder:<br />
<br />
{{ic|Go}} > {{ic|Connect to Server}} > {{ic|nfs://servername/}}<br />
<br />
Or, mount the share using a secure port using the terminal:<br />
# mount -t nfs -o resvport,nolocks,locallocks servername:/srv/nfs4 /Volumes/servername<br />
<br />
See https://blogs.oracle.com/jag/entry/nfs_on_snow_leopard for an explanation on why to use the {{ic|nolocks}} and {{ic|locallocks}} options.<br />
<br />
== Tips and tricks ==<br />
<br />
=== Performance tuning ===<br />
<br />
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.<br />
<br />
=== Automatic mount handling ===<br />
<br />
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<br />
<br />
Make sure that the NFS mount points are correctly indicated in {{ic|/etc/fstab}}:<br />
<br />
{{hc|$ cat /etc/fstab|<nowiki><br />
lithium:/mnt/data /mnt/data nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0<br />
lithium:/var/cache/pacman /var/cache/pacman nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0</nowiki><br />
}}<br />
<br />
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.<br />
<br />
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.<br />
<br />
Create the {{ic|auto_share}} script that will be used by ''cron'' to check if the NFS host is reachable,<br />
<br />
{{hc|/root/bin/auto_share|<nowiki><br />
#!/bin/bash<br />
<br />
SERVER="YOUR_NFS_HOST"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ping -c 1 "${SERVER}" &>/dev/null<br />
<br />
if [ $? -ne 0 ]; then<br />
# The server could not be reached, unmount the shares<br />
for umntpnt in ${MOUNT_POINTS}; do<br />
umount -l -f $umntpnt &>/dev/null<br />
done<br />
else<br />
# The server is up, make sure the shares are mounted<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
# chmod +x /root/bin/auto_share<br />
<br />
Create the root cron entry to run {{ic|auto_share}} every minute:<br />
<br />
{{hc|# crontab -e|<nowiki><br />
* * * * * /root/bin/auto_share<br />
</nowiki>}}<br />
<br />
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 [[#NetworkManager dispatcher]].<br />
<br />
{{hc|/etc/systemd/system/auto_share.service|<nowiki><br />
[Unit]<br />
Description=NFS automount<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=/root/bin/auto_share<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
Now enable {{ic|auto_share}}.<br />
<br />
==== NetworkManager dispatcher ====<br />
<br />
In addition to the method described previously, NetworkManager can also be configured to run a script on network status change.<br />
<br />
Enable and start the {{ic|NetworkManager-dispatcher}} service.<br />
<br />
The easiest method for mount shares on network status change is to just symlink to the {{ic|auto_share}} script:<br />
<br />
# ln -s /root/bin/auto_share /etc/NetworkManager/dispatcher.d/30_nfs.sh<br />
<br />
Or use the following mounting script that checks for network availability:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/30_nfs.sh|<nowiki><br />
#!/bin/bash<br />
<br />
SSID="CHANGE_ME"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ISNETUP=$(nmcli dev wifi | \grep $SSID | tr -s ' ' | cut -f 10 -d ' ') 2>/dev/null<br />
<br />
# echo "$ISNETUP" >> /tmp/nm_dispatch_log<br />
<br />
if [[ "$ISNETUP" == "yes" ]]; then<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
else<br />
for srvexp in ${MOUNT_POINTS}; do<br />
umount -l -f $srvexp &>/dev/null<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
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.<br />
<br />
=== Configure NFS fixed ports ===<br />
<br />
{{Out of date|This section was originally refered to NFS version 3.}}<br />
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):<br />
<br />
{{hc|/etc/conf.d/nfs-common|2=STATD_OPTS="-p 4000 -o 4003"}}<br />
{{hc|/etc/conf.d/nfs-server|2=MOUNTD_OPTS="--no-nfs-version 2 -p 4002"}}<br />
{{hc|/etc/modprobe.d/lockd.conf|2=# Static ports for NFS lockd<br />
options lockd nlm_udpport=4001 nlm_tcpport=4001}}<br />
<br />
After restart {{ic|nfs-common}} {{ic|nfs-server}} daemons and reload {{ic|lockd}} modules you can check used ports with following command:<br />
{{hc|$ rpcinfo -p|<br />
program vers proto port service<br />
100000 4 tcp 111 portmapper<br />
100000 3 tcp 111 portmapper<br />
100000 2 tcp 111 portmapper<br />
100000 4 udp 111 portmapper<br />
100000 3 udp 111 portmapper<br />
100000 2 udp 111 portmapper<br />
100024 1 udp 4000 status<br />
100024 1 tcp 4000 status<br />
100021 1 udp 4001 nlockmgr<br />
100021 3 udp 4001 nlockmgr<br />
100021 4 udp 4001 nlockmgr<br />
100021 1 tcp 4001 nlockmgr<br />
100021 3 tcp 4001 nlockmgr<br />
100021 4 tcp 4001 nlockmgr<br />
100003 2 tcp 2049 nfs<br />
100003 3 tcp 2049 nfs<br />
100003 4 tcp 2049 nfs<br />
100003 2 udp 2049 nfs<br />
100003 3 udp 2049 nfs<br />
100003 4 udp 2049 nfs<br />
100005 3 udp 4002 mountd<br />
100005 3 tcp 4002 mountd<br />
}}<br />
<br />
Then, you need to open the ports 111-2049-4000-4001-4002-4003 TCP and UDP.<br />
<br />
== Troubleshooting ==<br />
<br />
There is a dedicated article [[NFS Troubleshooting]].<br />
<br />
== See also ==<br />
<br />
* See also [[Avahi]], a Zeroconf implementation which allows automatic discovery of NFS shares.<br />
* HOWTO: [[Diskless network boot NFS root]]<br />
* [http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/nfs_perf.htm NFS Performance Management]<br />
* 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 !<br />
* [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]<br />
* [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</div>Tiziano88