1、安装
sudo apt-get install nfs-kernel-server nfs-common portmap
高版本ubuntu,portmap被rpcbind代替,只需要安装nfs-kernel-server,其他依赖包会自动安装;
2、配置
/etc/exports中添加:
/nfs_root *(rw,sync.no_root_squash)
#【NFS共享的常用参数】
ro 只读访问
rw 读写访问
sync 同步写入硬盘
async 暂存内存
secure NFS通过1024以下的安全TCP/IP端口发送
insecure NFS通过1024以上的端口发送
wdelay 多个用户对共享目录进行写操作时,则按组写入数据(默认)
no_wdelay 多个用户对共享目录进行写操作时,则立即写入数据
hide 不共享其子目录
no_hide 共享其子目录
subtree_check 强制NFS检查父目录的权限
no_subtree_check 不检查父目录权限
all_squash 任何访问者,都转为 匿名yong
root_squash root用户访问此目录, 映射成如anonymous用户一样的权限(默认)
no_root_squash root用户访问此目录,具有root操作权限
3、重启配置文件和服务
exportfs -rv
/etc/init.d/nfs-kernel-server restart
/etc/init.d/rpcbind restart
#exportfs是linux的一个用于管理NFS文件系统的命令,在不直接编辑/etc/exports的情况下,可用该命令来操作;
-a 递增式更新,对/etc/exports 增加或修改的部分进行挂载和卸载
-i<文件> 指定配置文件
-r 更新配置,重新读取/etc/exports
-u 卸载指定目录
-o 使用指定参数
-v 显示共享详细情况
4、本机验证nfs服务
mount -t nfs -o nolock localhost:/nfs_root /mnt
#如果出现选项错误,解决方法:kill 文件锁(lockd)或者mount -o nolock
nfs mount 默认选项包括文件锁,依赖于portmap提供的动态端口分配功能。
5、开发板
若在uboot下nfs下载文件出现error:cannot umount
解决方法:在/etc/hosts下添加一行
开发板ip nfs目录
例如:
192.168.1.210 nfs_root
注意设置
setenv serverip //ubuntu ip
setenv ipaddr //开发板ip
setenv bootargs root=/dev/nfs nfsroot=192.168.1.110:/nfs_root, nolock rw ip=192.168.2.210
这样可以将linux下交叉编译好的应用程序,放在arm开发板上运行。