# apt-get install nfs-kernel-server
2. 添加nfs需要挂载的文件系统目录
cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/home/yanghaibing/mmp3_q7/from_marvell/sw/M5.1.12.2.2/rootnfs *(rw,sync,no_root_squash)
3. 重启nfs服务
# service nfs-kernel-server restart
* Stopping NFS kernel daemon [ OK ]
* Unexporting directories for NFS kernel daemon... [ OK ]
* Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/yanghaibing/mmp3_q7/from_marvell/sw/M5.1.12.2.2/rootnfs".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
[ OK ]
* Starting NFS kernel daemon [ OK ]
4. 本地测试挂载nfs
#sudo mount -t nfs 10.20.112.20:/home/yanghaibing/mmp3_q7/from_marvell/sw/M5.1.12.2.2/rootnfs /home/yanghaibing/mmp3_q7/from_marvell/sw/M5.1.12.2.2/test_nfs
#ls test_nfs/
bin boot dev download etc home lib media mnt opt proc root run sbin selinux srv sys tmp usr var
这样服务就搭建好了,下面开始让单板挂载文件系统把!
5. 确认单板nfs及nfsroot服务已经启动
# menuconfig
CONFIG_ROOT_NFS=y
6. 设置nfs静态ip地址和server的ip地址
原先的CMDLINE为:CONFIG_CMDLINE="console=ttyS2,115200 panic_Debug rootdelay=5 root=/dev/mmcblk0p2 init='sbin/init -v' consoleblank=0 reserve_pmem=0x8000000 ip=off mac=6e:ee:2d:06:a1:1d fb_share"
将它修改为:
CONFIG_CMDLINE="console=ttyS2,115200 panic_Debug rootdelay=5 root=/dev/nfs nfsroot=10.20.112.20:/home/yanghaibing/mmp3_q7/from_marvell/sw/M5.1.12.2.2/rootnfs init='sbin/init -v' consoleblank=0 reserve_pmem=0x8000000 ip=10.20.112.40:10.20.112.20:10.20.112.254:255.255.255.0:marvell_pxa2128:eth0:off mac=6e:ee:2d:06:a1:1d fb_share"
当然您也可以使用DHCP来在kernel中自动获取IP地址,只要开启相应的服务即可.
[ 3.915802] ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 4.360260] pxa-otg pxa-otg: change from state undefined to b_peripheral
[ 6.342651] gpio 87 request failed
[ 6.346191] eth0: link up, 100 Mb/s, full duplex, flow control enabled
[ 6.353729] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 6.375915] Sending DHCP requests ...
[ 21.344665] ... timed out!
[ 89.331787] IP-Config: Reopening network devices...
[ 89.430572] phyctrl reg value: 0x0
[ 89.689270] ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 91.321258] eth0: link up, 100 Mb/s, full duplex, flow control disabled
[ 91.329895] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 91.352508] Sending DHCP requests ., OK
[ 91.438385] IP-Config: Got DHCP answer from 0.0.0.0, my address is 10.20.112.40
[ 91.447418] IP-Config: Complete:
[ 91.450744] device=eth0, addr=10.20.112.40, mask=255.255.255.0, gw=10.20.112.254,
[ 91.458801] host=10.20.112.40, domain=hoperun.com, nis-domain=(none),
[ 91.465942] bootserver=0.0.0.0, rootserver=0.0.0.0, rootpath=
--------------------------------------------------------------------------------------------------above OK
[ 3.845397] ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 4.344848] pxa-otg pxa-otg: change from state undefined to b_peripheral
[ 123.868164] Sending DHCP requests ...... timed out!
[ 195.463806] IP-Config: Reopening network devices...
[ 195.814117] ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 204.210205] eth0: link up, 100 Mb/s, full duplex, flow control enabled
[ 204.220275] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 204.243164] Sending DHCP requests ...
[ 216.954071] ... timed out!
[ 279.229553] IP-Config: Auto-configuration of network failed.
------------------------------------------------------------------------------------------------above Fail!
这时内核卡死,系统死无法启动(注: 实际上内核并没有卡死,只是一直在重试,等达到重试次数后会弹出超时,这个时间大约在两分钟,然后打出失败的信息,然后continue kernel's boot process),这个dhcp也有可能是成功的,只要dhcp server确实工作,以及你的网卡驱动OK,其他情况下当然就会失败了,我做的pxa2128平台集成的网卡dhcp时间大约是90s成功。
那么今天在这里我们就讲述一下这个ip参数的问题。
ip参数的格式为 ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
client-ip: 你正在使用的这块板子,你要为它设置的ip
server-ip: 提供nfs服务的服务器的ip地址。如不需要NFS服务于板子,则此项可以空置
gw-ip: 网关的ip地址,如果nfs与目标板在同一个网段内,则此项可以空置
netmask: 子网掩码,如此项为空,则子网掩码为默认值255.255.255.0
hostname: 你希望给目标板设置的主机名,在linux的shell中的如bash,命令行最开始有一个形如 blacksword@laptop:~ $ 这样的一个提示符,blacksword指当前的用户,而laptop就是一个hostname. 此项可以留空
device: 如果目标板上仅一个网卡,且只接了一个PHY,同时电路的设计没有将PHY拉出两个地址来,则此项为空。 如果不指有一个网卡,则可以指定要设置的ip地址是作用于哪一个网卡的。 如指定给第一块网卡,则该参数为eth0. 第二块为eth1,依此类推。
autoconf:
自动配置未明确指定参数的方式,可以是dhcp, rarp, bootp。如果不希望使用自动配置则可以使用off值来关闭 autoconf参数可以独立作用于ip参数,如ip=dhcp即表示由dhcp服务器给内核的ip参数提供所有数据。 ip=off则表示所有参数都不配置,留待系统启动进行配置。
最稳妥而简化的指定静态ip的方法为 ip=<clinet-ip>:::::eth0:off 请注意中间冒号的个数。
其他各项可以根据自己的实际情况来指定相应的值。