How to properly unpack and repack Android system.img for SP Flash Tool

JVitor

Member
Dec 12, 2014
76
19
8
40
Notice: I am not an expert or developer. Just writing this to fill a gap on the subject.


Requirements:


1. x86 (32-bit) Ubuntu OS.


2. img-tools (attached or here); you may try these alternative packages of android-tools-fsutils specific for your system (but not tested or guaranteed bug free).


Installing Ubuntu


You can run Ubuntu either in trial mode or install the latest version inside or next to Windows (dual boot). For instructions and downloadable ISO files see:


https://technet.microsoft.com/en-us/magazine/gg309169.aspx


http://www.pcworld.com/article/2142325/install-ubuntu-and-keep-windows.html


https://help.ubuntu.com/community/WindowsDualBoot


http://www.ubuntu.com/download/desktop


Installing img-tools


Just unpack/extract the img-tools folder to any place in your Ubuntu desktop


Unpacking system.img from stock ROM


1. Move or copy system.img to the img-tools folder.


2. Right click anywhere inside the img-tools folder and select "Open in Terminal". This opens up a terminal window already inside the folder.


3. Type the following commands:


sudo su (it will ask for your password and give you root privileges)


mkdir sys (it will create the sys folder inside img-tools folder)


mkdir system_folder (it will create sys_folder inside the img-tools folder)


./simg2img system.img sys.raw (it will read system.img and write a raw ext4 image of it, the same from MTKDroid tools (system.ext4.img)


mount -t ext4 -o loop sys.raw sys (it mount the raw ext4 image 'sys.raw' in the sys folder)


sudo nautilus (it opens file manager/browser with root privileges)


Now you have a new mounted drive called 'sys' with the system folder files. You can copy the system folders and files to the folder 'system_folder' or another place, using the file manager with root privileges and unmount the drive "sys". If you want to unpack files from MTKDroid Tools backup, the utility has actually already done that for you and the system folder is available in the compressed file system.ext4.tar. Alternatively you can just substitute 'sys.raw' in the mount command with 'system.ext4.img' from MTKDroid Tools.


Repacking system folder into system.img for SP Flash Tool


1. Move the folders and files inside of system folder to be repacked to a folder inside img-tools folder, such as the previously created 'system_folder'.


2. Check the right system partition size for your device. If you previously unpacked the system.img from your device, than the partition size is the size of the sys.raw file or the size of system.ext4.img from MTKDroid Tools backup. This is usually a multiplier of 256M, just like memory modules, i.e, 512M, 768M, 1G, 2G, 3G, etc. (1K = 1024 bytes, 1M = 1024K, 1G = 1024M and so on).


3. Right click anywhere inside the img-tools folder and select "Open in Terminal". This opens up a terminal window already inside the folder.


4. Type the following commands:


sudo su (it will ask for your password and give you root privileges)


./make_ext4fs -s -l <partition size> -a system newsystem.img system_folder (it will create newsystem.img from folders and files into 'system_folder') Note: substitude <partition size> for your device system partition size as explained in number 2 above, i.e., 512M or 768M or 1G, etc. So, for example, for a device whose system partition size is 512M the command will look like this: ./make_ext4fs -s -l 512M -a system newsystem.img system_folder


Now you can rename the newsystem.img file to system.img and flash it with a a scatter file of your device in SP Flash Tool: http://androidmtk.com/flash-stock-rom-using-smart-phone-flash-tool
 
Last edited by a moderator:
  • Like
Reactions: mrsim

mrsim

KingOfNoobs
Staff member
Mar 1, 2014
14,672
2,178
113
49
London UK
fucking AWESOME guide mate...excellent stuff...thank you very much for this... :good2: :party: :clapping: :dance2:
 
  • Like
Reactions: JVitor