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

文档时间: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:

696a4693549dbeaad0c980b3fda17640.png

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

2b76d637beced7fd1daaa243c471440b.png

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

0e9c1190bf20d789692c41c756d8eef4.png

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

077e92cfd7746fe8bb9f476f54703c73.png

如上图所示表示重启成功

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命令:

b3d90343bef24d96fa1a4a9d7e9aa1410b6.jpg

810b56f628fb8a096b725a774ebf679b29a.jpg

root=/dev/nfs

Thisis 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=[:][,]

If the `nfsroot'parameter is NOT given on the command line,

the default "/tftpboot/%s"will be used.Specifies the IP address of the NFS server.

Thedefault address is determined by the `ip'parameter

(see below). This parameter allows the use of different

serversforIP autoconfiguration and NFS. Name of the directory on the server to mount asroot.

If thereis a "%s" token in the string, it will be

replaced by the ASCII-representation of the client's

IP address.Standard NFS options. All options are separated by commas.

The following defaults are used:

port= asgiven by server portmap daemon

rsize= 4096wsize= 4096timeo= 7retrans= 3acregmin= 3acregmax= 60acdirmin= 30acdirmax= 60flags=hard, nointr, noposix, cto, ac

ip=::::::This parameter tells the kernel how to configure IP addresses of devices

and also how tosetup 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.

Ifthis parameter is missing fromthe kernel command line, all fields are

assumed to be empty, and the defaults mentioned below apply. In generalthis means that the kernel tries to configure everything usingautoconfiguration.

The parameter can appear alone as the value to the `ip' parameter (without all the ':' characters before) in which case auto-configurationisused.IP address of the client.

Default: Determinedusingautoconfiguration. IP address of the NFS server. If RARP isused to determine

the client address andthis parameter isNOT empty only

repliesfromthe specified server are accepted.

Only requiredfor for NFS root. That isautoconfiguration

will not be triggeredif it is missing and NFS root isnotinoperation.

Default: Determinedusingautoconfiguration.

The address of the autoconfiguration serverisused. IP address of a gateway if the server ison a different subnet.

Default: Determinedusingautoconfiguration. Netmask for local network interface. If unspecified

the netmaskis derived fromthe client IP address assuming

classful addressing.

Default: Determinedusingautoconfiguration.Name of the client. May be supplied by autoconfiguration,

but its absence will not trigger autoconfiguration.

Default: Client IP addressis used inASCII notation.Name of network device to use.

Default: If the host only has one device, itisused.

Otherwise the deviceis determined usingautoconfiguration. Thisisdone by sending

autoconfiguration requestsoutof all devices,

andusingthe device that received the first reply. Method to use for autoconfiguration. In the caseof options

which specify multiple autoconfiguration protocols,

requests are sentusingall protocols, and the first one

to replyisused.

Only autoconfiguration protocols that have been compiled

into the kernel will be used, regardless of the value ofthisoption.

off or none: don't use autoconfiguration (default)

on or any: use any protocol available inthe kernel

dhcp: use DHCP

bootp: use BOOTP

rarp: use RARP

both: use both BOOTP and RARP but not DHCP

(old option keptforbackwards compatibility)

Default: any

nfs命令格式

NFS 命令格式

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

nfsroot=[:][,] ip=::::::

在 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 目录下的东西

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值