[xhr4412][extension 2] NFS & NFS rootfs


   目前 xhr4412 可以 ping 通外网,说明网络配置已经成功,但是根文件系统在开发板的 emmc 中,这非常不方便,所以首先将 xhr4412 调试到可以挂载 nfs 文件系统,再进一步直接使用 nfs 的根文件系统。

一、NFS

1. install nfs

  • sudo apt-get update
  • sudo apt-get install nfs-kernel-server

(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap) 这样,宿主机就相当于NFS Server。

2. config nfs

  • 修改配置文件 /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/xhr/iTop4412/xhr4412/rootfs/system *(rw, sync, no_root_squash)
/home/xhr/iTop4412/xhr4412/rootfs/system *(rw,sync,no_root_squash) # no space
  • * – 表示允许任意用户使用,也可以使用具体IP;
  • rw – 挂载此目录的客户机对此目录有读写权利;
  • sync – ……;
  • no_root_squash – 挂载此目录的客户机享有主机root的权利;

3. restart nfs

3.1 exportfs

  • -a 全部挂载或者全部卸载
  • -r 重新挂载
  • -u 卸载某一个目录
  • -v 显示共享目录

不重启 nfs,便可使上面修改的 /etc/exports

sudo exportfs -arv

不过尝试了一下,好像没成功,语法错误?? = = ||

xhr@ubuntu:~/iTop4412/xhr4412/rootfs/system$ exportfs -arv
exportfs: /etc/exports:2: syntax error: bad option list
exportfs: No file systems exported!
exportfs: could not open /var/lib/nfs/.etab.lock for locking: errno 13 (Permission denied)
exportfs: can't lock /var/lib/nfs/etab for writing
xhr@ubuntu:~/iTop4412/xhr4412/rootfs/system$ sudo exportfs -arv
exportfs: /etc/exports:2: syntax error: bad option list
exportfs: No file systems exported!
xhr@ubuntu:~/iTop4412/xhr4412/rootfs/system$

3.2 restart

  • /etc/init.d/nfs-kernel-server restart
  • /etc/init.d/portmap restart 这条似乎是多余的

结果出现这个问题:

在这里插入图片描述

   经过一番搜索,原来是因为 /etc/exports 的格式有些问题,括号里的逗号不能有空格。。。看来前面那个 syntax error 指的就是这个。我还以为是命令的语法有错误。。

   果然,删掉空格就可以使用 3.1 的命令了。

4. test on local

  • sudo mount -t nfs localhost:/home/xhr/iTop4412/xhr4412/rootfs/system /mnt

注:localhost为本机linux的IP地址

这样就把共享目录挂到了/mnt目录,取消挂载用:
sudo umount /mnt

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

我在开发板上使用的挂载命令:

mount -t nfs -o nolock 192.168.177.128:/home/xhr/iTop4412/xhr4412/rootfs/system /mnt

4.1 error

mount.nfs: requested NFS version or transport protocol is not supported

  • /etc/init.d/nfs-kernel-server restart 还是需要 restart 一下。

5. test on xhr4412

  • mount -t nfs -o nolock 192.168.177.128:/home/xhr/iTop4412/xhr4412/rootfs/system /mnt

   进入 /mnt 目录,就可以看到 Ubuntu 中一模一样的文件了,以后就方便多了。

二、NFS rootfs

   为了更加方便调试,并不直接使用挂载的方式使用 nfs,而是直接将 nfs 作为根文件系统使用。

1. dependence

  • 确保linux内核配置的时候配置上了 Root file system on NFS 这一项,也就是 CONFIG_ROOT_NFS,它依赖于 IP_PNP
  • 当没有使用 ramdisk 根文件系统的时候,则需要使用 noinitrd 这个参数,所以用 nfs 启动根文件系统则必须要加上这个参数
  • root=/dev/nfs,在文件系统为基于 nfs 的文件系统时使用,指定 root=/dev/nfs 之后还需要指定 nfsroot=serveri:nfs_dir ,即指明文件系统存在在哪个主机的哪个目录下
  • ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf
    • client-ip 开发板的 IP 地址
    • server-ip nfs 文件目录所在的 IP 地址
    • gw-ip 网关的地址 netmask 子网掩码
    • hostname 主机名(一般都省略)
    • device 网卡名称(如 eth0
    • autoconf 自动配置

下面为一条bootargs的例子:
setenv bootargs mem=128M console=ttyS0o,115200n8 root=/dev/nfs nfsroot=host_ip:mount_dir,nolock rw noinitrd ip=192.168.0.8:192.168.0.2:192.168.0.1:255.255.255.0::eth0:off
其中的mem和console参数需要根据具体板子的配置给出相应配置

2. xhr4412

kernel 官方文档:

  • Documentation/admin-guide/nfs/nfsroot.rst

   官方文档已经写的很清楚了,不过官方文档没有给出一个选项的设置,真的太坑了,搞了挺长时间才谷歌到,应该是 nfs client 和 server 的版本不一致?猜的,可能是这样的。

   需要指定 nfsvers=3,才挂载成功。

修改 arch/arm/boot/dts/exynos4412-xhr-elite.dts

	chosen {
		bootargs = "root=/dev/nfs rw nfsroot=192.168.177.128:/home/xhr/iTop4412/xhr4412/rootfs/system,nfsvers=3 ip=192.168.177.132:192.168.177.128:192.168.177.2:255.255.255.0::eth0:off:192.168.177.2:114.114.114.114:192.168.177.2 init=/linuxrc rootdelay=1 rootwait nfsrootdebug";
		stdout-path = "serial2:460800n8";
	};

   由于 NFS 作为根文件系统启动时,网卡已经配置完成,所以不在启动文件系统后在配置网卡,这里修改一下开机脚本 /etc/init.d/rcS,来自动判断是从 NFS 启动还是 EMMC 启动。

cmdline=$(cat /proc/cmdline)
nfsdev="/dev/nfs"

ret=$(echo $cmdline | grep "$nfsdev")

if [[ "$ret" != "" ]]
then    # nfs
        echo "boot from nfs root !"
else    # emmc
        ifconfig lo up
        ifconfig eth0 hw ether 08:90:90:90:90:90
        ifconfig eth0 192.168.177.132 netmask 255.255.255.0 up
        route add default gw 192.168.177.2
fi

三、BUG

   这里有发现一个 BUG,在 u-boot 中使用 fastboot 后,直接使用 boot 命令直接启动 kernel 的话,网卡无法正常工作。

   所以使用 fastboot 后,需要重新断电再启动 xhr4412。

   由于不太影响使用,就暂时不去探索为什么会有这样的 BUG。

reference

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值