Packaging and unpacking of [android]system.img file

Two formats of 1: system.img

system2_0.img: Linux rev 1.0 ext4 filesystem data, UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (extents) (large files)

system1_0.img: Android sparse image, version: 1.0, Total of 393216 4096-byte output blocks in 1765 input chunks.

//The above two formats are respectively:  
ext4 filesystem data
Android sparse image

2: mutual conversion tool of two formats

//sparse image is converted to the raw image of ext4
Usage: simg2img <sparse_image_files> <raw_image_file>  

//Raw image to sparse image of ext4
Usage: img2simg <raw_image_file> <sparse_image_file> [<block_size>]

The repackaging process of 3:system.img file

The overall idea is to mount the system.img image, then modify it, and complete the modification to pack it with the command of "make" ext4fs.

1: first convert the system.img file to the raw image file of ext4 (as long as the system.img in this format can be mounted)

2: then mount system.img
sudo  mount system.img /mnt/system

3: then modify the files in the directory / mnt/system according to your own needs

4: REPACK
sudo make_ext4fs -s -l 3096M   new.img /mnt/system

5: the repackaged file new.img is in the sparse image format, so it needs to be converted to the raw image of ext4.
 sim2img new.img system.img

6: so far, the process of modifying system.img and repacking is completed.

4: packaging and unpacking process of recovery.img

http://rex-shen.net/android-unpackpack-factory-images/

Unpacking of 6: boot.img file

#Operation command
mkdir boot  &&  cd boot
abooting -x  ../boot.img
#Get these three files: bootimg.cfg initrd.img zimage

#Unpacking of initrd.img file
file initrd.img  
initrd.img: gzip compressed data, from Unix #You can see that it is a gzip compressed file

#Here is the command to unzip the initrd.img file
mkdir initrd
cd initrd
cat ../initrd.img | gunzip | cpio -vid
#After unzipping initrd.img above, you can see a lot of files

#After the above editing, the repackaging command is as follows
cd initrd
find . | cpio --create --format='newc' | gzip > ../myinitd.img


#New write package boot.img
abootimg --create myboot.img -f bootimg.cfg -k zImage -r myinitrd.img


#The following command prints out the config information in the myboot.img file
 abootimg -i myboot.img 

5: Android development tools included in Debian system

#Installation command
sudo apt-get install  android-tools-adb android-tools-fastboot android-tools-fsutils abootimg

#Purpose of each tool, install as required
android-tools-adb
    Android Debug Bridge CLI tool

android-tools-fastboot
    Android Fastboot protocol CLI tool

android-tools-fsutils
    Android ext4 utilities with sparse support

abootimg
    Tool to read/write/update android boot images

 

Keywords: Android sudo Linux Unix

Added by artfuldrone on Thu, 31 Oct 2019 22:08:04 +0200