sudo apt-get install nfs-kernel-server ;安装nfs
mkdir /root/nfs 建立一个nfs服务的专有的文件夹;
建立好文件夹后,接着执行命令:sudo gedit /etc/exports 配置nfs;
在文本的最后一行添加:
/root/nfs *(rw,sync,no_root_squash,no_subtree_check)
这一行的含义是:
/root/nfs:与nfs服务客户端共享的目录,这个路径必须和你前面设置的文件的路径一致!
*:允许所有的网段访问,也可以使用具体的IP
rw:挂接此目录的客户端对该共享目录具有读写权限
sync:资料同步写入内存和硬盘
no_root_squash:root用户具有对根目录的完全管理访问权限。
no_subtree_check:不检查父目录的权限。
sudo exportfs -r
修改完上述配置文件保存退出。
执行命令:service portmap restart 重启portmap 服务。
执行命令:sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务。
启用nfs服务需要虚拟机,开发板,主机以太网口处于同一网段,配置方法如下:
关闭主机和ubuntu的防火墙
修改主机本地连接即以太网口为静态ip:192.168.1.150
1、将虚拟机网络设置为桥接,在虚拟机网络设置中选择桥接到物理网卡,而非自动。
修改网络配置文件
ubuntu的eth0修改为静态ip,在interfaces中
eth0网络配置信息存储在/etc/network/interfaces 文件中
修改interfaces : gedit /etc/network/interfaces
修改内容为:
#interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface loinet loopback
# Theprimary network interface
auto eth0
ifaceeth0 inet static
address192.168.1.100
netmask255.255.255.0
gateway192.168.1.1
2、在静态ip下还要配置DNS服务器(Windows也是这么做的),DNS信息存储在/etc/resolv.conf 中,如果没有此文件则直接新建:gedit /etc/resolv.conf
修改内容为:
#Generated by NetworkManager
domainjiangnan.edu.cn
searchjiangnan.edu.cn
nameserver210.28.16.26
nameserver210.28.18.26
nameserver210.28.16.30
# NOTE:the libc resolver may not support more than 3 nameservers.
# Thenameservers listed below may not be recognized.
nameserver210.28.18.30
nameserver202.202.32.33
nameserver61.128.128.68
修改文件 hosts.allow
gedit/etc/hosts.allow
在行末添加
portmap:ALL:allow
lockd: ALL:allow
rquotad: ALL:allow
mountd: ALL:allow
statd: ALL:allow
修改文件hosts.deny
gedit /etc/hosts.deny
在行末添加
### NFSDAEMONS
portmap:ALL
lockd: ALL
mountd: ALL
rquotad:ALL
statd: ALL
重启ubuntu网络
sudo/etc/init.d/networking restart
在ubuntu和主机中分别
ping 192.168.1.100
ping 192.168.1.150
ping 192.168.1.230
如果都能ping通则成功
测试本机挂载:sudo mount -t nfs localhost:/root/ /root/nfs
卸载:umount /root/nfs
arm端挂载指令:
mount -t nfs -o intr,nolock,rsize=1024,wsize=1024 192.168.1.100:/root/nfs/mnt/nfs
umount /mnt/nfs
其中添加参数intr,nolock,rsize=1024,wsize=1024的原因可参考http://blog.csdn.net/wang_shuai_ww/article/details/12012723
192.168.1.100为虚拟机的ip
注:nfs只是一种文件目录共享模式,以本地方式进行访问。
开机自动挂载:
把上述指令mount -t nfs -o intr,nolock,rsize=1024,wsize=1024192.168.1.100:/root/nfs /mnt/nfs 写到/etc/rc.local 文件中
此时可能出现ubuntu无法上外网,解决方案为:
虚拟机选nat方式,删除interfaces里关于eth0的内容,networkmanager里设置为true使其接管网络,但同时nfs服务失效,重启网络sudo /etc/init.d/networkingrestart
然后reboot,就可以重新连上网。想重用nfs时,只需把eth0里的除了前三行全部删掉,虚拟机设置为桥接,重启网络然后重启ubuntu即可