FORUMS
Remove All Ads from XDA

[GUIDE] Unpack/repack ext4 Android system images

42 posts
Thanks Meter: 89
 
Post Reply Email Thread
I didn't find any good info for modifying and creating ext4 sparsed images so i decided to share

This is for all who wants to unpack and modify the original system.img that you can flash using recovery.

system.img (what you get from the google factory images for example) represents a sparsed ext4 loop mounted file system.

It is mounted into /system of your device. Note that this tutorial is for ext4 file system, you may have system image which is yaffs2 for example.

the way it is mounted on Galaxy Nexus:

"/dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro,relatime,barrier=1,data=ordered 0 0"
Prerequisites:

1. Linux box or virtual machine
2. simg2img, make_ext4fs binaries which can be downloaded from here http://web.djodjo.org/?a=download:an...inux:ext4tools

Procedure:

place you system.img and the 2 binaries in one directory, and make sure the binaries have exec permission.
Part 1 - mount the filesystem

1. mkdir sys
2. ./simg2img system.img sys.raw
3. sudo mount -t ext4 -o loop sys.raw sys/

Then you have all your system partition mouned in 'sys' and you can modify whatever you want in 'sys'. For example de-odex apks and framework jars.
Part 2 - create a new flashable system image.

1. sudo ./make_ext4fs -s -l 512M -a system new.img sys/
2. sudo umount sys
3. rm -fr sys

Now you can simply type:

fastboot flash system new.img

enjoy
The Following 67 Users Say Thank You to andwise For This Useful Post: [ View ] Gift andwise Ad-Free
 
 
19th July 2012, 01:37 PM |#2  
Retired Recognized Developer
Flag chennai
Thanks Meter: 486
 
Donate to Me
More
Hey thanks for the guide .
I tried to make use of you command to make the .img but I get this error
Code:
[email protected]:~/ext4_utils$  sudo ./make_ext4fs -s -l 512M -a system new.img ~/system/
[sudo] password for vijai: 
Creating filesystem with parameters:
    Size: 536870912
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 2048
    Label: 
    Blocks: 131072
    Block groups: 4
    Reserved block group size: 31
error: do_inode_allocate_extents: Failed to allocate 134 blocks
1st September 2012, 11:32 AM |#3  
Senior Member
Flag Birmingham
Thanks Meter: 75
 
Donate to Me
More
for what is that 512m ?
9th September 2012, 07:26 AM |#4  
TiBiSMART's Avatar
Senior Member
Thanks Meter: 13
 
More
Question
This is the same problem...

any idea?

Quote:
Originally Posted by vijai2011

Hey thanks for the guide .
I tried to make use of you command to make the .img but I get this error

Code:
[email protected]:~/ext4_utils$  sudo ./make_ext4fs -s -l 512M -a system new.img ~/system/
[sudo] password for vijai: 
Creating filesystem with parameters:
    Size: 536870912
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 2048
    Label: 
    Blocks: 131072
    Block groups: 4
    Reserved block group size: 31
error: do_inode_allocate_extents: Failed to allocate 134 blocks

9th September 2012, 02:02 PM |#5  
TiBiSMART's Avatar
Senior Member
Thanks Meter: 13
 
More
Quote:
Originally Posted by TiBiSMART

This is the same problem...

any idea?

This is the solution for sgs3:

./make_ext4fs -s -l 1610612736 -a system new_system.img sys/
The Following User Says Thank You to TiBiSMART For This Useful Post: [ View ] Gift TiBiSMART Ad-Free
31st December 2012, 10:19 AM |#6  
Junior Member
Flag Vienna
Thanks Meter: 22
 
Donate to Me
More
You need to use the correct size for your new system image.
Use tune2fs -l sys.raw and "Block count" * "Block size" for make_ext4fs -s parameter.
You can also use "cat /proc/partitions" and your device to find out the correct size

Note: If your Samsung Device does not support fastboot, you can use heimdall instead.

Tom
The Following 9 Users Say Thank You to RealBorg For This Useful Post: [ View ] Gift RealBorg Ad-Free
11th January 2013, 07:45 AM |#7  
Member
/dev/kmem
Thanks Meter: 60
 
Donate to Me
More
You can just get the size of the original sys.raw and create the new image the same size. You can create the new image whatever size you like that can fit the files you put in but have to bear in mind not to ovrflow the dedicated partition size by the system as it wont be mounted correctly. For example if you create 1gb system for Galaxy Nexus it will be fine and flashed but it will not boot.


Quote:
Originally Posted by RealBorg

You need to use the correct size for your new system image.
Use tune2fs -l sys.raw and "Block count" * "Block size" for make_ext4fs -s parameter.
You can also use "cat /proc/partitions" and your device to find out the correct size

Note: If your Samsung Device does not support fastboot, you can use heimdall instead.

Tom

The Following User Says Thank You to djodjoni For This Useful Post: [ View ] Gift djodjoni Ad-Free
1st March 2013, 07:50 AM |#8  
Junior Member
Flag mumbai
Thanks Meter: 0
 
Donate to Me
More
after mounting i cant modify and cant unmount it
after mounting the sys i cant write maybe there is no root permission and i cant unmout also and tell me one more thing when i use the fastboot flash command its says command not found. please help me, i have mtk .img files
10th March 2013, 06:46 PM |#9  
toly084's Avatar
Member
Flag Rivne, UA
Thanks Meter: 3
 
Donate to Me
More
Wink
Good time of the day for everyone. Finnaly I found what I need. I need to make an image of the system of the Kindle Fire. I have problem with my KF. It can be seen only from Fastboot. It was absolutly dead. Now partitions mounted and even its boot till Kindle Fire (white and yellow). All I've done in the terminal of the TWRP. But to finish I need to make system.img and flash it in Fastboot. As I understood I need Linux, I prepare USB disk right now that to install. Then as wrote:

------------------------------------------------------------------------
1. Linux box or virtual machine
2. make_ext4fs binary which can be downloaded from here http://andwise.net/?attachment_id=406

Procedure:

Create a new flashable system image.

1. sudo ./make_ext4fs -s -l 512M -a system new.img sys/
2. sudo umount sys
3. rm -fr sys

Now you can simply type:

fastboot flash system new.img
----------------------------------------------------------------------------------------------

So, I rebooting my Windows to install Linux
The Following User Says Thank You to toly084 For This Useful Post: [ View ] Gift toly084 Ad-Free
15th March 2013, 09:16 PM |#10  
Member
Thanks Meter: 12
 
More
thanks .
16th March 2013, 04:20 AM |#11  
Member
Thanks Meter: 12
 
More
Waiting for any solution
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes