# 嵌入式局域网调试方案
> 该方案基于`linux` 与 `nfs`  
> 其原理为将`nfs`挂载在系统上, 从而直接访问运行在`nfs`服务器上共享的文件, 从而免去烧录步骤, 快速调试  
> 验证平台: ubuntu 18.04
> 嵌入式方案: 君正linux

## 安装`nfs服务`
> 不同的服务器上有不同的安装方式

1. 使用`apt`的服务器安装`nfs-kernel-server`  (未验证)
    ```shell
    sudo apt updatesudo apt install nfs-kernel-server
    ```
2. 基于`yum`的服务器`nfs-utils` (未验证)
    ```shell
    sudo yum install nfs-utils
    ```

3. 启用`nfs`服务
    ```shell
    sudo systemctl start nfs-kernel-server
    ```


## 配置共享
> 先创建一个目录  
> 例如: `/home/test/dir`
> 再编译服务器上编辑 `/etc/exports` 文件
```shell
sudo vim /etc/exports
```

添加如下内容
```shell
/home/test/dir *(rw,sync,no_root_squash)
```

刷新环境
```
sudo exportfs -a
```




## 设备挂载
> 在设备端的控制台输入下面命令  
> `192.168.1.203` 为共享服务器的ip   
> `/home/test/dir` 为共享的目录 

```shell
mount -t nfs -o nolock 192.168.1.203:/home/test/dir /opt
```


## 测试
> [参考文章](https://blog.csdn.net/qq_34158598/article/details/81976063)  
> 平台windows10

### 启用服务
1. 在windows上打开控制面板
2. 控制面板页面上选择程序
3. 选择其中启用或关闭Windows功能
4. 找到`NFS`一项
5. 启用`NFS`

### 测试

#### 查看远程电脑NFS共享的目录
> nfs服务器为 203

```shell
showmount -e 192.168.1.203
```

```shell
showmount -e [server]    #显示 NFS 服务器导出的所有共享。
showmount -a [server]    #列出客户端主机名或 IP 地址,以及使用“主机:目录”格式显示的安装目录。
showmount -d [server]    #显示 NFS 服务器上当前由某些 NFS 客户端安装的目录。
```

#### 挂载至windows网络映射
在windows上打开资源管理器,  
右键点击`我的电脑`,选择`管理`,选择`网络共享`,  
输入如下目录  
```shell
\\192.168.1.203\home\test\dir
```
选择要挂载的目录,点击`映射为驱动器`