Configure NFS sharing in Linux

Source: Internet
Author: User
Article Title: Set up NFS sharing in a Linux operating system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Network File System (NFS) is a mechanism for attaching partitions (directories) on remote hosts to local systems through the Network, with support for the network file system, you can operate on the shared partition (directory) of the remote host on the local system just like operating on the local partition.

During the development of embedded Linux, developers need to develop all the software on the Linux server. After cross-compilation, the executable files can be downloaded to the embedded system in the FTP mode, however, this method is not only inefficient, but cannot be used for online debugging. Therefore, you can create NFS to share specific partitions on the Linux server to the Embedded Target System to be debugged, and then operate the Linux server directly on the embedded target system, at the same time, you can debug and modify the program online, greatly facilitating software development. Therefore, NFS is an important part of Embedded Linux development. This section details how to configure the NFS development environment of embedded Linux.

The implementation of the NFS development environment in Embedded Linux includes two aspects: one is the support of the NFS server on the Linux server, and the other is the support of the NFS client on the embedded target system. Therefore, to establish an NFS development environment, you must configure the linux server and Embedded Target System.

Configuration of NFS server on Linux Server

Log on to the Linux server as root, edit the exports shared directory configuration file under the/etc directory, and specify the shared directory and permissions.

Run the following command to edit the file/etc/exports:

# Vi/etc/exports

Add the following content to the file:

/Home/work 192.168.0. * (rw, sync, no_root_squash)

Save and exit.

The added content indicates that the computer with the ip address range of 192.168.0. * can access the/home/work directory with the read/write permission.

/Home/work is also called the server output shared directory.

The meanings of parameters in parentheses are described as follows:

Rw: read/write permission. the read-only permission parameter is ro;

Sync: data is written to the memory and hard disk synchronously. You can also use async. Data is saved in the memory before being written to the hard disk immediately.

No_root_squash: attributes of the NFS server shared directory user. If the user is root, the shared directory has root permissions.

Run the following command to start port ing:

#/Etc/rc. d/init. d/portmap start

Finally, run the following command to start the NFS service. At this time, NFS will activate the daemon and then start listening to Client requests:

#/Etc/rc. d/init. d/nfs start

You can also restart the Linux server to automatically start the NFS service.

After the NFS server is started, you also need to check the firewall and other settings of the Linux Server (usually you need to disable the Firewall Service) to ensure that the ports used by NFS and the hosts that allow communication are not blocked, check the settings of iptables, ipchains, and other options on the Linux server, as well as/etc/hosts. deny,/etc/hosts. allow file.

We first perform a loop test on the NFS server on the Linux server to verify whether the shared directory can be accessed. Run the following command on a Linux Server:

# Mount? T nfs 192.168.0.20:/home/work/mnt

# Ls/mnt

Command to mount the NFS output shared directory of the Linux server to the/mnt directory. Therefore, if NFS works properly, you should be able to see the content in the/home/work shared directory in the/mnt directory.

Ii. configurations of NFS clients in the Embedded Target System

After the Linux server is configured, you also need to configure the client. When configuring the kernel, select Load an Alternate Configuration File and enter the path and File name of the Configuration File to add Kernel support for NFS:

Select networking options-> IP: kernel level aulow.alion.

Select the root file system on nfs under file systems-network file systems-

And nfs file system support re-compile the kernel to download bootloader and kernel to the Development Board.

In the Linux Shell of the embedded target system, run the following command to mount the NFS shared directory:

# Mkdir/mnt/nfs // create a mount point for the Linux server to output the shared directory;

# Mount? T nfs 192.168.0.20:/home/work/mnt/nfs? O nolock

# Cd/mnt/nfs

# Ls

In this case, the content displayed on the Embedded Target system is the content of the output directory of the Linux server, that is, the output directory of the Linux server.

/Home/work is mapped to the/mnt/NFS Directory of the embedded target system through nfs. You can use the Add/delete/modify method to verify the actual effect. In the mount command, 192.168.0.20 is the IP address of the Linux server,/home/work is the shared output directory configured on the Linux server, And/mnt/nfs is the local directory on the embedded device.

During the development process, it is very annoying to input commands back and forth. I wrote two simple scripts to start and mount nfs.

       
        
Host starts nfs: snfs #! /Bin/bashifconfig eth0 192.168.0.20/etc/rc. d/init. d/portmap start/etc/rc. d/init. d/nfs start mounting nfs: mnfs: #! On the Embedded Target machine :#! /Bin/shmount-t nfs 192.168.0.20:/home/work/nfs/mnt/nfs-o nolockecho "nfs OK !"
       
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.