FORUMS

Moto X Style, Moto X Play and Moto G Forums Are Here!

The latest family members of the new generation of Motorola devices are … more

Galaxy Unpacked: What is Samsung Going to Unveil?

Amidst all the hype of the OnePlus 2 and the rain of Moto 2015 news, Samsung tried … more

Arrow Launcher: Good Effort Without Direction

Microsoft’s Android expansion has been well received on the productivity front, but … more

Two New Moto X and New Moto G – Specs & Details

Today’s Moto event just ended and now we have a clear look at all of … more

[REF] Unpacking and repacking stock rom .img files

51 posts
Thanks Meter: 147
 
By jazzor, Member on 16th May 2011, 06:42 AM
Post Reply Subscribe to Thread Email Thread
As most of you are aware, the stock rom tarball is comprised of several .img files which don't seem to be of any file system format and it is difficult at first to see what is inside these files without flashing via Odin.

Well, thanks to fguy, this thread http://forum.xda-developers.com/show....php?t=1054836 provided me the necessary inspiration to investigate just exactly what are these img made of.

Hopefully, this will allow easy removal of all the Samsung junk, deodexing, rooting etc etc without going through adb.

As it turns out, they are simply sparse ext4 images, and the AOSP source tree already contains the necessary utilities to both unpack and repack these img files via "ext4_utils" in system/extras (https://android.googlesource.com/pla...system/extras/)

For your convenience, I have provided a repackage of the source code for ext4_utils with a simple Makefile, for keen developers to make the necessary tools for unpacking and repacking the stock img files. Making these tools requires a linux development environment, which is beyond the scope of this topic.

To make the tools, simple extract the attached source code and type "make".

To unpack the .img file:
Code:
./simg2img factoryfs.img output.img
To view the contents of .img file:
Code:
mkdir tempdir; mount -o loop output.img tempdir
To repack .img file:
Code:
./mkuserimg.sh -s /some/directory/with/files ./factoryfs_custom.img ext4 ./temp 512M
As I do not have Odin at the moment, I am not able to test the repacked files can be reflashed successfully. I will test this shortly.


UPDATE
I have just tested repacking the stock factoryfs.img. It so happens that the original ext4_utils does not properly preserve permissions on the new ext4 image. I have made a slight modification to the source and reuploaded the zip.

You can now successfully unpack, remove and change the stock apps, root and modify the stock image using instructions above!!

I hope this will help people create their own custom roms.


UPDATE 27th MAY FOR GALAXY S4 TESTING (i9500 i9505)
A few people have messaged me asking why these tools do not work for the new Galaxy S4. Unfortunately I do not have a Galaxy S4 so I can not test any of these utilities. HOWEVER, it seems there has been quite a bit of updates by Google in the ext4_utils package. I have updated the sources according to 4.2.2 which is the latest version of the tools. I must stress that I DO NOT HAVE A GALAXY S4 TO TEST so don't be expecting miracles. In any case I have uploaded the new code now. As it was before, I have provided a MAKEFILE and you simply type "make" in order to build the tools. They are contained in ext4_utils_new.zip.

Thanks for your support guys. And I do apologize for replying late to my inbox...

Update 9th November 2014
Thanks to qwerty_7564 for providing the fixes for cygwin compilation.
Ext4 utils new still missing link arguments to compile. Investigating. I will update the sources to that of the 4.3 branch later.

Update 3rd December 2014
I have updated the tools to 4.3 branch. Note that no attempts has been made to make this compatible with cygwin as I have no cygwin to test.
As I have mentioned earlier, I do not have a newer samsung device to test any of these files, use at your own discretion. The new files are in ext4_utils_r4.3.tar.gz and is based on the jb release 2.0.0 branch.
Attached Files
File Type: zip ext4_utils_cygwin_fixed.zip - [Click for QR Code] (59.8 KB, 7892 views)
File Type: gz ext4_utils_new_cygwin_fixed.tar.gz - [Click for QR Code] (64.9 KB, 6025 views)
File Type: gz ext4_utils_r4.3.tar.gz - [Click for QR Code] (110.0 KB, 11156 views)
Last edited by jazzor; 4th December 2013 at 12:14 AM. Reason: updated to 4.3
The Following 105 Users Say Thank You to jazzor For This Useful Post: [ View ]
 
 
16th May 2011, 07:57 AM |#2  
manuvaidya's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 8
 
More
you mean, with these tools anyone with fair knowledge of linux can create custom ROMs ? what all we can do with this trick to an image/stock ROM ? pls explain
keen to know what change it could bring to the present scenario of tweaks...
16th May 2011, 08:27 AM |#3  
Senior Member
Flag Reggio Emilia
Thanks Meter: 262
 
More
Yes and you can even provide root privileges to stock rom without having to pass through insecure firmware

As you said anyone with a little knowledge of Linux could do that
It's only unpacking and repackaging new rom

Sent from my GT-I9100 using Tapatalk
The Following User Says Thank You to nightranger73 For This Useful Post: [ View ]
16th May 2011, 01:26 PM |#4  
Senior Member
Thanks Meter: 64
 
More
very good jazzor

what is so special samsung img file?
16th May 2011, 02:59 PM |#5  
OP Member
Thanks Meter: 147
 
More
There is nothing special about the img file. It is just that I have not seen anyone write a guide to modify these img files yet. They are simple compressed ext4 images as explained in the first post. AOSP already recognises this format and have made available utilities for you to modify and create your own img files which can be flashed via Odin
The Following 2 Users Say Thank You to jazzor For This Useful Post: [ View ]
16th May 2011, 03:43 PM |#6  
dxdiag32's Avatar
Senior Member
Flag Chongqing
Thanks Meter: 350
 
More
hope someone can make this tool....i know little linux knowledge....
22nd May 2011, 09:23 AM |#7  
Senior Member
Valencia
Thanks Meter: 64
 
More
Hi, I have given make a mistake, it can be?

Thanks.
Quote:

borou@borou-casa:~/discoduro/BASURILLA/GSII/Varios/ext4_utils$ make
gcc -I. -DANDROID -c make_ext4fs.c
gcc -I. -DANDROID -c make_ext4fs_main.c
gcc -I. -DANDROID -c ext4_utils.c
gcc -I. -DANDROID -c allocate.c
gcc -I. -DANDROID -c backed_block.c
gcc -I. -DANDROID -c output_file.c
output_file.c:25:18: fatal error: zlib.h: No existe el fichero o el directorio
compilation terminated.
make: *** [output_file.o] Error 1

The Following User Says Thank You to BoRoU For This Useful Post: [ View ]
22nd May 2011, 09:41 AM |#8  
Senior Member
Thanks Meter: 32
 
More
Quote:
Originally Posted by BoRoU

Hi, I have given make a mistake, it can be?

Thanks.


hi BoRoU, try this:

$ apt-get install zlib1g-dev

The Following 3 Users Say Thank You to vauss For This Useful Post: [ View ]
22nd May 2011, 09:47 AM |#9  
Senior Member
Valencia
Thanks Meter: 64
 
More
Perfect. Gracies.
24th May 2011, 07:28 AM |#10  
Senior Member
Thanks Meter: 23
 
More
i get a warning when i try the option make

root@galaxy-1:/home/galaxy/ext4_utils# make
gcc -I. -DANDROID -c make_ext4fs.c
gcc -I. -DANDROID -c make_ext4fs_main.c
gcc -I. -DANDROID -c ext4_utils.c
gcc -I. -DANDROID -c allocate.c
gcc -I. -DANDROID -c backed_block.c
gcc -I. -DANDROID -c output_file.c
gcc -I. -DANDROID -c contents.c
contents.c: In function ‘make_directory’:
contents.c:118:3: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 4 has type ‘u32’

how can i fix this?
The Following User Says Thank You to GalaxyS! For This Useful Post: [ View ]
24th May 2011, 02:32 PM |#11  
Member
Thanks Meter: 9
 
More
Quote:
Originally Posted by GalaxyS!

i get a warning when i try the option make

root@galaxy-1:/home/galaxy/ext4_utils# make
gcc -I. -DANDROID -c make_ext4fs.c
gcc -I. -DANDROID -c make_ext4fs_main.c
gcc -I. -DANDROID -c ext4_utils.c
gcc -I. -DANDROID -c allocate.c
gcc -I. -DANDROID -c backed_block.c
gcc -I. -DANDROID -c output_file.c
gcc -I. -DANDROID -c contents.c
contents.c: In function ‘make_directory’:
contents.c:118:3: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 4 has type ‘u32’

how can i fix this?


Code:
error("failed to allocate %llu extents", (unsigned long long)len);

Read More
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes