Create and configure an instance for the NFS development environment of Embedded linux

Source: Internet
Author: User
Create and configure an instance for the NFS development environment of Embedded linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. In the application development stage, the NFS method is more efficient than the ftp method, because it does not need to download the linux server program to the Embedded Target System for debugging. Next we will first write down the detailed process of establishing NFS, and then compare the differences between the ftp and nfs modes by using a simple application development instance.

1. Establish an NFS development environment

The NFS development environment for Embedded linux includes two aspects: NFS server support for linux Server and NFS Client support for target board.

1.1 linux server

1.1.1 Log On As root, compile the exports configuration file of the shared directory, and specify the shared directory and its permissions.
# Vi/etc/exports
Add:
/Home/lqm (shared directory) 192.168.1. * (rw, sync, no_root_squash)
The added content allows the computer with the IP address range of 192.168.1. * to access the shared directory/home/lqm with the read and write permissions.
[Note: The parameters are described as follows:
Rw --- read/write permissions. If read-only permission is set, it is set to ro. But in general, to facilitate interaction, you must set it to rw.
Sync-synchronize data into memory and hard disk.
No_root_squash -- this parameter is used to require the server to allow remote systems to access this directory with its own root privilege. That is to say, if the user is root, then he has the root permission on the shared directory. Obviously, this parameter grants great rights to the target board. Security is the first thing to consider. You can adopt a certain protection mechanism. The following describes the protection mechanism. If the default root_squash is used, many of the target board's own root file systems may not be able to write data, so the running will be greatly restricted. We recommend that you use the no_root_squash parameter while ensuring security .]

1.1.2 initial Protection Mechanism
You can set the/etc/hosts. deny and/etc/hosts. allow files to restrict the access permissions of network services.
* **/Etc/hosts. deny ***
Portmap: ALL
Lockd: ALL
Mountd: ALL
Rquotad: ALL
Statd: ALL
* **/Etc/hosts. allow ***
Portmap: 192.168.1.100
Lockd: 192.168.1.100
Mountd: 192.168.1.100
Rquotad: 192.168.1.100
Statd: 192.168.1.100
By using these two files at the same time, only machines with ip address 192.168.1.100 can use the NFS service. Set the IP address of your target board to 192.168.1.100.

1.1.3 start
First, start the portmapper (Port ing) service, which is required by NFS itself.
#/Etc/init. d/portmap start
Then start the NFS Server. In this case, NFS activates the daemon and starts to listen to client requests.
#/Etc/init. d/nfs start
After the NFS Server is started, check the linux server's iptables and so on to make sure that the port used by NFS is not blocked and the host that allows communication.
You can perform the NFS recycle test on the linux server first. Modify/etc/hosts. allow, change the ip address to the ip address of the linux server, and then run the following command on the linux server:
# Mount-t nfs :/Home/lqm/mnt
# Ls/mnt
If the NFS Server works properly, you should see the contents of the shared directory/home/lqm under/mnt.

1.2 target board client

1.2.1 The embedded Linux kernel should support the NFS client.

When configuring the kernel, select the following:
File system --> Network File Systems -->
Select NFS System support and Provide NFSvs client support, save and exit, re-compile the kernel, and re-download the generated zImage to the target board.

1.2.2 in the linux shell of the target board, run the following command to mount the NFS shared directory.
# Mkdir/mnt/nfs
# Mount-o nolock-t nfs :/Home/lqm/mnt/nfs
# Ls/mnt/nfs
Because portmap is not included in the root file system of many embedded devices, the-o nolock parameter is generally used, that is, the NFS file lock is not used, so that portmap can be avoided. If it succeeds, you can see the content in the shared folder of linux server under/mnt/nfs, and the modifications in the two folders are synchronized.

2. Application Instance

Write a simple C program test. c
-------------------------------------------
/* This is a test program .*/
Int main (void)
{
Int I;
For (I = 0; I <10; I ++)
Printf ("Hello World % d times. \ n", I );
Return 0;
}
-------------------------------------------
Compile the program:
# Arm-linux-gcc-o test. c

2.1 FTP

First download test to target board. Start linux on the target board and run the following command on the Super Terminal:
# Cd/var
# Ftp
Ftp> bin // transfers files in binary mode
Ftp> get test
Ftp> exit
Then modify the file attributes:
# Chmod + x test
#./Test
Now you can view the results.

2.2 NFS Mode

Mount the shared output directory of the linux server on the target board and run the program.
# Mkdir/mnt/nfs
# Mount-o nolock-t nfs :/Home/lqm/mnt/nfs
# Ls/mnt/nfs
The contents of the shared directory of linux server are displayed. Then execute:
#./Test

3. Conclusion

These two methods are not very complex in the application time zone, not very large, but when the development program is more complex, the NFS method is obviously much more efficient. After developing the application, you can download it to the flash file system of the embedded target board after debugging, or compile it directly to the embedded Linux kernel and burn it to flash, and finally become an independent embedded application.
---------------------------------------
Bibliography: building embedded linux systems
Embedded linux system development-based on EP93XX ARM
These two books are detailed in the process and are suitable for beginners to learn. On the basis of being familiar with the practice, I have elevated the theoretical height. This is my learning method.
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.