Difference between revisions of "NFS"

From ArchWiki
Jump to: navigation, search
(merged Sharing data with NFS, cleaned up)
(removed Mounting from Windows from Troubleshooting; minor spelling)
Line 122: Line 122:
 
Using [[autofs]] is useful when you have multiple machines that you want to connect via NFS and they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if one of the machine(server) is switched off, the client will not throw errors about being unable to find NFS shares. Please see the relevant section on the [[autofs#NFS_Network_mounts]] page for setting up NFS shares.
 
Using [[autofs]] is useful when you have multiple machines that you want to connect via NFS and they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if one of the machine(server) is switched off, the client will not throw errors about being unable to find NFS shares. Please see the relevant section on the [[autofs#NFS_Network_mounts]] page for setting up NFS shares.
  
==Troubleshooting==
+
== Mounting from Windows ==
 +
{{note|only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"}}
 +
NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default).
 +
To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "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 clicking on the client->properties.
 +
 
 +
{{Warning|under Windows the share is addressed by it's full path on the server, not just the path relative to the nfsroot!! If in doubt run {{ic|showmount -e servername}} from cmd.exe}}
  
 +
==Troubleshooting==
 
===exportfs: /etc/exports:2: syntax error: bad option list===
 
===exportfs: /etc/exports:2: syntax error: bad option list===
 
Delete all space from the option list in {{ic|/etc/exports}}
 
Delete all space from the option list in {{ic|/etc/exports}}
Line 136: Line 144:
 
Check that the permissions on your client's folder are correct. Try using 755.
 
Check that the permissions on your client's folder are correct. Try using 755.
  
=== Permissions issues ===
+
=== permissions issues ===
 
If you find that you cannot set the permissions on files properly, make sure the user/group you are chowning are on both the client and server.
 
If you find that you cannot set the permissions on files properly, make sure the user/group you are chowning are on both the client and server.
 
If that does not help, try modifying these lines in {{ic|/etc/conf.d/nfs-common.conf}}
 
If that does not help, try modifying these lines in {{ic|/etc/conf.d/nfs-common.conf}}
Line 151: Line 159:
 
I restarted all the other daemons as well, just to be sure.
 
I restarted all the other daemons as well, just to be sure.
  
=== Group/gid Permissions issues ===
+
=== group/gid permissions issues ===
 
If NFS shares mount fine, and are fully accessible to the owner, but not to group members; check the number of groups that user belongs to. NFS has a limit of 16 on the number of groups a user can belong to. If you have users with more then this, you need to enable the {{ic|--manage-gids}} start-up flag for {{ic|rpc.mountd}} on the NFS server.
 
If NFS shares mount fine, and are fully accessible to the owner, but not to group members; check the number of groups that user belongs to. NFS has a limit of 16 on the number of groups a user can belong to. If you have users with more then this, you need to enable the {{ic|--manage-gids}} start-up flag for {{ic|rpc.mountd}} on the NFS server.
  
Line 162: Line 170:
 
   
 
   
 
  MOUNTD_OPTS="--manage-gids"
 
  MOUNTD_OPTS="--manage-gids"
 
=== Mounting from Windows ===
 
{{note|only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"}}
 
NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default).
 
To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "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 clicking on the client->properties.
 
 
{{Warning|under Windows the share is addressed by it's full path on the server, not just the path relative to the nfsroot!! If in doubt run {{ic|showmount -e servername}} from cmd.exe}}
 

Revision as of 17:08, 30 August 2012

Note: this article covers NFSv4, for the older version 3 see NFSv3

Network File System (NFS), is an open standard network file sharing protocol.

Installing

Both client and server only require nfs-utils from the official repositories.

Configuring

Time synchronization

In order for NFS to function properly, both server and client must have closely matching time values. If the clocks on the clients differ from the server too much, then basic functions like file copy operations may hang for a very long time leaving the system unusable until they resume. The clocks do not have to match to micro/nano second accuracies, but ideally they should be within 1 second of each other.

The NTP system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet. For a small system like a home network, the ntpdate utility may be used to sync both servers and clients to the same time. For a larger installation, it may be desirable to install an OpenNTP server (see NTP) onto the same machine acting as the NFS server, and then all clients on the network would sync time values from the server. This has the advantage of lowering the stress on the external NTP servers, and in assuring that the NFS clients will use the exact time that the NFS server has, even if the NFS server experiences some drift.

Server

The server configuration involves the /etc/idmapd.conf file and the /etc/exports file to export shares shares. Further tweaking can be done by editing /etc/conf.d/nfs-server.conf.

Server ID mapping

/etc/idmapd.conf needs to be edited. You'll need to at the very least specify your Domain there. Example:

[General]

Verbosity = 1
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = archlinux.org

[Mapping]

Nobody-User = nobody
Nobody-Group = nobody

Exports

All the NFS shares are defined in /etc/exports. Add directories which you want to share and ip addresses or hostnames of client machines that will be allowed to mount them:

/mnt/data  192.168.0.3(rw,sync)

You can also share it to a whole subnet:

/mnt/data  192.168.0.0/24(rw,sync)
Note: The old NFSv3-style 192.168.0.*-scheme is no longer supported.

See man 5 exports for more information.

A typical NFSv4 export would look like this:

/mnt       192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
/mnt/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
Note: The fsid=0 is required for the root filesystem being exported. /mnt is the NFS root here (due to the fsid=0 entry). Everything else that you want to be shared over NFS must be accessible under /mnt. Setting an NFS root is required. For exporting directories outside the NFS root, see below.
Note: The no_root_squash option means that root on the client is also considered root on the server. This is of course a security risk. Remove it if you do not need it.
Exporting directories outside your NFS root

To do this, you will need to use bind mounts. For example, to bind /home/john to /mnt/john:

# mount --bind /home/john /mnt/john

Then, /mnt/john needs to be added to /etc/exports:

/mnt       192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
/mnt/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
/mnt/john  192.168.0.12(rw,no_subtree_check,async,no_root_squash,nohide)

The nohide option is required, because the kernel NFS server automatically hides mounted directories. Add the bind mount to /etc/fstab so that it sticks across boots of the server machine:

/home/john    /mnt/john    none    bind  0 0

Starting the server

To start the NFS server:

# rc.d start rpcbind nfs-common nfs-server

Or add them to your /etc/rc.conf.

DAEMONS=(... rpcbind nfs-common nfs-server ...)

To start the NFS server when you are using systemd, use:

# systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service

Client

The client configuration only involves the /etc/idmapd.conf file. If your client also acts as a server for other machines on the network, then you will still have to configure the files covered in the server section.

Client ID mapping

/etc/idmapd.conf needs to be edited on all clients. The Domain entry should be identical to the one on the server (see the Server ID mapping section). Example:

[General]

Verbosity = 1
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = archlinux.org

[Mapping]

Nobody-User = nobody
Nobody-Group = nobody

[Translation]
Method = nsswitch

Starting the client

To start the NFS client:

# rc.d start rpcbind nfs-common

Or add them to your /etc/rc.conf.

DAEMONS=(... rpcbind nfs-common ...)
Note: On a client only setup make sure rpc.idmapd is running. The nfs-common daemon usually auto-detects whether rpc.idmapd has to be started, but it might fail if there aren't any nfs4 mount entries in /etc/fstab or if /etc/exports is empty (which both might be the case if you are using autofs to mount the nfs4 shares). In this case set NEED_IDMAPD="yes" in /etc/conf.d/nfs-common.conf.

Mounting NFS shares on the client

Show the server's exported filesystems:

showmount -e server

Then just mount as normal:

# rc.d start rpcbind nfs-common
# mount -t nfs4 server:/ /mnt/server/
# mount -t nfs4 server:/music /mnt/music/
# mount -t nfs4 server:/john /mnt/john

Replacing 'server' with the hostname or IP address of your NFS server and of course 'server', 'music' and 'john' with the names of whatever directories you exported on the server.

Note: The root of the path on the server is the NFS root specified; all paths must be specified relative to it.

Auto mounting

  • With Initscripts: If you want to auto mount the NFS shares on boot, you will have to make sure that the network(or any other networking daemon that you use), rpcbind, nfs-common daemons are started up and also in that order. Do NOT background the daemons since the order in which they start up is important. Additionally you will also want to start netfs daemon which handles the clean unmount of NFS shares while shutting down the client machine. The netfs daemon can be backgrounded without any issues.
DAEMONS=(... network rpcbind nfs-common @netfs ...)

After you have added the daemons, auto mounting of NFS shares can be handled in one of two ways:

Using fstab

Using fstab is useful when you have a server which is always on, and the NFS shares are available whenever your client boots up. Edit your /etc/fstab file, and add an appropriate line in there reflecting your setup.

server:/ /mnt/nfsshare nfs4 defaults 0 0
Note: where server is the server hostname or IP address

If you wish to specify a packet size for read and write packets, specify them in your /etc/fstab entry. Read the NFS man page for further information, including all available mount options.

Using autofs

Using autofs is useful when you have multiple machines that you want to connect via NFS and they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if one of the machine(server) is switched off, the client will not throw errors about being unable to find NFS shares. Please see the relevant section on the autofs#NFS_Network_mounts page for setting up NFS shares.

Mounting from Windows

Note: only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"

NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default). To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "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 clicking on the client->properties.

Warning: under Windows the share is addressed by it's full path on the server, not just the path relative to the nfsroot!! If in doubt run showmount -e servername from cmd.exe

Troubleshooting

exportfs: /etc/exports:2: syntax error: bad option list

Delete all space from the option list in /etc/exports

mount.nfs4: No such device

Check that you have loaded the nfs module

lsmod | grep nfs

and if previous returns empty or only nfsd-stuff, do

modprobe nfs

mount.nfs4: access denied by server while mounting

Check that the permissions on your client's folder are correct. Try using 755.

permissions issues

If you find that you cannot set the permissions on files properly, make sure the user/group you are chowning are on both the client and server. If that does not help, try modifying these lines in /etc/conf.d/nfs-common.conf

# /etc/conf.d/nfs-common.conf

# Do you want to start the statd daemon? It is not needed for NFSv4.
NEED_STATD="no"

# Do you want to start the idmapd daemon? It is only needed for NFSv4.
NEED_IDMAPD="yes"

Restart the nfs-common daemon for the changes to take effect. I restarted all the other daemons as well, just to be sure.

group/gid permissions issues

If NFS shares mount fine, and are fully accessible to the owner, but not to group members; check the number of groups that user belongs to. NFS has a limit of 16 on the number of groups a user can belong to. If you have users with more then this, you need to enable the --manage-gids start-up flag for rpc.mountd on the NFS server.

/etc/conf.d/nfs-server.conf

# Options for rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option.
# See rpc.mountd(8) for more details.

MOUNTD_OPTS="--manage-gids"