下载代码仓储 https://android.googlesource.com/platform/system/extras:
git clone https://android.googlesource.com/platform/system/extras
选择对应的版本:
cd extras
git checkout android-4.1.1_r1
编译 simg2img:
cd ext4_utils
gcc -o simg2img -lz sparse_crc32.c simg2img.c
拆包 android 镜像文件:
cd ../../
./extras/ext4_utils/simg2img system.img system.raw.img
./extras/ext4_utils/simg2img userdata.img userdata.raw.img
通过 mount 挂载镜像( Mac osx 系统可以使用 Paragon's ExtFS ):
mkdir /mnt/my_system /mnt/my_userdata
mount -t ext4 -o loop userdata.raw.img /mnt/my_userdata
编译 make_ext4fs:
cd extras/ext4_utils
gcc -o make_ext4fs -lz make_ext4fs_main.c make_ext4fs.c ext4fixup.c ext4_utils.c allocate.c backed_block.c output_file.c contents.c extent.c indirect.c uuid.c sha1.c sparse_crc32.c wipe.c
重新打包镜像:
cd ../../
PATH="$PATH:$(pwd)/extras/ext4_utils/make_ext4fs" ./extras/ext4_utils/mkuserimg.sh -s /mnt/my_system_dir my_system.img ext4 /tmp 512M