天天看点

虚拟机ubuntu10.04挂载nfs

一、环境

        虚拟机:VMware 7.0

        Linux系统:Ubuntu10.04

        PC机操作系统:WindowsXP

        客户机端 :ARM9开发板(freescale iMx27)

二、安装NFS服务器程序

       apt-get install nfs-kernel-server

       apt-get install nfs-common

       也可以使用Synaptic(新立得)软件包管理器安装,搜索“nfs”,选择软件包"nfs-kernel- server"项进行安装即可,安装过程中默认启动SUNRPC服务和nfs服务,并创建/etc/exports和、etc /default/nfs-kernel-server配置文件,等待用户完成nfs安装后,配置将要共享的资源,可以使用netstat -tl命令检查nfs端口是否已经打开;

三、 配置portmap

方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.

方法2: $ sudo dpkg-reconfigure portmap , 对Should portmap be bound to the loopback address? 选N.

配置/etc/hosts.deny

(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:

### NFS DAEMONS

portmap:ALL

lockd:ALL

mountd:ALL

rquotad:ALL

statd:ALL

配 置/etc/hosts.allow

允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.197开头的主机(连 接到NFS服务器上),也可以指定特定的IP地址。参看man页 hosts_access(5), hosts_options(5)。加入:

### NFS DAEMONS

portmap: 10.176.28.

lockd: 10.176.28.

rquotad: 10.176.28.

mountd: 10.176.28.

statd: 10.176.28.

/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似"mask"的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问.

运行 $ sudo /etc/init.d/portmap restart 重启portmap daemon.

配置/etc/exports

NFS挂载目录及权限由/etc/exports文件定义

比如我要将将我的home目录中的/home/wjd/qte目录让10.176.28.*的IP共享, 则在该文件末尾添加下列语句:

          /home/wjd/work    10.176.28.* (rw,sync,no_root_squash)

10.176.28.* 网段内的NFS客户端能够共享NFS服务器/home/wjd/work目录内容.且有读,写权限, 并且该用户进入/home/zp/share目录后的身份为root

最好加上sync, 否则 $ sudo exportfs -r 时会给出警告, sync是NFS的默认选项.

(运行 $ showmount -e 查看NFS server的export list.

若更改了/etc/exports, 运行 $ sudo exportfs -r 更新

运行 $ sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务)

四.配置IP地址

1.配置主机IP地址:将PC主机IP地址设置为静态IP:10.176.28.249 Mask:255.255.255.0;Gateway:10.176.28.1

2.配置VMware:

将VMware的网络连接设置成桥接方式, 在VMware->Settings->Network Adapter->bridged,选上。Device status的连接全部选上。

3.配置Ubuntu

将Ubuntu也设置成静态IP,IP地址与主机PC在同一个网段内,为:10.176.28.248

4、配置开发板IP地址

开发板IP地址设置为:10.176.28.247,与主机PC、Ubuntu都在同一网段内

测试一下,相互ping一下,看网络是否连通

五、测试nfs

1、Ubuntu本机测试

#sudo mount 10.176.28.248:/home/wjd/work /mnt/nfs

2、开发板测试

#mount -t nfs -o nolock 10.176.28.248:/home/wjd/work /mnt/nfs

若出现错误为:

  portmap: server localhost not responding, timed out

 解决办法:

  mount -t nfs -o nolock node1:/public /public

 即增加-o nolock参数,原因:

 Unfsd doesn't support NLM locking, and it's causing the lockd daemon to be started (which again requires the portmapper to be installed etc.)

继续阅读