NFS开发环境搭建

(测试环境Ubuntu14)

安装目标板挂载根文件系统的方法有两种(这里所说的服务端就是ubuntu,Ubuntu已经成功安装了nfs服务,并且保证服务端与目标板ping 通)

(注意开发板的linux要设置为nfs启动和配置nfs支持)
第一种:等待开发板启动之后去挂载,此时文件系统从Flash中启动,然后手动的通过命令去挂载服务端的文件系统。

一、安装

sudo apt-get install nfs-kernel-server
(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)
即分别安装:
1.服务器端:sudo apt-get install portmap
2.服务器端:sudo apt-get install nfs-kernel-server
3.客户端:sudo apt-get install nfs-common

二、配置nfs
(1) sudo vim /etc/exports     
     在末尾一行加入

    /home/book/work *(rw,sync,no_root_squash,no_subtree_check)

    或/home/book/work *(rw,sync,no_root_squash)

含义:
/home/book/work 与nfs服务客户端共享的目录,
*:允许所有的网段访问,也可以使用具体的IP
rw:挂接此目录的客户端对该共享目录具有读写权限
sync:资料同步写入内存和硬盘
no_root_squash:root用户具有对根目录的完全管理访问权限。
no_subtree_check:不检查父目录的权限。更多的参数说明我在文章下面贴出来了!

(2) 设置 /home/book/work目录权限
     sudo chmod 777 work -R

(3) 重启服务:
    #sudo /etc/init.d/portmap restart <---重启portmap,
    #sudo /etc/init.d/nfs-kernel-server restart <---重启nfs服务
    #showmount -e <---显示共享出的目录

注意:nfs是一个RPC程序,使用它前,经常要映射好端口,通过portmap设定,不过我这里没设。
**重启nfs服务有2种方式:
book@ubuntu:/mnt$ sudo /etc/init.d/nfs-kernel-server restart
* Stopping NFS kernel daemon [ OK ] 
* Unexporting directories for NFS kernel daemon... [ OK ] 
* Exporting directories for NFS kernel daemon... [ OK ] 
* Starting NFS kernel daemon [ OK ] 

book@ubuntu:/mnt$ sudo service nfs-kernel-server restart 
* Stopping NFS kernel daemon [ OK ] 
* Unexporting directories for NFS kernel daemon... [ OK ] 
* Exporting directories for NFS kernel daemon... [ OK ] 
* Starting NFS kernel daemon [ OK ]

(4) 本机上试一下:

sudo mount -t nfs localhost:/home/book/work /mnt

sudo mount 127.0.0.1:/home/book/work /mnt
注:localhost为本机linux的IP地址

这样就把共享目录挂到了/mnt目录。


(5)  取消挂载用:

sudo umount /mnt

(6) 开发板测试

如果用在嵌入式设备上挂载,要加上参数-o nolock

mount -t nfs -o nolock 192.168.1.8:/home/book/work /mnt

============================================================

第二种方法:直接从nfs启动,这样服务端所生成的目标文件,目标端可以直接执行,不需要挂载
 这种做法就是在u-boot启动之后,设置nfs挂载参数。首先必须掌握nfs命令。

root=/dev/nfs

  This is necessary to enable the pseudo-NFS-device. Note that it's not a
  real device but just a synonym to tell the kernel to use NFS instead of
  a real device.


nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]

  If the `nfsroot' parameter is NOT given on the command line,
  the default "/tftpboot/%s" will be used.

  <server-ip>    Specifies the IP address of the NFS server.
        The default address is determined by the `ip' parameter
        (see below). This parameter allows the use of different
        servers for IP autoconfiguration and NFS.

  <root-dir>    Name of the directory on the server to mount as root.
        If there is a "%s" token in the string, it will be
        replaced by the ASCII-representation of the client's
        IP address.

  <nfs-options>    Standard NFS options. All options are separated by commas.
        The following defaults are used:
            port        = as given by server portmap daemon
            rsize        = 4096
            wsize        = 4096
            timeo        = 7
            retrans        = 3
            acregmin    = 3
            acregmax    = 60
            acdirmin    = 30
            acdirmax    = 60
            flags        = hard, nointr, noposix, cto, ac


ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

  This parameter tells the kernel how to configure IP addresses of devices
  and also how to set up the IP routing table. It was originally called
  `nfsaddrs', but now the boot-time IP configuration works independently of
  NFS, so it was renamed to `ip' and the old name remained as an alias for
  compatibility reasons.

  If this parameter is missing from the kernel command line, all fields are
  assumed to be empty, and the defaults mentioned below apply. In general
  this means that the kernel tries to configure everything using
  autoconfiguration.

  The <autoconf> parameter can appear alone as the value to the `ip'
  parameter (without all the ':' characters before) in which case auto-
  configuration is used.

  <client-ip>    IP address of the client.

          Default:  Determined using autoconfiguration.

  <server-ip>    IP address of the NFS server. If RARP is used to determine
        the client address and this parameter is NOT empty only
        replies from the specified server are accepted.

        Only required for for NFS root. That is autoconfiguration
        will not be triggered if it is missing and NFS root is not
        in operation.

        Default: Determined using autoconfiguration.
                 The address of the autoconfiguration server is used.

  <gw-ip>    IP address of a gateway if the server is on a different subnet.

        Default: Determined using autoconfiguration.

  <netmask>    Netmask for local network interface. If unspecified
        the netmask is derived from the client IP address assuming
        classful addressing.

        Default:  Determined using autoconfiguration.

  <hostname>    Name of the client. May be supplied by autoconfiguration,
          but its absence will not trigger autoconfiguration.

          Default: Client IP address is used in ASCII notation.

  <device>    Name of network device to use.

        Default: If the host only has one device, it is used.
             Otherwise the device is determined using
             autoconfiguration. This is done by sending
             autoconfiguration requests out of all devices,
             and using the device that received the first reply.

  <autoconf>    Method to use for autoconfiguration. In the case of options
                which specify multiple autoconfiguration protocols,
        requests are sent using all protocols, and the first one
        to reply is used.

        Only autoconfiguration protocols that have been compiled
        into the kernel will be used, regardless of the value of
        this option.

                  off or none: don't use autoconfiguration (default)
          on or any:   use any protocol available in the kernel
          dhcp:        use DHCP
          bootp:       use BOOTP
          rarp:        use RARP
          both:        use both BOOTP and RARP but not DHCP
                       (old option kept for backwards compatibility)

                Default: any

nfs命令格式
在u-boot界面,输入print就可以显示如下参数

bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0
然后根据nfs命令格式,具体格式解析要看nfs命令介绍。
nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]  ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
将启动参数设置为
set bootargs noinitrd root=/dev/nfs nfsroot=192.168.1.24:/home/linux/root_fs/first_fs/ ip=192.168.1.12:192.168.1.24:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0
当文件系统启动之后,服务器端的文件会共享过来


============================================================

apt-cache search nfs
nfs 30000000 192.168.1.8:/home/book/work/fs.yaffs2 

这和用tftp下载一样的效果









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值