1# NFS 2 3 4## Basic Concepts<a name="section195414101464"></a> 5 6NFS 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. 7 8## Working Principles<a name="section165621321194618"></a> 9 10The 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. 11 12## Development Guidelines<a name="section7454935184611"></a> 13 141. Create an NFS server. 15 16The following uses the Ubuntu OS as an example to describe how to configure an NFS server. 17 18- Install the NFS server software. 19 20Set the download source of the Ubuntu OS when the network connection is normal. 21 22``` 23sudo apt-get install nfs-kernel-server 24``` 25 26- Create a directory for mounting and assign full permissions for the directory. 27 28``` 29mkdir -p /home/sqbin/nfs 30sudo chmod 777 /home/sqbin/nfs 31``` 32 33- Configure and start the NFS server. 34 35Append the following line in the **/etc/exports** file: 36 37``` 38/home/sqbin/nfs *(rw,no_root_squash,async) 39``` 40 41**/home/sqbin/nfs** is the root directory shared by the NFS server. 42 43Start the NFS server. 44 45``` 46sudo /etc/init.d/nfs-kernel-server start 47``` 48 49Restart the NFS server. 50 51``` 52sudo /etc/init.d/nfs-kernel-server restart 53``` 54 551. Configure the board as an NFS client. 56 57In this section, the NFS client is a device running the OpenHarmony kernel. 58 59- Set the hardware connection. 60 61Connect 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. 62 63You can run the **ifconfig** command to check the OpenHarmony kernel device's IP address. 64 65- Start the network and ensure that the network between the board and NFS server is normal. 66 67Start the Ethernet or another type of network, and then run **ping** to check whether the network connection to the server is normal. 68 69``` 70OHOS # ping 10.67.212.178 71[0]Reply from 10.67.212.178: time=1ms TTL=63 72[1]Reply from 10.67.212.178: time=0ms TTL=63 73[2]Reply from 10.67.212.178: time=1ms TTL=63 74[3]Reply from 10.67.212.178: time=1ms TTL=63 75--- 10.67.212.178 ping statistics --- 764 packets transmitted, 4 received, 0 loss 77``` 78 79Initialize the NFS client. 80 81``` 82OHOS # mkdir /nfs 83OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000 84``` 85 86If the following information is displayed, the NFS client is initialized. 87 88``` 89OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000 90Mount nfs on 10.67.212.178:/home/sqbin/nfs, uid:1011, gid:1000 91Mount nfs finished. 92``` 93 94This 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. 95 96> **NOTE:** 97>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. 98>The **mount** command format is as follows: 99>``` 100>mount <SERVER_IP:SERVER_PATH> <CLIENT_PATH> nfs 101>``` 102>- **SERVER\_IP** indicates the IP address of the server. 103>- **SERVER\_PATH** indicates the path of the shared directory on the NFS server. 104>- **CLIENT\_PATH** indicates the NFS path on the local device. 105>- **nfs** indicates the path to which the remote shared directory is mounted on the local device. 106>Replace the parameters as required. 107>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. 108>``` 109>chmod -R 777 /home/sqbin/nfs 110>``` 111>The NFS client setting is complete, and the NFS file system has been mounted. 112 1131. Share files using NFS. 114 115Create the **dir** directory on the NFS server and save the directory. Run the **ls** command in the OpenHarmony kernel. 116 117``` 118OHOS # ls /nfs 119``` 120 121The following information is returned from the serial port: 122 123``` 124OHOS # ls /nfs 125Directory /nfs: 126drwxr-xr-x 0 u:0 g:0 dir 127``` 128 129The **dir** directory created on the NFS server has been synchronized to the **/nfs** directory on the client \(OpenHarmony kernel system\). 130 131Similarly, you can create files and directories on the client \(OpenHarmony kernel system\) and access them from the NFS server. 132 133> **NOTE:** 134>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. 135 136