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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章