android 镜像image解析(二)

尝试在本地环境上加载system.img userdata.img,然后对其进行修改,省去pack/unpack过程,提高效率。但是失败了,虽然失败了,但是还是学到了很多知识了,进行总结下:

Linux 命令:
File 相当强大的命令,可以对文件进行识别,从而进一步知道,接下来该干什么
对一个android db进行file android.db
android.db :SQLite 3.x database, user version 8 表明这是一个sqlite3的数据库

file setup.conf
setup.conf: ASCII text

file ./tmp/sdcard.img (对于avd中的sdcard,img进行file)
./tmp/sdcard.img: x86 boot sector, code offset 0x5a, OEM-ID "MSWIN4.1", sectors/cluster 4, Media descriptor 0xf8, sectors 1048576 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 2044, reserved3 0x800000, serial number 0xdeb2d05, label: "     SDCARD"
表明这是个fat文件系统的镜像,可以对其使用mount

Mount:
使用man mount 可以得到2000多页的帮助文档,足见其复杂性

简单来说:
不带参数使用:列出当前系统所有挂载的分区

带参数使用: mount –t fstype –o option device mount-point
-t指定文件系统类型 一般有 vfat ntfs ext2,3,4 iso9660(光盘镜像)
-o 表明可选项 常用的有loop(如果不是块设备,即是一个文件,那么这个选项是必须的),ro,rw(读写权限),remount, noatime,noatdirtime(性能相关,系统将不修改文件访问时间)
Device 块设备或者镜像文件
Mount-point:指定挂载点

如挂载一个sdcard.img
Mount –t vfat –o loop,rw,noatime sdcard.img sdcard-mnt-point
这样就能像访问文件夹一样访问image了


如果挂载后汉字文件显示乱码
-o iocharset=cp936


如此,是否可以挂载system.img 和 userdata.img?

File system.img
system.img: VMS Alpha executable
遗憾的是VMS Alpha executable 不是一个镜像文件,具体是什么不知道,但是从stackoverflow中得知,也许是一种经过转换的镜像文件,不能直接挂载,如果需要挂载,可能需要重新编译ubuntu内核,使其支持yaffs文件格式,以下是原文:


In Android file system, "system.img" and "userdata.img" are VMS Alpha executable. "system.img" and "userdata.img" have the contents of /system and /data directory on root file system. They are mapped on NAND devices with yaffs2 file system. Now, yaffs2 image file can not be mounted on linux PC. If you can, maybe you got some rom that not packed in yaffs2 file system. You can check those rom file by execute the command:

file <system.img/userdata.img>

If it show "VMS Alpha executable" then you can use "unyaffs" to extract it.”


Yes, they can be mounted. Under Ubuntu you can mount sdcard.img via vfat and system.img and userdata-qemu.img via yaffs2. See also: "Whats Android file system ??".

Note that the file system yaffs2 is not included in the standard Ubuntu kernel. Thus, in case of Ubuntu, you have to build your own kernel with yaffs2 support before you are able to mount the system.img and the userdata-qemu.img. Alternatively, you can also take a look at the yaffs2utils which allow you to extract files from yaffs2 images or to create new image files. The advantage is that you do not have to build your own kernel for using these tools.”

值得注意的是,从android2.3版本开始后,android默认的文件系统为ext4,之前版本为yaffs2。但是这样还是无法直接挂载,因为我认为这个镜像可能需要做某些转换才能在ubuntu下挂载。另外一点值得注意的是,没有规范规定android必须为ext4文件系统,这个是有设备厂商自定的,不过大部分可以认为是ext4,某些大厂商可能会改变文件系统(如三星)

从这方面来看,貌似是无法直接挂载system.img 和 userdata.img。只能解包打包了

Simg2img 这个是源码自带的工具out/host/linux-x86/bin
作用是将一个VMS Alpha executable文件转换成镜像文件,以便加载
用法很简单 simg2img src dst

打包使用 makext4fs 也是源码自带的 位置同上
make_ext4fs -s -l 512M -a system system.img system.img.raw
-s 表示去除分区中的空数据,也即生成的img为实际数据,而不是-l指定的大小
-l 表示分区大小,
-a 表示在android挂载点
system.img 为输出文件
system.img.raw 为源文件(可以是个目录,也可以是个镜像)

pack/unpack过程具体参考

http://blog.csdn.net/wutianyin222/article/details/7920617


My original intent was to have this package dependency-free, but as you can see, I did have to include Cygwin. Initially just for mkbootimg since the huaixzk standalone version wouldn't work (it wasn't loading the kernel as binary, thanks trevd); then I discovered that using the GNUWin32 cpio to unpack somehow didn't play nice with repacking the ramdisk in a usable state, so at that point I decided I might as well go Cygwin across the board. As it is, I've included the latest Cygwin-dependent executables and required libraries from their repos and built my own custom Cygwin image and ramdisk utilities built from the latest sources. Originally only for Google Pixel/Nexus/AOSP standard boot.img files, built-in support has now expanded to Android Verified Boot (AVBv1)/ChromeOS/SignBlob signed boot.img files, Barnes & Noble Nook "Green Loader" signed boot.img files, Samsung/Spreadtrum DHTB header signed boot.img files, the Samsung/Marvell PXA1088/1908 board boot.img variant (AOSP-PXA), Loki patched boot.img files, Sony SIN signed/packaged kernel.elf extraction, Sony ELF kernel.elf files, Intel OSIP Android image files, DENX U-Boot uImage files, Rockchip KRNL signed ramdisk image files, MTK headers for zImage/ramdisk, and LG Bump/Samsung SEAndroid footers for boot.img. The main advantage here is you don't need Cygwin shell or PERL scripts. Other guides exist but none of them are universal for target device, compression and/or developed for Windows, Android ARM/x86/MIPS + ARM64/x86_64/MIPS64, and now macOS. With this universality in mind I've automated the whole process with batch/shell scripts. My development work on my many projects comes out of my free time, so if you enjoy this project or anything else I've done on xda, please do hit the donate link from my profile. Thank you for your support!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值