Mount mini2440 NFS to Ubuntu

Source: Internet
Author: User

Reprinted please indicate the source: http://dreamlcr.cublog.cn/
----------------------------------------------------

Network File System (NFS)

I. Introduction to NFS

1. NFS is short for Network File System. Its biggest function is to allow different machines and operating systems to share files with each other over the network) -- you can mount the directory of the remote host through NFS. Accessing the directory is like accessing the local directory, so you can simply regard it as a file server ).

Note: In general, NFS can be used to easily share Unix-like systems. However, if you want to share a Unix-like system with a Windows system, so you have to use Samba.

2. NFS transmits data over the network. What port does NFS use? The answer is ...... I don't know, because the NFS port used for data transmission is random, the only limit is less than 1024. How does the client know which port the server uses? In this case, Remote Procedure Call RPC is required.

In fact, NFS runs on the basis of Sun's Remote Procedure Call (Remote Procedure Call). RPC defines a system-independent method for inter-process communication, NFS server can also be considered as an RPC server. Because NFS is an RPC service program, you must map the port before using it-set through Portmap. For example, when an NFS client initiates an NFS service request, it needs to first obtain a port, so it first obtains the port number through Portmap (not only NFS, you must set Portmap before starting all RPC service programs ).

Note: Before starting the RPC service (such as NFS), you must start the Portmap service.

3. NFS allows the system to share its directories and files to other systems on the network. With NFS, users and applications can access files on the remote system, just as they are local files. NFS has the following advantages:
(1) local workstations can use less disk space, because common data can be stored on one machine and accessed by other machines on the network.
(2) You do not need to put a user directory on each network machine, because the user directory can be set on the NFS server and make it available throughout the network.
(3) storage devices such as floppy disks, optical drives, and USB drives can be used by other machines on the network, which may reduce the number of mobile devices on the network.

Ii. Several nfs-related files and commands

1./etc/exports
The access to the NFS service is approved by exports, which enumerate several hostnames that have the right to access the file system on the NFS server.

2./sbin/exportfs
To maintain NFS resource sharing, You can reset the shared directory of/etc/exports, unmount the shared directory of NFS server, or share it again.

3./usr/sbin/showmount
The above files are mainly used on the NFS server, while showmount is mainly used on the client. showmount can be used to view NFS shared directory resources.

4./var/lib/nfs/xtab
NFS record document: You can view which clients are connected to the NFS host.

The following are not directly responsible for NFS. In fact, they are responsible for all RPC.

5./etc/default/Portmap
In fact, Portmap maps all the RPC service ports. Its content is very simple.

6./etc/hosts. Deny
Set the host that rejects the Portmap service, that is, the list of Client IP addresses that are not allowed to access.

7./etc/hosts. Allow
Set the host that allows the Portmap service, that is, the list of Client IP addresses allowed to access.

Iii. NFS Installation

Install the NFS service software on the host, because Debian/Ubuntu is not installed by default.

1. Install port er Portmap (optional)
$ Sudo apt-Get install Portmap

2. Enter the following command at the terminal prompt to install the NFS server:
$ Sudo apt-Get install nfs-kernel-Server

3. Install the NFS client (optional)
$ Sudo apt-Get install nfs-common

Note: Both nfs-kernel-server and NFS-common depend on Portmap. In addition, it is suggested in some documents that APT-Get should be used to manually install NFS client nfs-common and port er Portmap. However, this is not necessary, this is because apt automatically installs nfs-kernel-server.

In this way, the host is equivalent to the NFS server. Similarly, if the target system is an NFS client, you must install the NFS client program. For Debian/Ubuntu systems, install nfs-common (step 1 ).

Iv. NFS configuration

1. Configure Portmap
Method 1: edit/etc/default/Portmap and remove "-I 127.0.0.1;
Method 2: $ sudo dpkg-reconfigure Portmap. The "Configuring Portmap" Software Package setting interface appears. Do you want to shocould Portmap be bound to the loopback address? Select "no )".

2. Configure/etc/hosts. Deny
Prohibit any host from connecting to your NFS server. Add:

### NFS daemons
Portmap: All
Lockd: All
MOUNTD: All
Rquotad: All
STATD: All

3. Configure/etc/hosts. Allow
Allow hosts you want to establish connections with your NFS server.

The following steps allow any host starting with 192.168.1 to connect to the NFS server. The specific IP address depends on the port address of your target board, or you can specify a specific IP address. Add:

### NFS daemons
Portmap: 192.168.1.
Lockd: 192.168.1.
Rquotad: 192.168.1.
MOUNTD: 192.168.1.
STATD: 192.168.1.

Use/etc/hosts. Deny and/etc/hosts. Allow to set access to Portmap. The two configuration files are similar to "Mask. Prohibit all users from accessing Portmap in/etc/hosts. deny, and then allow some users to access Portmap in/etc/hosts. allow.

Restart Portmap daemon:
$ Sudo/etc/init. d/Portmap restart

4. Configure/etc/exports

(1) The shared NFS directory is listed in/etc/exports. This file controls the sharing of directories (the NFS mount directory and permissions are defined by this file ), the writing rule is that each row is shared ).

Format: [shared directory] [host name or IP address] (parameter, parameter ...)
The first parameter is the directory to be accessed by the client, the second parameter is the IP address of the host you allow, and the last () parameter is the access control method.

Note: The client can specify the host name or IP address, and use wildcard characters (*) In the host name. The IP address can also be followed by the mask segment (/24 ), however, we should avoid this situation for security reasons. After the description of the client, you can add a series of parameters in parentheses. It is very important not to leave any blank space behind the last client declaration or not close the brackets, because the blank space is interpreted as the separator of the client.

For example, if you want to share the/opt/friendlyarm/mini2440/root_nfs directory with your IP address, add the following statement at the end of the file:
/Opt/friendlyarm/mini2440/root_nfs * (RW, sync, no_root_squash)

Where:
/Opt/friendlyarm/mini2440/root_nfs indicates the NFS shared directory, which can be mounted as the root file system of the Development Board through NFS;
* Indicates that all clients can mount the directory;
RW indicates that the Client Connected to this directory has the permission to read and write the directory;
Sync indicates that all data is written to the shared data upon request, that is, data is synchronized to the memory and hard disk;
No_root_squash indicates that the Client Connected to this directory is allowed to have the root identity of the host.

Note: You can use the host name instead of *. Specify the host name as much as possible so that systems that do not want it to access cannot access resources mounted by NFS. In addition, it is best to add sync. Otherwise, a warning will be given when $ sudo exportfs-R is used. Sync is the default option of NFS.

(2) below are some common NFS sharing parameters:
RO read-only access
RW read/write access
Sync all data written for sharing upon request
Async NFS can request data before writing data
Secure NFS is sent through the secure TCP/IP ports below 1024
Insecure NFS is sent over port 1024
Wdelay if multiple users want to write data to the NFS Directory, group write (default)
No_wdelay if multiple users want to write data to the NFS Directory, write the data immediately. This setting is not required when async is used.
Hide does not share its subdirectories in the NFS shared directory.
No_hide shares the subdirectory of the NFS Directory
Subtree_check if sub-directories such as/usr/bin are shared, force NFS to check the permissions of the parent directory (default)
No_subtree_check is opposite to the above. The parent directory permission is not checked.
All_squash: The UID and gid of the shared file are mapped to the anonymous user anonymous, which is suitable for public directories.
No_all_squash retains the UID and gid of the shared file (default)
Root_squash all requests of the root user are mapped to the same permissions as those of the anonymous user (default)
The no_root_squash root user has full management access permissions to the root directory.
Anonuid = xxx specifies the UID of an anonymous user in the NFS server/etc/passwd file
Anongid = xxx specifies the GID of anonymous users in the NFS server/etc/passwd file

(3) view the NFS server's export list:
$ Sudo showmount-e

If/etc/exports is changed, run the following command to update it:
$ Sudo exportfs-R

Then restart the NFS service:
$ Sudo/etc/init. d/nfs-kernel-server restart

5. Start and Stop the NFS service

1. The method for starting NFS is similar to that for starting other servers. You must first start the Portmap and NFS services, and the Portmap service must be started before the NFS service.
$ Sudo/etc/init. d/Portmap start
$ Sudo/etc/init. d/nfs-kernel-Server start

2. Stop the NFS service.
When stopping the NFS service, you must stop the NFS service before stopping the Portmap service. If other services in the system need to use the Portmap service, you can stop the Portmap service.
$ Sudo/etc/init. d/nfs-kernel-server stop
$ Sudo/etc/init. d/Portmap stop

3. Restart the Portmap and NFS services.
$ Sudo/etc/init. d/Portmap restart
$ Sudo/etc/init. d/nfs-kernel-server restart

4. Check Portmap and NFS service status
$ Sudo/etc/init. d/Portmap status
$ Sudo/etc/init. d/nfs-kernel-Server Status

5. Set automatic start of NFS service

(1) Check the NFS running level:
$ Sudo chkconfig -- list Portmap
$ Sudo chkconfig -- list nfs-kernel-Server

(2) In actual use, it is very troublesome to manually start the NFS service after each computer is started. You can set the system to automatically start the Portmap and NFS services at the specified running level.
$ Sudo chkconfig -- level 235 Portmap on
$ Sudo chkconfig -- level 235 nfs-kernel-server on

Vi. NFS client configuration (NFS test)

1. After the NFS server is started, check the firewall settings of the Linux Server (usually 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. It is usually developed in the internal lan. It is best not to install firewall and other network security software when installing the system, so as to facilitate the configuration during use.

If you have a firewall, make sure ports 32771, 111, and 2049 are open.

2. Manual mounting
Use the mount command to mount the NFS Directory shared by other machines.

Format: $ sudo Mount [server IP]:/[Share dir] [local mount point]

For example:
$ Sudo Mount-t nfs [-O nolock] localhost:/opt/friendlyarm/mini2440/root_nfs/mnt/root_nfs or
$ Sudo Mount-T nfs-O nolock 192.168.1.101:/opt/friendlyarm/mini2440/root_nfs/mnt/root_nfs

Localhost can be a specific IP address, and the mount point/mnt/root_nfs directory must already exist, and there is no file or subdirectory in the/mnt/root_nfs directory.

3. automatic mounting

(1) another way to mount nfs sharing on other machines is to add a row in the/etc/fstab file, this row must specify the Host Name of the NFS server, the directory name output by the server, and the local directory mounted to NFS sharing. At the same time, it must be the root user to modify the/etc/fstab file.

Format: server.mydomain.com:/usr/local/pub NFS rsize = 8192, wsize = 8192, timeo = 14, Intr

Note: you can modify the NFS server shared folder "servername.mydomain.com:/usr/local/pub" and the local mount point "/pub ", at the same time, the mount point/pub must exist on the client machine.

(2) Common NFS mount parameters:
If timeo times out, the client waits for a second.
Retrans timeout attempts
BG background mounting (useful)
Hard if the server does not respond, the client keeps trying to mount
Rsize read block size
Wsize write block size

4. Use autofs to mount NFS

(1) The Third Way to mount nfs sharing is to use autofs, which uses the automount daemon to manage mount points and dynamically mounts them only when the file system is accessed.

Autofs accesses the master ing configuration file/etc/auto. Master to determine which mount points to define, and then starts the automount daemon process using the parameters applicable to each mount point. Each row in the master ing configuration defines a mount point, and a separate ing file defines the file system to be mounted under the mount point. For example, the/etc/auto. Misc file may define the mount point in the/MISC directory. This relationship will be defined in the/etc/auto. master file.

(2)/etc/auto. each project in the master file has three fields, 1st of which are mount points, 2nd of which are the location of the ing file, and 3rd of which are optional and can contain information such as timeout values.

For example, mount the/project52 directory in penguin.example.net on the/MISC/myproject mount point on the machine.
Add the following lines to the/etc/auto. master file:
/MISC/etc/auto. Misc -- timeout 60
Add the following lines to the/etc/auto. Misc file:
Myproject-RW, soft, Intr, rsize = 8192, wsize = 8192 penguin.example.net:/proj52

/Etc/auto. the first field in MISC is the name of the/MISC sub-Directory, which is created dynamically by automount. It should not actually exist on the client machine. The second field includes the mounting option, for example, RW indicates read/write access. The 3rd fields are the location of the NFS to be exported, including the host name and directory.

(3) autofs is a service. To start this service, enter the following command at the shell prompt:
$ Sudo/sbin/service autofs restart
To view active mount points, enter the following command at the shell prompt:
$ Sudo/sbin/service autofs status
If the/etc/auto. Master configuration file is modified when autofs is running, you must enter the following command at the shell prompt to notify the automount daemon to reload the configuration file:
$ Sudo/sbin/service autofs reload

5. Run the DF command to check whether the mounting is successful:
$ Sudo DF

The command to cancel mounting is as follows:
$ Sudo umount/mnt/root_nfs

VII. Target Board NFS configuration operation

Host IP Address: 192.168.1.101
Target Board IP Address: 192.168.1.230

Connect the USB to the serial port and input minicom on the terminal to connect the board as a "Super Terminal.

After starting the target board and connecting to the network, first check whether the target board kernel itself supports NFS. In minicom, enter the CAT/proc/filesystems command to check whether there is a line of NFS, if not, it indicates that the kernel does not support NFS. You need to re-compile and burn the kernel. If yes, OK. Then you can directly mount the kernel.

The specific command is:
# Mount-T nfs-O nolock 192.168.1.101:/opt/friendlyarm/mini2440/root_nfs/mnt/root_nfs

If no prompt is displayed, the file is successful. You can enter the/mnt/root_nfs directory and perform CP, MV, and other operations on the file.

However, if you run the Mount-t nfs 192.168.1.101:/opt/friendlyarm/mini2440/root_nfs/mnt/root_nfs command, the following error message is displayed (that is, "-O nolock" is omitted "):
# Mount-t nfs 192.168.1.101:/opt/friendlyarm/mini2440/root_nfs/mnt/root_nfs
Portmap: Server localhost not responding, timed out
RPC: failed to contact Portmap (errno-5 ).
Portmap: Server localhost not responding, timed out
RPC: failed to contact Portmap (errno-5 ).
Lockd_up: makesock failed, error =-5
Portmap: Server localhost not responding, timed out
RPC: failed to contact Portmap (errno-5 ).

If you use the LS/mnt/root_nfs command to view the contents of this directory, you will find that NFS has been mounted successfully.

The following error message is displayed when the mounting is canceled:
# Umount/mnt/root_nfs/
Lockd_down: No lockd running.

When the mounting is successfully canceled, there is no prompt. At this time, NFS has indeed canceled the mounting.

The cause of the above error message may be:
The default NFS mount options include file locks, depending on the dynamic port allocation function provided by Portmap.

A simple solution: Kill the file lock (lockd) or use the Mount-O nolock command.

What are the specific causes of the file lock mentioned above? No better solutions have been found yet. However, if the host firewall is configured, the target board may not be accessible.

If you want to use the command port, you only need to enter minicom (if you want to use a notebook, your port cannot use tty0 but ttyusb0). After entering, you can enter the command. Then mount the file directly. Yes. However, your eth0 will definitely conflict with your infinite. I am afraid I cannot change it. Because it will not be your network card, so NFS cannot be connected

In the embedded learning process, the online notes are integrated:

NFS configuration for Debian/Ubuntu
Introduction: NFS (Network File System) allows you to share directories of different hosts (different OS) over the network-you can mount directories of remote hosts through NFS, accessing this directory is like accessing a local directory!
Generally, NFS can be used to easily share Unix-like systems.
Principle: NFS runs on the basis of Sun's Remote Procedure Call (Remote Procedure Call). RPC defines a system-independent method for inter-process communication. therefore, the NFS server can also be viewed as an RPC server.
Because NFS is an RPC service program, you must map the port before using it-set it through Portmap. for example, when an NFS client initiates an NFS service request, it must first obtain a port ). therefore, it first obtains the port number through Portmap. (not only NFS, but Portmap needs to be set before all RPC service programs start)

For NFS-related files, run the following command:
1,/etc/exports
The access to the NFS volume is approved by exports, which enumerate several hostnames that have the right to access the file system on the NFS server.
2,/sbin/exportfs
Maintain NFS Resource Sharing. You can reset the shared directory of/etc/exports, unmount the shared directory of NFS server, or share it again.
3,/usr/sbin/showmount
It is used on the NFS server, while showmount is mainly used on the client. showmount can be used to view NFS shared directory resources.
4,/var/lib/nfs/xtab
NFS record document: You can view which clients are connected to the NFS host.

The following are not directly responsible for NFS. In fact, they are responsible for all RPC
5,/etc/default/Portmap
In fact, Portmap maps all the RPC service ports. Its content is very simple (detailed later)
6,/etc/hosts
Set the host to reject/allow the Portmap service

Install NFS:

By default, the NFS server is not installed on Debian/ubuntu. First, install the NFS service program:
$ Sudo apt-Get install nfs-kernel-Server
$ Sudo apt-Get install nfs-commmon
(When nfs-kernel-server is installed, APT will automatically install nfs-common and Portmap)
In this way, the host is equivalent to the NFS server.

In the development system, the NFS client must be installed as the target system as the NFS client. For Debian/Ubuntu systems, NFS-common must be installed.
$ Sudo apt-Get install nfs-commmon
Note: Both nfs-common and NFS-kernel-server depend on Portmap!

Configure NFS:
Configure Portmap $ sudo dpkg-reconfigure Portmap to shocould Portmap be bound to the loopback address? Select n.
Configure/etc/hosts. Deny
(Prohibit any host (host) from connecting to your NFS server), add:

### NFS daemons
Portmap: All
Lockd: All
MOUNTD: All
Rquotad: All
STATD: All

Configure/etc/hosts. Allow
Allow hosts you want to establish connections with your NFS server. The following steps allow any host whose IP address starts with 192.168.2 (connected to the NFS server), or specify a specific IP address. See hosts_access (5) and hosts_options (5) on the man page ).
### NFS daemons
Portmap: 59.64.
Lockds: 59.64.
Rquotad: 59.64.
MOUNTD: 59.64.
STATD: 59.64.
/Etc/hosts. deny and/etc/hosts. allow sets the access to Portmap. using these two configuration files is a bit similar to "Mask. first in/etc/hosts. deny prohibits all users from accessing Portmap. then in/etc/hosts. some users are allowed to access Portmap in allow.
Run $ sudo/etc/init. d/Portmap restart to restart Portmap daemon.

Configure/etc/exports:
The NFS mount directory and permissions are defined by the/etc/exports file./etc/exports is actually the core configuration file of the NFS server.
For example, to share the IP address of 59.64.195.97 with the/home/warmbupt/ARM/NFS directory in my home directory, add the following statement at the end of the file:
/Home/warmbupt/ARM/nfs 59.64.195.97 (RW, sync, no_root_squash)
The preceding configurations are described as follows:
The NFS client of 59.64.195.97 can share the content of the NFS server/home/warmbupt/ARM directory, and has the read and write permissions. the user's identity after entering the/home/warmbupt/ARM directory is root.
It is best to add sync. Otherwise, a warning will be given when $ sudo exportfs-R is used. Sync is the default option of NFS.

Modify the directory permission: chmod 777-r/home/warmbupt/ARM/nfs

Run $ showmount-e to view the NFS server's export list. If/etc/exports is changed, run $ sudo exportfs-r update.

Run $ sudo/etc/init. d/nfs-kernel-server restart to restart the NFS service)
$ Sudo iptables-F

Test NFS:

Try mounting the local disk (assuming the IP address of the local host is 59.64.195.97, Mount/home/warmbupt/ARM/NFS to/mnt)
$ Sudo Mount 59.64.195.97:/home/warmbupt/ARM/nfs/mnt
Run $ DF to check the result
$ Sudo umount/mnt
If permission deny appears:
Try: sudo Mount-O nolock-t nfs 59.64.195.97:/home/warmbupt/ARM/nfs/mnt

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.