How to pack and unpack system.img and userdata.img from an Android factory image


  1. Download the https://android.googlesource.com/platform/system/extras repository:
    git clone https://android.googlesource.com/platform/system/extras
  2. Check out a revision of your choice:
    cd extras
    git checkout android-4.1.1_r1
  3. Compile simg2img:
    cd ext4_utils
    gcc -o simg2img -lz sparse_crc32.c simg2img.c
  4. Unpack your Android image files:
    cd ../../
    ./extras/ext4_utils/simg2img system.img system.raw.img
    ./extras/ext4_utils/simg2img userdata.img userdata.raw.img
  5. Do whatever you want with the images (eg. you can use Paragon's ExtFS on a Mac or just simply mount the images in linux via the loop device).
    (Update, 2012.02.16: Paragon's ExtFS -or at least v8- does not work well. Sad It doesn't show all files that are in the ext4 image.)
    Eg.
    mkdir /mnt/my_system /mnt/my_userdata
    mount -t ext4 -o loop system.raw.img /mnt/my_system
    mount -t ext4 -o loop userdata.raw.img /mnt/my_userdata
  6. Compile 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
  7. Repack the images:
    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
P.S.: if compiling stuff is not your thing, you can just download simg2img and make_ext4fs from here.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Since the linking behaviors

Since the linking behaviors may be changed, the order of linking zlib now matters, the command of compilation of make_ext4fs should be this:

gcc -Wl,--as-needed 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 -lz -o make_ext4fs

Worked on Ubuntu 14.04

Re: Since the linking behaviors

Thanks for the feedback! Much appreciated. Smile

ext4 util compilation with Android source 4.4.x

Someone could rewrite the article how to compile ext4 utils (simg2img - make_ext4) using the latest source file (Androdi 4.4.r2.01)

Re: ext4 util compilation with Android source 4.4.x

I'll look into this.

How it can be made in Odin

Can I convert it to tar file to use in Odin

Re: How it can be made in Odin

Eg. search for the terms "how create samsung tar odin site:forum.xda-developers.com" on Google. It will give you plenty of tutorials on how to put a custom system.img into a *.tar.md5 so you can flash it with Odin.

To obtain such a mistake I pack

I enter the following command:
mkuserimg.sh -s /mnt/my_system new.img ext4 /tmp/ 1024M

Get an error
file_context_open:error file context handle(no such file or directory)
no such file or directory
...
exit 4

Re: To obtain such a mistake I pack

Are you sure this is the entire output of the command you were trying to execute?
Was there anything else besides what is hidden behind the three dots?
What output do the three dots represent?

collect2: error:

I got the next error when compile simg2img

/usr/bin/ld: cannot find -lz
colect2: error: ld returned 1 exit status.

may somebody help me plz

PS. using ubuntu-15.04 and/or 14.04 under windows10/virtualbox


Tks

Bob

system.img does not start

Hello,

Is anyone familiar how to change system image in wear ?
I am using the checkout for android_4.1.1 as in this example. I hope it should be OK with wear preview 2 too.

I use the non-preview release in "Preview image for LGE Watch Urbane 2nd Edition", and installed it on wear.
Then I tried to use simg2img&make_ext4fs inorder to extract and pack back to img.
I made no change in system files. Just extracted and packed again. No error been recieved.
But on flashing the new system.img, it fails to start correctly (nothing is seen in screen after boot).


2304 sudo ./simg2img system.img system.raw
2308 sudo mount -t ext4 -o loop system.raw xxx/
2309 sudo ./make_ext4fs -s -l 512M system_new2.img xxx/



Did anyone have success in programming new system image into waer ?
Why didn't it work ?
Is there another simpler way I should try ?

Thanks,
ranchu

Syndicate content