• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# NFS<a name="EN-US_TOPIC_0000001078704660"></a>
2
3-   [Basic Concepts](#section195414101464)
4-   [Working Principles](#section165621321194618)
5-   [Development Guidelines](#section7454935184611)
6
7## Basic Concepts<a name="section195414101464"></a>
8
9NFS allows you to share files across hosts and OSs over a network. You can treat NFS as a file system service, which is equivalent to folder sharing in the Windows OS to some extent.
10
11## Working Principles<a name="section165621321194618"></a>
12
13The NFS of the OpenHarmony LiteOS-A kernel acts as an NFS client. The NFS client can mount the directory shared by a remote NFS server to the local machine and run the programs and shared files without occupying the storage space of the current system. To the local machine, the directory on the remote server is like its disk.
14
15## Development Guidelines<a name="section7454935184611"></a>
16
171.  Create an NFS server.
18
19The following uses the Ubuntu OS as an example to describe how to configure an NFS server.
20
21-   Install the NFS server software.
22
23Set the download source of the Ubuntu OS when the network connection is normal.
24
25```
26sudo apt-get install nfs-kernel-server
27```
28
29-   Create a directory for mounting and assign full permissions for the directory.
30
31```
32mkdir -p /home/sqbin/nfs
33sudo chmod 777 /home/sqbin/nfs
34```
35
36-   Configure and start the NFS server.
37
38Append the following line in the  **/etc/exports**  file:
39
40```
41/home/sqbin/nfs *(rw,no_root_squash,async)
42```
43
44**/home/sqbin/nfs**  is the root directory shared by the NFS server.
45
46Start the NFS server.
47
48```
49sudo /etc/init.d/nfs-kernel-server start
50```
51
52Restart the NFS server.
53
54```
55sudo /etc/init.d/nfs-kernel-server restart
56```
57
581.  Configure the board as an NFS client.
59
60In this section, the NFS client is a device running the OpenHarmony kernel.
61
62-   Set the hardware connection.
63
64Connect the OpenHarmony kernel device to the NFS server. Set their IP addresses in the same network segment. For example, set the IP address of the NFS server to  **10.67.212.178/24**  and set the IP address of the OpenHarmony kernel device to  **10.67.212.3/24**. Note that the preceding IP addresses are private IP addresses used as examples. You need to use your actual IP addresses.
65
66You can run the  **ifconfig**  command to check the OpenHarmony kernel device's IP address.
67
68-   Start the network and ensure that the network between the board and NFS server is normal.
69
70Start the Ethernet or another type of network, and then run  **ping**  to check whether the network connection to the server is normal.
71
72```
73OHOS # ping 10.67.212.178
74[0]Reply from 10.67.212.178: time=1ms TTL=63
75[1]Reply from 10.67.212.178: time=0ms TTL=63
76[2]Reply from 10.67.212.178: time=1ms TTL=63
77[3]Reply from 10.67.212.178: time=1ms TTL=63
78--- 10.67.212.178 ping statistics ---
794 packets transmitted, 4 received, 0 loss
80```
81
82Initialize the NFS client.
83
84```
85OHOS # mkdir /nfs
86OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000
87```
88
89If the following information is displayed, the NFS client is initialized.
90
91```
92OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000
93Mount nfs on 10.67.212.178:/home/sqbin/nfs, uid:1011, gid:1000
94Mount nfs finished.
95```
96
97This command mounts the  **/home/sqbin/nfs**  directory on the NFS server whose IP address is 10.67.212.178 to the  **/nfs**  directory on the OpenHarmony kernel device.
98
99>![](../public_sys-resources/icon-note.gif) **NOTE:**
100>This section assumes that the NFS server is available, that is, the  **/home/sqbin/nfs**  directory on the NFS server 10.67.212.178 is accessible.
101>The  **mount**  command format is as follows:
102>```
103>mount <SERVER_IP:SERVER_PATH> <CLIENT_PATH> nfs
104>```
105>-   **SERVER\_IP**  indicates the IP address of the server.
106>-   **SERVER\_PATH**  indicates the path of the shared directory on the NFS server.
107>-   **CLIENT\_PATH**  indicates the NFS path on the local device.
108>-   **nfs**  indicates the path to which the remote shared directory is mounted on the local device.
109>Replace the parameters as required.
110>If you do not want to restrict the NFS access permission, set the permission of the NFS root directory to  **777**  on the Linux CLI.
111>```
112>chmod -R 777 /home/sqbin/nfs
113>```
114>The NFS client setting is complete, and the NFS file system has been mounted.
115
1161.  Share files using NFS.
117
118Create the  **dir**  directory on the NFS server and save the directory. Run the  **ls**  command in the OpenHarmony kernel.
119
120```
121OHOS # ls /nfs
122```
123
124The following information is returned from the serial port:
125
126```
127OHOS # ls /nfs
128Directory /nfs:
129drwxr-xr-x 0        u:0     g:0     dir
130```
131
132The  **dir**  directory created on the NFS server has been synchronized to the  **/nfs**  directory on the client \(OpenHarmony kernel system\).
133
134Similarly, you can create files and directories on the client \(OpenHarmony kernel system\) and access them from the NFS server.
135
136>![](../public_sys-resources/icon-note.gif) **NOTE:**
137>Currently, the NFS client supports some NFS v3 specifications. Therefore, the NFS client is not fully compatible with all types of NFS servers. You are advised to use the Linux NFS server to perform the development.
138
139