NFS built in an embedded environment

Source: Internet
Author: User

NFS built in an embedded environment


Author: Tiger-John
Time: 2013-08-04
Mail: jibo.tiger@gmail.com
Blog: http://blog.csdn.net/tigerjb/article/details/9748561

Reprinted please indicate the source!

[Abstract]: This article introduces NFS concepts, NFS configuration files, and how to set up NFS servers and clients, and checks whether the settings are successful. It also analyzes the exceptions, an embedded configuration instance is also provided.

1. Introduction to network file systems

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) The server can be a virtual machine or an independent Linux server.

(4) create multiple accounts on the server for sharing, saving resources

(5) You can have an independent personal directory, which is secure and reliable.

Ii. NFS server settings

The configuration of the NFS server includes four main steps:

(1) install 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 Start and Stop are implemented through the script file NFS in the/etc/init. d directory.

(3) run the/etc/init. d/nfs restart command on the command line to restart NFS.

Note:

Before starting the NFS server, start rpcbind.

#/Etc/init. d/rpcbind restart

2.2 configure the NFS server

(1) configuring 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:

dir_to_export  NFS_client (permissions)  [NFS_client (permissions)…]

Instance:

# Vim/etc/exports

/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 NFS service output directory list

(1) After modifying the content of the/etc/exprots file, you do not need to restart the NFS service, but 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: Re-mount 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 detaching all shared directories, run the following command:

# Exportfs-Au

Iii. NFS client settings

The NFS server is shared by/etc/expors and released with exportfs. After the directory is shared, run the shownmount command to display the shared directory.

To configure an NFS client, follow these 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) view mounting information

3.1 install the NFS client (NFS configuration is supported in the kernel)

To run NFS on the target board, you must compile the kernel to support NFS.

 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, you can run the showmount command to view the shared directories on the NFS server.

(1) The command format of showmount is as follows:

Showmount [-ade] [hostname]

-A: List all remote loads.

-D: List directories 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.101

3.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:

mount -t nfs NFS_server_name :exported-directory  mount_point

-T nfs: Specifies the file system type.

Nfs_server_name: Specifies the name of the NFS server;

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, enter/mnt/NFS to enter the/share1 directory on the remote host tiger.

3.4 check whether the load is successful

(1) DF can display 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 unmount an NFS File System

Use umount command

Umount/home/think/test

You need to exit the mounted directory before unmounting. Otherwise, the following message is displayed:

The device is busy!

3.6 automatic NFS mounting

The mount point and related parameters mounted at startup 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 and related parameters mounted at startup 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

mout  -t  nfs  192.168.1.100:/home/think//EmbeddedWork  /mnt -o nolock
Iv. execption

4.1 The network between the Development Board and the host is disconnected

If the network end is connected

NFS: Server 192.168.0.12 not responding, still trying

4.2 connection timeout

Portmap: Server localhost not responding, timed out

Solution:

# Mount-T nfs-O nolock node1:/public

The-O nolock parameter is added because:

Unfsd doesn't support nlmlocking, and it's causing the lockd daemon to be started (which again requiresthe Portmapper to be installed.

4.3 restricted access

Access denied by server while mounting

The possible cause is that the firewall is faulty or the IP segment range set in the configuration file is set incorrectly or the setting is small. If the modification is not complete, then, use a "*" to replace the previous IP address. Although it is not safe, it can solve the problem.

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 but the network and server are both good, 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.

V. Instance

. Typical settings of Embedded Systems

(1) server-side settings of Embedded Systems

Because embedded systems are developed by connecting their own computers to the Development Board, they do not have much security considerations for access IP addresses and permissions. Therefore, the settings are simple and the following configurations are generally used:

/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) Use the following mount command to mount the client (Development Board ):

# Mount-t nfs 192.168.1.100:/home/think // embeddedwork/mnt-O nolock

Appendix 1: Detailed description of each element in exportfs

1. Common Methods for specifying the client:

Client description 192.168.16.20 specifies the IP address of the host 192.168.16.0/24 (or 192.168.16. *) specifies all hosts in the subnet. pc1.gdvcp.net specifies the host of the domain name * .gdvcp.net specifies all hosts in the 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:

Options used to control access to the output directory

The ACL option indicates that Ro sets the output directory read-only RW sets the output directory to read and write.

(2) User ing options:

The user ing option indicates that all_squash will be compressed into anonymous users regardless of the NFS user identity, generally, nobodyno_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) Other common options

There are many other options for more comprehensive control over the output directory.

Other options indicate that the secure client can only connect to the NFS server from a TCP/IP Port smaller than 1024 (default) insecure allows the client to connect to NFS server sync from a TCP/IP port greater than 1024 to write data to the memory buffer and disk synchronously, although this is less efficient, however, the data consistency can be ensured. async first saves the data in the memory buffer and writes the data to the disk only when 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.

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.