NFS built in an embedded environment

Source: Internet
Author: User
NFS in an embedded environment [abstract]: This article introduces NFS-related concepts, NFS configuration files, how to set up NFS servers and clients, and check whether the settings are successful; analyze the exceptions and provide an embedded configuration instance. I. network File System Overview 1.1.what..nfs built in the embedded environment [abstract]: This article introduces NFS-related concepts, NFS configuration files, how to set up NFS servers and clients, and check whether the settings are successful; analyze the exceptions and provide an embedded configuration instance. 1. Network File System Overview 1.1.What is NFS? NFS is short for Network FileSystem and developed by Sun. The objective is to allow linux machines to share documents with each other. NFS allows the shared directory on the server to be mounted to the local client. for the local client machine, the directory on the remote server is like a part of its own. 1.2 whatis NFS, In embedded development engineer's eyes? Its function is to mount a directory of the NFS server (that is, a Linux host) to the file system of the Development Board. In this way, the development board can execute executable programs in this directory. The advantage of this is that you do not need to write the program into the Flash of the Development Board, which reduces the damage to Flash and facilitates debugging. In embedded system development, it is mainly used to start the NFS network root file system or load and debug applications on the network. 1.3 How NFS works: NFS is based on the customer/server mode. An NFS server is a computer that outputs a group of files, while an NFS Client is a computer that accesses files. The client and the server call communication through a remote process. when applications on the client host access remote files, the client host kernel sends a request to the remote NFS server, waiting for the server to respond, the NFS server remains in the waiting state. if a customer request is received, the server processes the request and returns the result to the client. If the directory on the NFS server can be accessed by remote users, it is called "export". The process of accessing the exported directory on the client host is called "mount )", or "mount" or "import. Features: (1) sharing between Linux hosts (2) sharing between development boards and development hosts (3) sharing between servers can be virtual machines or independent Linux servers (4) create multiple accounts on the server and share them with others to save resources (5) you can have an independent personal directory, which is secure and reliable. II. the NFS server configuration includes four main steps: (1) installing the NFS software package (2) configure the file system or directory to be exported on the NFS server in the/etc/exprots file. (3) start the NFS service. (4) export the file system or directory configured in/etc/exports. 2.1 install NFS (1) run the following command to install NFS in ubuntu: # sudo apt-get install nfs-kernel-server (2) NFS is started and stopped through/etc/init. d directory. (3) the command for restarting NFS on the command line is/etc/init. d/nfs restartnote: Before starting the NFS server, start rpcbind #/etc/init. d/rpcbind restart2.2 configure the NFS server (1) configure NFS mainly involves the configuration file/etc/exports, which is used on the NFS server, lists the directories to be exported from the NFS server, NFS clients that can access these directories, and their access permissions. (2) the format of the/etc/exports file is as follows: [cpp] dir_to_export NFS_client (permissions) [NFS_client (permissions)…] Instance: # vim/etc/exports [cpp]/tmp 192.168.100.0/24 (ro) localhost (rw) * (ro, sync) [share Directory] [first client (permission)] [available host name] [available wildcard] this instance means to share/tmp to three different hosts or domains respectively. Between the output directory and the client in the format, the client and the client are separated by spaces, but there cannot be spaces between the client and the permission parameter. If there are more than one permission parameter, separate them with commas. Output Directory: dir_to_export is the name of the file system or directory to be exported, that is, the directory to be shared to the client. The directory must be an absolute path. Client: NFS_client is the name of the client that can access the NFS server. The specified client is flexible. it can be the IP address or domain name of a single host, or a host in a subnet or domain. Option: permissions is the access permission for the NFS client to access the export directory. the optional value is ro (read-only) or rw (read/write ). Note: For a detailed explanation of the preceding parameters, see Appendix 1: detailed description of each element in exportfs. 2.3exportfs maintains the output directory list of the NFS service (1) when the content of the/etc/exprots file is modified, you do not need to restart the NFS service, you can directly use the command exportfs to make the settings take effect immediately. (2) the exportfs command is used to maintain the output directory list of the NFS service. The Command format is as follows: exportfs [options]-a: Mount (or detach) all directories in the/etc/exports file-r: remount the settings in the/etc/exports file and make the settings take effect immediately without restarting the NFS service. -U: unmount a directory-v: displays the shared directory on the screen during the export operation. (3) after the content in the/etc/exports file is modified, run the following command to make the configuration take effect immediately: # exportfs-rv. (4) when uninstalling all the shared directories, run the following command: # exportfs-au 3. set NFS server to share with/etc/expors and publish with exportfs. After the directory is shared, run the shownmount command to display the shared directory. The NFS client configuration requires the following steps: (1) select the NFS option when compiling the kernel. (2) use showmount to scan the directories shared by the NFS server and check whether they can be used. (3) Create a mount point directory on the client. (4) mount the remote host directly to the relevant Directory using mount. (5) Check the mounting status. 3.1 when installing the NFS client (supporting NFS configuration in the kernel) to run nfs on the target board, you must compile the kernel, make it support NFS [cpp] File systems netwok file systems <*> nfs file system support <*> provide nfsv3 client support <*> nfs server support 3.2 showmount view NFS server information on the client, to view the shared directories on the NFS server, run the showmount command. (1) the command format of showmount is as follows: showmount [-ade] [hostname]-a: list all remote loads-d: list directories that are remotely loaded-e: list all shared file systems (2). For example, if the IP address of the NFS server is 192.168.1.101, run the following command: # showmount-e192.168.1.1013.3 connect to the NFS server (mount) after using the showmount command to learn about the shared resources on the remote NFS server, the next step is to perform the actual mounting operation. (1) the command format for mounting the output directory on the NFS server is as follows: [cpp] mount-t nfs NFS_server_name: exported-directory mount_point-t nfs: specifies the file system type. NFS_server_name: the NFS server name; exported_directory: the directory to be shared; mount_point: The installation location on the local machine. (2) instance: for example, the NFS client installs the/share1 directory exported from the remote file system tiger under its own file system/mnt/nfs directory for sharing. # Mount tiger:/share1/mnt/nfs (3) after the shared directory is mounted, as long as you type/mnt/nfs, it is equal to entering the/share1 directory on the remote host tiger. 3.4 check whether the disk is successfully loaded (1) df displays the drive letter of the current system, including the mounted NFS directory. (2) you can also directly view the mounted directory to check whether the mount is successful. 3.5 run the umount command umount/home/think/test to unmount the NFS file system and exit the mounted directory before uninstalling it. Otherwise, the system prompts: the device is busy! 3.6 when NFS is started, it is automatically mounted. The Mount point and related parameters are written to/etc/fstab. can NFS be written to/etc/fstab? No !!! After analyzing the boot process, we can find that the network is mounted on the local machine. Therefore, when you try to Mount NFS using/etc/fstab, the system has not started the network, so it is definitely not possible to mount it! However, we can write it to/etc/rc. d/rc. local! # Vim/etc/rc. d/rc. local the mount point mounted upon startup and the related parameters are written to/etc/fstab. can NFS be written to/etc/fstab? No !!! After analyzing the boot process, we can find that the network is mounted on the local machine. Therefore, when you try to Mount NFS using/etc/fstab, the system has not started the network, so it is definitely not possible to mount it! However, we can write it to/etc/rc. d/rc. local! # Vim/etc/rc. d/rc. local [cpp] mout-t nfs 192.168.1.100:/home/think // EmbeddedWork/mnt-o nolock 4. execption4.1 if the network end of the Development Board is disconnected from the host, nfs: server 192.168.0.12 not responding, still trying4.2 connection timeout portmap: server localhost not responding, timed out solution: # mount-t nfs-o nolock node1:/public: the-o nolock parameter is added. reason: Unfsd doesn' t support NLMlocking, and it's causing the lockd daemon to be started (whic H again requiresthe portmapper to be installed. 4.3 Restricted access denied by server while mounting may be caused by firewall problems or the IP segment range set in the configuration file is incorrect or the setting is small, if the modification is not complete, use "*" to replace the previous IP address. although it is not safe, it can be solved. 4.5 some services on the server or client are not started (1) mount: xxxxx failed: System Error: Connection refused solution: If ping is used, the network and server are both good, the rpcbind is not enabled. Start method: #/etc/init. d/rpcbind restart. (2) mout: xxxxx failed: RPCError: Program not registered. after the rpcbind service is restarted, the NFS service is not restarted. Solution: #/etc/init. d/rpcbind restart. #/etc/init. d/nfs restart. 5. instance 5. 1. typical settings of embedded systems (1) server-side settings of embedded systems because the embedded systems are developed by connecting their own computers to the development board, there is not much security considerations for access to IP addresses and permissions, etc, therefore, the setting is relatively simple. Generally, the following configuration is used: [cpp]/home/think/EmbeddedWork * (rw, sync, no_root_squash) indicates that any client can mount the/home/think/EmbeddedWork Directory of the server. In this way, the development board will not be unable to access the host because of IP settings, and have the read and write permissions. the root user logged on to the development board will have the same permissions as the root user of the host. (2) the client (Development Board) uses the following mount command to mount # mount-t nfs 192.168.1.100:/home/think // EmbeddedWork/mnt-o nolock Attachment 1: description of each element in exportfs 1. common methods for specifying a client: [cpp] The client describes the host 192.168.16.0/24 (or 192.168.16) with the specified IP address 192.168.16.20. *) All hosts in the specified subnet * .gdvcp.net all hosts in the specified domain * (or by default) all hosts 2. the options are used to set the access permission and user ING of the output directory. in the/etc/exports file, the options are generally divided into three categories (1) access permission options: option [cpp] for controlling the access permission of the output Directory Description: ro sets the read-only rw of the output directory to set the read/write permission of the output Directory (2) User ing option: [cpp] The user ing option indicates that no matter what the NFS logon user identity is, all_squash will be compressed into an anonymous user, generally, nobody no_all_squash does not map all common users and user groups for remote access to anonymous users or user groups (default setting) root_squash maps root users and user groups to anonymous users or user groups (default) no_root_squash does not map root users and user groups to anonymous users or user groups anonuid = xxx to map all remotely accessed users to anonymous users, specify the anonymous user account as the local user account (UID = xxx) anongid = xxx to map all remotely accessed user groups to anonymous user group accounts, and specify the anonymous user group account as the local user group account (GID = xxx) (3) There are many other options commonly used, it can be used to control the output directory in a more comprehensive manner. [cpp] Other options indicate that secure limits the client to be able /IP port connection to the NFS server (default setting) insecure allows the client to connect to the NFS server sync from a TCP/IP port greater than 1024 to write data to the memory buffer and disk synchronously, although this method is inefficient, it ensures data consistency. async first saves data in the memory buffer and writes it to the disk if necessary. Wdelay checks whether there are related write operations. If yes, the write operations are executed together. This improves efficiency (default setting). no_wdelay performs the write operation immediately if there is a write operation, subtree_check should be used with sync. if the output directory is a sub-directory, the NFS server will check the permissions of its parent directory (default setting) no_subtree_check even if the output directory is a sub-directory, the NFS server does not check the permissions of its parent directory. This improves efficiency.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.