九,Linux-3.19内核支持挂载NFS文件系统

╄→尐↘猪︶ㄣ 提交于 2020-12-28 08:02:30

文档时间:2018-08-25

交叉编译器:arm-linux-gcc-4.3.2

Ubuntu版本:16.04

kernel版本:linux-3.19

 

一,在 Ubuntu 上安装配置 NFS

1),安装 NFS

输入命令 sudo apt-get install nfs-kernel-server 安装 nfs-kernel-server:

输入命令  sudo apt-get install nfs-common 安装 nfs-common 这是挂载 nfs目录所需要的:

2),建立共享工作目录

输入命令:

/home/aaron/work
mkdir nfs_root        //建立工作目录
chmod 777 nfs_root    //修改nfs_root权限

 把制作好的根文件系统 fs_new 拷贝到 nfs_root 目录下

3),配置 NFS

打开 /etc/exports,添加如下内容:

/home/aaron/work/nfs_root *(rw,sync,no_root_squash,no_subtree_check)

* : 允许所有的网段访问

rw : 挂接此目录的客户端对该目录具有读写权限

sync :资料同步

no_root_squash :root 用户对文件目录具有完全访问权限

no_subtree_check :不检查父目录的权限

配置完成后,重启 NFS 服务:sudo /etc/init.d/nfs-kernel-server restart

查看是否启动成功:showmount -e

如上图所示表示重启成功

4),验证

在 uboot 终端输入命令 nfs 32000000 192.168.2.110:/home/aaron/work/kernel/linux-3.19/arch/arm/boot/uImage 下载 uImage

下载成功

也可以通过在服务端挂载根文件系统来验证:

sudo mount -t nfs 192.168.2.110:/home/aaron/work/nfsroot/fs_new /mnt/

在服务端/mnt/目录下可以查看挂载到的文件系统

 

2,目标板通过 NFS 挂接根文件系统

(前提是内核已经支持网卡驱动,并且和服务端之间能够 ping 通,如果未移植 DM9000 驱动,可以参考:https://www.cnblogs.com/zhyy-mango/p/9527951.html)

1),目标板文件系统启动之后去挂载

命令如下:mount -t nfs -o nolock 192.168.2.110:/home/aaron/work/nfsroot/fs_new /mnt

2),修改 bootargs 直接从 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命令格式
NFS 命令格式

 然后根据nfs命令格式,具体格式解析要看nfs命令介绍:

nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]  ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

在 uboot 终端,输入以下命令来设置 bootargs:

set bootargs noinitrd root=/dev/nfs nfsroot=192.168.2.110:/home/aaron/work/nfs_root/fs_new/ ip=192.168.2.90:192.168.2.110:192.168.2.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0,115200

 然后 boot 启动,当文件系统启动后,就会与服务端共享 fs_new 目录下的东西

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!