- Download the https://android.googlesource.com/platform/system/extras repository:
git clone https://android.googlesource.com/platform/system/extras
- Check out a revision of your choice:
cd extras
git checkout android-4.1.1_r1
- Compile
simg2img
:
cd ext4_utils
gcc -o simg2img -lz sparse_crc32.c simg2img.c
- Unpack your Android image files:
cd ../../
./extras/ext4_utils/simg2img system.img system.raw.img
./extras/ext4_utils/simg2img userdata.img userdata.raw.img
- 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. 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
- 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
- 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
Something Missing in Step 6
...make_ext4fs
probably should be
...make_ext4fs.c
Re: Something Missing in Step 6
gcc
parameters by mistake.I wrote:
gcc -o allocate.c backed_block.c contents.c ext4_utils.c extent.c indirect.c make_ext4fs.c make_ext4fs_main.c sha1.c sparse_crc32.c uuid.c wipe.c make_ext4fs -lz
gcc -o make_ext4fs -lz allocate.c backed_block.c contents.c ext4_utils.c extent.c indirect.c make_ext4fs.c make_ext4fs_main.c sha1.c sparse_crc32.c uuid.c wipe.c
Thanks for bringing this to my attention. Already fixed it.
Compiling simg2img and make_ext4fs from Android v4.2.1 sources
Let's assume that the
$AOSP_ROOT
variable points to our AOSP root (eg.export AOSP_ROOT="$HOME/Android/AOSP"
).cd "$AOSP_ROOT"
[ ! -d "platform/system" ] && mkdir -p platform/system
cd platform/system
git clone https://android.googlesource.com/platform/system/core
cd core
git checkout android-4.2.1_r1
simg2img
:cd libsparse
gcc -o simg2img -Iinclude -lz simg2img.c sparse_crc32.c backed_block.c output_file.c sparse.c sparse_err.c sparse_read.c
cd ../../
./core/libsparse/simg2img system.img system.raw.img
./core/libsparse/simg2img userdata.img userdata.raw.img
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
make_ext4fs
did get more complicated too:cd "$AOSP_ROOT/platform"
[ ! -d "system" ] && mkdir system
cd system
git clone https://android.googlesource.com/platform/system/extras
cd extras
git checkout android-4.2.1_r1
make_ext4fs
:cd ..
gcc -o make_ext4fs -Icore/libsparse/include -lz extras/ext4_utils/make_ext4fs_main.c extras/ext4_utils/make_ext4fs.c extras/ext4_utils/ext4fixup.c extras/ext4_utils/ext4_utils.c extras/ext4_utils/allocate.c extras/ext4_utils/contents.c extras/ext4_utils/extent.c extras/ext4_utils/indirect.c extras/ext4_utils/uuid.c extras/ext4_utils/sha1.c extras/ext4_utils/wipe.c core/libsparse/backed_block.c core/libsparse/output_file.c core/libsparse/sparse.c core/libsparse/sparse_crc32.c core/libsparse/sparse_err.c core/libsparse/sparse_read.c
PATH="$PATH:$(pwd)" ./extras/ext4_utils/mkuserimg.sh -s /mnt/my_system_dir my_system.img ext4 /tmp 512M
error("can't set android permissions - built without android sup
error("can't set android permissions - built without android support");
Re: error
had the same error (when
gcc calls need this too:
-Icore/include -DANDROID
Re: had the same error
After putting " -lz" at the
Otherwise: undefined reference to `gzwrite'
Ubuntu 12.04.1
Re: After putting " -lz" at the
gcc
I had the-lz
option worked where I put it. It seems thatgcc
is not that much standardized after all.Compiling make_ext4fs from Android v4.3 sources
simg2img
is pretty much the same as for 4.2.*. But the compilation ofmake_ext4fs
got a lot more complicated. First of all, it seems that this cannot be compiled (at least out-of-the-box) on a Mac anymore because of SELinux dependencies.If you try to compile it on linux, the following might be sufficient:
gcc -o make_ext4fs -Isystem/core/libsparse/include -Isystem/core/include -Iexternal/libselinux/include -lz external/libselinux/src/android.c external/libselinux/src/booleans.c external/libselinux/src/callbacks.c external/libselinux/src/check_context.c external/libselinux/src/freecon.c external/libselinux/src/getenforce.c external/libselinux/src/init.c external/libselinux/src/label.c external/libselinux/src/label_android_property.c external/libselinux/src/label_file.c system/extras/ext4_utils/make_ext4fs_main.c system/extras/ext4_utils/make_ext4fs.c system/extras/ext4_utils/ext4fixup.c system/extras/ext4_utils/ext4_utils.c system/extras/ext4_utils/allocate.c system/extras/ext4_utils/contents.c system/extras/ext4_utils/extent.c system/extras/ext4_utils/indirect.c system/extras/ext4_utils/uuid.c system/extras/ext4_utils/sha1.c system/extras/ext4_utils/wipe.c system/extras/ext4_utils/crc16.c system/core/libsparse/backed_block.c system/core/libsparse/output_file.c system/core/libsparse/sparse.c system/core/libsparse/sparse_crc32.c system/core/libsparse/sparse_err.c system/core/libsparse/sparse_read.c
I didn't have the chance to test it (tried to compile on a Mac, but gave up after hitting the SELinux problem), but it seems to be the complete
gcc
line for make_ext4fs.Since the linking behaviors
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
ext4 util compilation with Android source 4.4.x
Re: ext4 util compilation with Android source 4.4.x
How it can be made in Odin
Re: How it can be made in Odin
To obtain such a mistake I pack
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
Was there anything else besides what is hidden behind the three dots?
What output do the three dots represent?
collect2: error:
/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
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