nfs原理是通过网络,将远程主机共享的文件系统,挂载到本机。Ubuntu 12.04上默认是没有安装NFS服务器的,首先要安装NFS服务程序:
先执行 # apt-get update
然后执行 # sudo apt-get install nfs-kernel-server
(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap) 这样,宿主机就相当于NFS Server。
在终端下用 # vi /etc/exports
打开exports文件。
如果你没有配置过这个文件的话此文件应该是空的。
在开始部分写入 /home/topeet/targetNFS/ * (rw,sync,no_root_squash)
/home/topeet/targetNFS/
-- 与客户机共享的目录,在这里我的共享目录为 /home/topeet/targetNFS/;
其中:
*
-- 表示允许任意用户使用,也可以使用具体IP;
(rw,sync,no_root_squash) -- rw
,挂载此目录的客户机对此目录有读写权利;sync
,……;no_root_squash
,挂载此目录的客户机享有主机root的权利;
我是将主机的根目录设置为共享目录 / *(rw,sync,no_root_squash)
OK,保存,退出。
修改完成之后输入:# exportfs –rv
来使配置文件生效
———————
/etc/init.d/nfs-kernel-server restart
/etc/init.d/portmap restart
现在可以在本机上试一下:
#sudo mount -t nfs localhost:/home/kevin /mnt
注:localhost为本机linux的IP地址
这样就把共享目录挂到了/mnt目录,取消挂载用:
#sudo umount /mnt
如果用在嵌入式设备上挂载,要加上参数-o nolock
我在开发板上使用的挂载命令:
mount -t nfs -o nolock 192.168.1.8:/home/kevin /mnt