通过wifi挂载Android文件系统

来源:互联网 发布:淘宝开店设置模板 编辑:程序博客网 时间:2024/05/16 04:51

通过wifi挂载Android文件系统

一、 步骤

1.       搭建NFS服务器

(1)       安装

# sudo apt-get install nfs-kernel-server

(2)       配置

# vi /etc/exports,添加一行:

            /share_path ip(rw,sync,no_root_squash)

           Eg.  /home/ubuntu/nfsroot 192.168.1.*(rw,sync,no_root_squash)

(3)       重启NFS

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

(4)       测试

# mount pc_ip:/share_path /mnt 或

# mount 127.0.0.1:/share_path  /mnt

2.       修改内核或init进程,使设备只运行shell,详见注1、2

3.       设备启动后,设置环境变量                                        

         #export PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin

           # exportLD_LIBRARY_PATH=/vendor/lib:/system/lib

4.       加载wifi驱动,并配置网络

# insmod /system/module/bcmdhd.ko "firmware_path=/system/etc/wifi/fw-bcmdhd.bin   nvram_path=/system/etc/wifi/nvram-bcmdhd.txt"

 

# chmod 4777 /system/bin/wpa_supplicant

# busybox ifconfig wlan0 192.168.1.199

# busybox route add default gw 192.168.1.1

# netcfg

5.       连接wifi,参见注3

# /system/bin/wpa_supplicant -B -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf

6.       挂载NFS

# busybox mount -t nfs -o nolock192.168.1.190:/home/ubuntu/nfsroot/ /mnt/nfs

7.       卸载已挂载的虚拟文件系统,并设置新的根目录

# umount /sys

# umount /proc

# umask 000

# cd /

# busybox chroot /mnt/nfs /system/bin/sh

8.       运行init

# ./init

二、可能问题

1. mount nfs时,提示no such device。

内核需配置nfs支持

2. mount nfs时。提示invalid argument

需要使用busybox mount。

3. 使用wpa_supplicant.conf连接wifi时,提示deamon错误

需要先挂载sys,proc,dev。

依赖的设备节点为/dev/urandom,/dev/null

4. 运行init时大量进程无法启动

修改/etc/exports加入no_root_squash字段,确保nfs客户端有写权限

 

三、注

注1:只运行shell,可修改内核,注释掉init执行代码,并添加执行shell的代码

Eg: + run_init_process("/system/bin/sh");

这种情况下,需要手动挂载sys和proc并手动创建相应设备节点

mount [-t vfstype] [-o options] device dir

注2:在init内挂载虚拟文件系统、fork shell进程后停止,修改init的main函数:

Mount函数传入参数注释:

(1)挂载类型

(2)挂载路径

(3)挂载设备

(4)指定文件系统的读写访问标志

(5)设备挂载选项(exp:”mode=0777”)

mount("proc","/proc", "proc", 0, NULL);

mount("sysfs","/sys", "sysfs", 0, NULL);

//以下是添加

   if ((pid = fork()) < 0) {

                 ERROR("forkfail\n");

    }

   if (!pid) {

             if (execl("/system/bin/sh","/system/bin/sh", (char *) NULL)) {

                            ERROR("shexec fail\n");

                            return-1;

             }

             ERROR("Data Call Should never gethere!\n");

    }else {

             if (execl("/sbin/ueventd","/sbin/ueventd", (char *) NULL)) {

                            ERROR("ueventexec fail\n");

                            return-1;

                   }

    }

         while(1);

 

注3:连接wifi使用的配置文件是/data/misc/wifi/wpa_supplicant.conf,里面需要有待连接wifi的参数。可从已连接过此wifi的设备提取wpa_supplicant.conf文件。内容:

ctrl_interface=wlan0

update_config=1

 

network={

         ssid="VANSTONE-RD"

         psk="van12345"

         key_mgmt=WPA-PSK

         priority=2

}

0 0
原创粉丝点击