LiveSuit image - Use of simg2img and mkuserimg

Introduction

The RFSFAT16_DATA_00000000000 and RFSFAT16_SYSTEM_000000000 files are in a sparse ext4 format, meaning they cannot just be mounted as normal. The files need to be converted before they can be mounted - this is where the two utilities simg2img and mkuserimg are used.

First, where to get them. There are, as might be expected, various versions going around. I found a good thread on their use at http://forum.xda-developers.com/showthread.php?t=1081239. The tools are in a ZIP file called ext4_utils.zip. There are two versions available from that thread - one is from the first post, the other is from post #109 (direct link http://forum.xda-developers.com/showthread.php?p=31089100#post31089100). I experimented with both versions, and they both seemed to produce the same results. Therefore, I'm sticking with the one linked in the first post.

Installation

Remember, this is on Linux. Although you can place the files in whatever path you like, I suggest you stick to what I've done here, so relative paths work correctly.

Extract the contents of ext4_utils.zip to a folder called ext4_utils on your Desktop. Fire up a terminal and cd to the folder ext4_utils. You will need the zlib package installed, so run

sudo apt-get install zlib1g-dev

Once zlib is installed, type make and that should compile the packages.

Usage - simg2img

As the name implies, this converts a sparse image into a "normal" image. For this example, we will use it on RFSFAT16_DATA_00000000000. Copy RFSFAT16_DATA_00000000000 over to the Linux machine and place it on the Desktop. Open up a terminal and navigate to the Desktop.

In the terminal, run:

sudo ext4_utils/simg2img RFSFAT16_DATA_00000000000 data.img

After a while, you will have a data.img file on the Desktop which is a mountable ext4 image. Note the size of the file - on mine, it is 1073741824 bytes. This corresponds exactly to the partition size specified in either the COMMON_SYS_CONFIG000000 file (from the Livesuit unpacking) or by doing a cat /proc/partitions on the tablet itself. During the burning process, Livesuit presumably extracts the sparse image to a normal image, then writes it byte-for-byte to the partition on the tablet.

Still inside the terminal, and on the Desktop, we make a new folder:

mkdir data

and then mount the image file:

sudo mount -o loop -t ext4 data.img data

This mounts data.img to the folder we just created (data). We can now view and edit all the files.

Usage - mkuserimg

After modifying any files, if required, or if we are starting afresh from a .tar.gz of the files extracted from another tablet, we need to recreate the sparse ext4 image. This is done using the mkuserimg.sh script. cd into the ext4_utils folder, then run the following:

sudo ./mkuserimg.sh -s ../data ../data_new ext4 ../tmp 1073741824

This is a tricky one. mkuserimg.sh is a sort of wrapper for make_ext4fs. The -s switch tells it to make a sparse image. ../data is the path to the folder containing the files to combine into the sparse image - in this case, it's the folder where we previously mounted the simg2img converted image. ../data_new is the output file to create - this will be the new sparse image. ext4 tells it to create an ext4 sparse image. ../tmp is weird - the only description I can find of this is "mount point". However, I tried changing this and then comparing the resulting files byte-for-byte and there was no difference, so it doesn't seem to matter. Leave it as ../tmp. The last part, 1073741824 is very important - this is the exact size (in bytes) of the partition which the image will be used to create. In our case, this is the size obtained from the COMMON_SYS_CONFIG000000 file (from the Livesuit unpacking). The data partition size is listed as 1048576 blocks - remember this is blocks of 1024 bytes each, so the total size is 1048576*1024=1073741824. Make sure this matches, otherwise things will screw up.

The output from the command looks like:

in mkuserimg.sh PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
./make_ext4fs -s -l 1073741824 -a ../tmp ../data_new ../data
Creating filesystem with parameters:
    Size: 1073741824
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 4096
    Label: 
    Blocks: 262144
    Block groups: 8
    Reserved block group size: 63
Created filesystem with 441/65536 inodes and 39765/262144 blocks

There will now be a file called data_new on the Desktop - this can be used to replace the original RFSFAT16_DATA_00000000000 in the Livesuit image and repack it.

Back to index