Building NFS under Ubuntu

Introduction to NFS

NFS (Network File System) is a network file system, which is one of the file systems supported by FreeBSD. It allows computers in the network to share resources through the TCP/IP network. In NFS applications, local NFS client applications can transparently read and write files located on remote NFS servers, just like accessing local files. Details on Linux NFS Overview, FAQ and HOWTO Documents .
NFS is divided into server and client. When using remote files, just use the mount command to mount the file system on the remote NFS server under the local file system. Operating remote files is no different from operating local files. The files or directories shared by the NFS server are recorded in the /etc/exports file.
In embedded Linux development, NFS is often used, the target system is usually used as an NFS client, and the Linux host is used as an NFS server. On the target system, mount the NFS shared directory of the server to the local through NFS, and you can directly run the files on the server. When debugging system driver modules and applications, NFS is very necessary, and Linux also supports the NFS root file system, which can directly start the system from the remote NFS root, which is also very necessary for the cutting and integration of embedded Linux root file systems. .

Install nfs server and client

Server side: sudo apt-get install portmap nfs-kernel-server
Client side: sudo apt-get install portmap nfs-common

Configure shared files

Edit /etc/exports and add the directory to be shared
sudo gedit /etc/exports
configuration
/ubuntu *(rw,sync,no_root_squash,no_subtree_check)
or /ubuntu 192.168.0.64/24(rw,sync,no_root_squash,no_subtree_check)
/ ubuntu is the directory to be shared, * means to allow access to all network segments, rw is read and write permission, sync is the synchronous writing of data to memory and hard disk, no_root_squash is the permission of the NFS client to share the directory user, if the client uses is the root user, then the client has root permission to
save .
sudo exportfs -ra (it can rescan /etc/exports, so that users do not have to restart the NFS service to modify the /etc/exports configuration file)
The following is a detailed description of the parameters: refer to http://www.cnblogs.com/Charles-Zhang- Blog/archive/2013/02/05/2892879.html

parameter illustrate
ro read only access
rw read and write access
sync All data is written to the share when requested
async nfs can respond to requests before writing data
secure nfs send over secure TCP/IP ports below 1024
insecure nfs send over ports above 1024
wdelay If multiple users want to write to the nfs directory, group writes (default)
no_wdelay If multiple users want to write to the nfs directory, write immediately, when using async, this setting is not required
hide Do not share its subdirectories in an nfs shared directory
no_hide Subdirectories of shared nfs directory
subtree_check Force nfs to check the permissions of the parent directory if sharing a subdirectory like /usr/bin (default)
no_subtree_check Do not check parent directory permissions
all_squash UID and GID mapping of shared files Anonymous user anonymous, suitable for public directories
no_all_squash Preserve UID and GID of shared files (default)
root_squash All requests of the root user are mapped to the same permissions as the anonymous user (default)
no_root_squash The root user has full administrative access to the root directory
anonuid=xxx Specify the UID of the anonymous user in the /etc/passwd file of the nfs server
anongid=xxx Specify the GID of the anonymous user in the /etc/passwd file of the nfs server

restart the service

sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-kernel-server restart

Test after the server is installed.

s h o w m o u n t e h o s t n a m e ( display the shared directory set in h o s t n a m e / e t c / e x p o r t s _ record ) If you see such a messagejust explainIt worked . abc @ abcde s k t o p : / showmount -e
Export list for abc-desktop:
/ubuntu *

Client mounts.

  • Create the directory that the client needs to mount (the mount directory set by the client must already exist)
    sudo mkdir /mnt/share
    sudo chmod 777 /mnt/share/
  • Mount the client directory
    sudo mount 192.168.0.58:/ubuntu /mnt/share

problem appear

  • Server permission error
    reason given by server: Permission denied
    Solution: The
    server must be started with sudo, otherwise the startup will fail and the service will be rejected

  • 连接拒绝
    svc: failed to register lockdv1 RPC service (errno 111).
    lockd_up: makesock failed, error=-111
    mount: mounting 192.168.1.101:/home/share on /mnt/hosts failed: Connection refused
    解决:
    加上参数-t nfs -o nolock
    mount -t nfs -o nolock 192.168.1.101:/home/share /mnt/hosts

  • The device or resource is busy
    mount: mounting 192.168.1.101: /home/share on /mnt/hosts failed: Device or resource busy
    Solution:
    This prompt will appear when the mount command is executed after the mount is on. The device is running, and there is no need to mount it again. If you want to To mount again, you can first umount /mnt/hosts

  • MAC system mount
    mount_nfs -P 192.168.2.104:/home/sun/rootnfs /Users/sunchunlei/nfsroot

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325476994&siteId=291194637