Windows10搭建NFS服务

1 下载haneWIN NFS Server for Windows#

链接如下:
https://www.hanewin.net/nfs-e.htm
image

2 安装并且执行 haneWIN NFS Server#

安装完后,打开hanWin如下:进入Edit->Preferences
image

进入Exports->Edit exports file
image

2.1 修改配置文件#

image
添加一行配置如下:
D:\ldc_res -name:nfs *(rw,sync,no_root_squash)
表示把D盘ldc_res目录当成nfs共享目录,-name:nfs表示客户端挂载时使用nfs表示D:\ldc_res路径
mount -t nfs -o nolock 192.168.0.100:/nfs /mnt/sd

2.2 保存配置#

勾选如下2个选项:仅对授权用户可见,通过nfs将导出添加到文件夹的上下文菜单
image

3 让NFS服务通过防火墙#

方法1:打开电脑防火墙设置,将专用网络和公用网络的防火墙禁用。
image
image

方法2:设置防火墙入栈连接规则
查看haneWIN NFS server的端口映射:
image
可以看到haneWIN使用的端口如下:

TCP:111, 1058, 2049
UDP:111, 1058, 2049

进入windows防火墙高级设置,设置入栈规则->新建规则:

规则类型选端口,
协议选TCP, 规则应用于特定本地端口,输入刚才查看的映射端口号:111,1058, 2049
操作选允许连接
配置文件将域,专用,公用网络全部勾选
最后设置好名称和描述

image
image
image
image
image
image

4 开发板客服端挂载测试#

image

设置板端IP地址:
image
先确保windows和板端能ping通
image

4.1 挂载共享目录到开发板#

image

mount -t nfs -o nolock 192.168.0.100:/nfs /mnt/sd
可以看到已经挂载上了,并且能访问挂载目录的文件

4.2 添加可写可执行权限#

挂载上后发现没有可写权限,
image

修改配置exports选项,添加-maproot:0 -public
D:\ldc_res -name:nfs -maproot:0 -public *(rw,sync,no_root_squash)
image

可以可写可执行了:
image

5 nfs配置文件#

#
# exports example
#
# please read doc for a list of all options
# drive letters should be in upper case, because file-id returns upper case
#   by default (option setting) they are mapped to lower case for clients
# Option -range restricts access to specified address range
#   a list of addresses restricts to these clients only
# Option -readonly prohibits create/write/delete
# Option -name:<x> makes folder for clients avalailable as /<x>
# Option -maproot:<uid> maps unix root to specified <uid>
#   without it uid root -> uid NOBODY
# Option -alldirs allows clients to mount folder or any subfolder
# Use UNC path specification for access to remote drive
# Hidden volumes without a drive letter can be mounted by volume GUID
#
C:\ftp -range 192.168.1.1 192.168.1.10
C:\video -readonly 192.168.1.1 192.168.1.4 192.18.1.23
C:\server -alldirs -name:server -maproot:0 -range 192.168.1.1 192.168.1.30
\\router\FRITZ.NAS\SanDisk-U3CruzerMicro-00 -name:fritz
\\?\Volume{6afa3aa3-1b38-11e6-a140-0000fbaa0005}\ -name:drive1
D:\ldc_res -name:nfs -public -maproot:0 *(rw,sync,no_root_squash)
E:\ -name:nfs_udisk -public -maproot:0 *(rw,sync,no_root_squash)

挂载:
mount -t nfs -o nolock 192.168.0.100:/nfs_udisk /mnt/