android 挂载NFS教程

本文详细介绍了如何在Ubuntu上通过NFS作为Android设备的根文件系统,包括NFS服务器的搭建、内核镜像的构建、初始化参数的设置以及确保文件所有权的正确性等关键步骤。通过实例演示,提供了从理论到实践的操作指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0,在Ubuntu新建nfs目录:

#mkdir /home/shuimu/arm_project/rootfs

FORLINX_6410_yaffs2_v1.0.tgz复制到rootfs中,

解压当前文件夹#tar zxf FORLINX_6410_yaffs2_v1.0.tgz

1.烧写mmcubootzImage到开发板。

2,在ubuntu上安装nfs-server-kernal。编辑/etc/export文件,设置输出路径。启动nfs服务。

 安装:

   #sudo apt-get install portmap

   #sudo apt-get install nfs-kernel-server

   #sudo gedit /etc/exports

   在弹出的文本编辑器中编辑exports 文件,在最后一行添加:

   /forlinx *(rw,sync,no_root_squash)

 启动相关服务:

   #sudo /etc/init.d/portmap restart

   #sudo /etc/init.d/nfs-kernel-server restart

3,在uboot启动后,输入:

#setenv bootargs "root=/dev/nfs nfsroot=192.168.1.1:/home/shuimu/arm_project/rootfs ip=192.168.1.200:192.168.1.1:192.168.1.1:255.255.255.0:witech.com.cn:eth0:off console=ttySAC0,115200"

#saveenv

#printenv

#reset

NOTE

   192.168.1.1 PC Ubuntu IP

   192.168.1.200 开发板IP

   192.168.1.1 网关

   255.255.255.0 子网掩码

   saveenv(保存)

   printenv查看设置是否正确

   恢复nand flash启动:setenv bootargs root=/dev/mtdblock3 consle=/dev/ttySAC0,115200

#saveenv

#reset

 

 

Android 使用NFS喝Linux还是有点不同的,需要我们注意。

这里有一篇如何使用nfs作为根文件系统的文章,写的不错, 转载到这里了,看了这篇文章以后,根据自己的使用心得,把自己的使用方法也写了下来,供大家参考


[First written by Steve Guo, please keep the mark if forwarding.]Usually the Android uses YAFFS as rootfs and uses the mtd device as storage media, the bad blocks in the mtd device seldom cause YAFFS file system to work abnormally. if the Android uses NFS as the rootfs, there will not exist such problem. So here is the solution to use NFS as the rootfs of Android.
1.       Setup host machine as NFS server (I will use ubuntu 8.0.4 as an example.).

$ sudo apt-get install nfs-kernel-server portmap

$ sudo mkdir /nfsroot

$ sudo vim /etc/exports 

      Add one line in /etc/exports,
/nfsroot  192.168.1.101(rw,no_root_squash,sync)

Then restart NFS server. 
$ sudo /etc/init.d/nfs-kernel-server restart Here setups an NFS server which exports /nfsroot directory only to 192.168.1.101(Which is the default IP address of Android eth0).

2.       Build a Linux kernel image to use NFS as rootfs.
$make menuconfig

Modify the default setup. In "general setup" section, uncheck the "initial RAM filesystem and RAM disk(initramfs/initrd) support". In "file systems" section, check the "Network File Systems" and mark it as kernel built-in. In "boot options" section, add the kernel parameter "root=/dev/nfs nfsroot=192.168.1.100:/nfsroot init=/init". 192.168.1.100 is the IP address of host machine running NFS server. 
3.       Modify init program.

      To make log system work, in the device/system/init modify the device.c by change the statement '!strncmp(uevent->path,"/class/misc/",12) && !strncmp(name, "log_", 4) to '!strncmp(name, "log_", 4)'. 

4.       Modify init.rc config file.

      Comment out below statements

mount rootfs rootfs /ro remount

mount yaffs mtd@system /system

mount yaffs2 mtd@system /system ro remout

mount yaffs2 mtd@userdata /data nosuid nodev

mount yaffs2 mtd@cache /cache nosuid nodev

5.    Add the user id and group id used by android on the NFS server.

      Android does not use /ect/passwd file to record the user name and user id, it uses a fixed method to map the user name to user id through the head file device/include/private/android_filesystem_config.h, e.g. the user "system" has the user id of 1000.

      So to correctly set the file ownership(owner and group), the NFS server should have these users with correct user IDs. Such as system(1000). For ubuntu, you can call like this.

$sudo userdd -u 1000 android_system

      This step is not necessary. It only allows you to display a user name in the develop machine.
6.       Prepare the rootfs.

      Assume the built output of device lies in device/out/target/product/***/, which is called $OUTPUTDIR later. Do the follwings:

$cp -rf $OUTPUTDIR/root/* /nfsroot  

$cp -rf $OUTPUTDIR/system /nfsroot

$cp -rf $OUTPUTDIR/data /nfsroot


使用心得:

我在使用NFS过程中第二步骤与作者的不同,我是设置的Uboot的启动参数,没有像作者那样在linux内核 中固定参数,我在Uboot中设置的参数是这样的:


  setenv bootargs "root=/dev/nfs nfsroot=192.168.0.232:/forlinux/root ip=192.168.0.231:192.168.0.232:192.168.0.201:255.255.255.0:witech.com.cn:eth0ff init=/linuxrc console=ttySAC0,115200 "
saveenv

其中 192.168.0.232是主机IP(运行Ubuntu系统的PC),192.168.0.231是Android嵌入式设备的IP地址,在这里设定。192.168.0.201是我的网络的网关,当然这三个IP地址可以跟据你的当前网络情况来设置,不一定跟我的相同。

:/forlinux/root  是NFS开放的目录,里面存放着Android的文件系统,跟作者第一步骤中 /nfsroot  192.16 8.1.101(rw,no_root_squash,sync) 雷同,他开放的是 /nfsroot目录,我开放的是 /forlinux/root目录。


设定好参数后就可以顺利的挂载NFS文件系统了。

### 如何在 Android 系统中配置和使用 NFS 服务 #### 配置 NFS 客户端的基础环境 为了使 Android 设备能够作为 NFS 客户端运行,需要确保设备具备支持 NFS 的功能模块。通常情况下,Android 平台上的 NFS 支持依赖于 Linux 内核中的 NFS 模块以及相应的用户空间工具[^1]。 #### 启用 NFS 功能 启用 NFS 功能的第一步是在 Android 系统中加载必要的内核模块并安装对应的客户端软件包。如果目标设备未预装这些组件,则可以通过 ADB 或其他方式手动部署它们。具体操作如下: - **确认内核支持** 使用 `adb shell` 登录至 Android 终端,并执行命令检查是否存在 `/proc/filesystems` 中的 nfs 条目: ```bash cat /proc/filesystems | grep nfs ``` - **安装必要工具** 如果缺少相关工具(如 `mount.nfs`),可以尝试通过 BusyBox 工具集或其他第三方应用提供支持。BusyBox 是一种轻量级工具集合,它包含了大量标准 Unix 实用程序的小型版本,适用于嵌入式系统或资源受限场景下的开发调试工作[^3]。 #### 设置自动挂载脚本 对于频繁使用的远程共享目录来说,建议创建自动化挂载机制来简化日常维护流程。以下是基于 Android Shell 脚本实现的一个简单例子: ```bash #!/system/bin/sh # Define variables for server IP, export path and local mount point. SERVER_IP="192.168.x.y" EXPORT_PATH="/home/qnx/shared" MOUNT_POINT="/mnt/nfs" # Ensure the directory exists locally before attempting to mount. if [ ! -d "$MOUNT_POINT" ]; then mkdir $MOUNT_POINT fi # Perform actual mounting process with appropriate options set according to your needs. busybox mount -t nfs ${SERVER_IP}:${EXPORT_PATH} $MOUNT_POINT -o nolock,proto=tcp,port=2049,rsize=8192,wsize=8192,timeo=14,intr,bg,retry=5 ``` 上述脚本定义了一个基本框架用于连接指定地址上的 QNX 提供的服务实例[^2]。 #### 测试与验证 完成以上步骤之后,可通过简单的读写测试验证新建立起来的数据通道是否正常运作。例如,在已成功绑定的目标位置下新建文件或者复制已有文档过去查看反应情况如何。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值