NFS/Server

From Gentoo Linux Wiki

< NFS
Jump to: navigation, search

Contents

[edit] Kernel Modules

You first need to enable kernel support for NFS. Use make menuconfig to enable the following options:

Linux Kernel Configuration: NFS Server Kernel Modules (2.6.27)
File systems  --->
  [*] Network File Systems  --->    
    <*> NFS server support
    [*]   NFS server support for NFS version 3
    [ ]     NFS server support for the NFSv3 ACL protocol extension
    [ ]   NFS server support for NFS version 4 (EXPERIMENTAL)

The majority of installations are using NFSv3, so NFSv4 support is optional. You should also note that NFSv4 support may not be included on older clients. If you opt to compile NFS server support as a module, it will be called nfsd.

[edit] Userspace Support

You'll need the userspace scripts that control the NFS service, so install them with:
emerge -av nfs-utils

[edit] Creating Shares

The list of directories that clients are allowed to mount is stored in /etc/exports.

File: /etc/exports examples
/home/user/shared 192.168.0.3(async,rw,no_subtree_check)
/home/user/shared2 192.168.0.0/255.255.0.0(async,rw,no_subtree_check)
/mnt/portage 192.168.0.0/16(async,no_subtree_check,rw,no_root_squash)

In the above example, the /home/user/shared directory can be mounted only by 192.168.0.3, while the /home/user/shared2 and /mnt/portage directories can be mounted by any machine on 192.168.*.*

The following are the most frequently used options that can be specified for each share. For a full list see the exports(5) man page.

  • rw - Allow read and write access
  • ro - Allow read only access - no write access
  • async - Reply to requests before data has been committed to the file system. This improves performance, but increases the risk of data loss in the event of a server crash.
  • no_subtree_check - Disable subtree checking. The technical details are in the man page, but essentially it's recommended for read/write filesystems where files change frequently, such as /home. If you disable subtree checking and export something that's not the root of a filesystem, it's possible a client could access a file outside the exported directory, however.
  • root_squash - Prevent the client creating files owned by root - instead they will be owned by the anonymous uid/gid (user id / group id, see man page for details).
  • no_root_squash - Turn off root squashing. Mostly used on diskless clients.
  • all_squash - Map all uids/gids to the anonymous user. This means that all files written to this filesystem will be owned by the same user.

[edit] Starting the Server

To start the nfs server, making the shares accessible to clients, run:
/etc/init.d/nfs start
To have the server start automatically on boot, run:
rc-update add nfs default

[edit] Reloading Exported Shares

If you make changes while the NFS server is running, you'll need to reload the exports before the changes take effect using:
/etc/init.d/nfs reload

[edit] Troubleshooting

If your NFS service doesn't start and you have this error in logs:

Code: Log error
nfssvc: writing fds to kernel failed: errno 93 (Protocol not supported)

take a look to bug 264253.

If you get the error message "mount: RPC: Program not registered": Ensure that the portmapper service is running on both the server and the client machines and that /etc/hosts.allow has been setup to allow remote access. See the manpage for hosts.allow for more information.

Personal tools
In other languages