There are many ways to extract the Android file system. Today I will explain how to extract the file system from the source code completed by make.
In the compiled android source code directory, the file system is stored in the source/out/target/product/generic/directory/
1. Structure of the Android File System
After the Android source code is compiled, the system. img, ramdisk. img, and userdata. img image files are obtained. Ramdisk. img is the file system of emulator. img includes the main packages, libraries, and other files, userdata. img includes some user data. After the emulator loads these three image files, it loads system and userdata to the system and userdata directories in the ramdisk file system respectively. Therefore, we can copy all the files in ramdisk. img and decompress system. img and userdata. img to the system and userdata directories in the ramdisk file system.
2. Separate the Android File System
The system. img, ramdisk. img, and userdata. img image files are packaged using cpio and compressed using gzip. You can run the file command to verify that:
Root @ linux-home :~ /Kernel/out/target/product/generic # file ramdisk. img
Ramdisk. img: gzip compressed data, from Unix
After the Android source code is compiled, in addition to system. img and userdata. img, the system and userdata folders are generated, so you do not need to decompress them. After the Android source code is compiled, the root folder is generated. In fact, the files under root are the same as those in ramdisk. img. But here we will introduce how to decompress ramdisk. img:
Copy ramdisk.imgto another directory, change its name to ramdisk.img.gz, and decompress it with the gunzip command. The operations are as follows:
// Copy ramdisk to the current working directory
Root @ linux-home :~ # Cp kernel/out/target/product/generic/ramdisk. img ./
Root @ linux-home :~ # Ls
Android2.3.6-source.tar.bz2 Documents overview.png qt-book-examples.tar.gz
Android_fs_m.tar.bz2 Downloads Pictures ramdisk. img
Bin kernel Public Templates
Desktop Music qt-book Videos
// Name it ramdisk.img.gz
Root @ linux-home :~ # Mv ramdisk. img ramdisk.img.gz
// Decompress the package with gunzip
Root @ linux-home :~ # Gunzip ramdisk.img.gz
Next, create a folder named ramdisk and enter. Enter the following command:
Cpio-I-F ../ramdisk. img
Then ls
The process is as follows:
Root @ linux-home :~ # Cd ramdisk
Root @ linux-home :~ /Ramdisk # ls
Root @ linux-home :~ /Ramdisk # cpio-I-F ../ramdisk. img
456 blocks
Root @ linux-home :~ /Ramdisk # ls
Data dev init. goldfish. rc proc sys ueventd. goldfish. rc
Default. prop init. rc sbin system ueventd. rc
Now we can see the content of the file system.
Finally, copy the files in system and userdata generated after compiling the Android source code to ramdisk/system and ramdisk/userdata. In this way, a file system is obtained. You can mount the file system using nfs or other methods.
Author Ren jianmeng