Repack system.img with simg2img/mkuserimg - Nexus 5X Q&A, Help & Troubleshooting

Has anyone been able to repack system.img using these tools? I've tried a couple variations of of parameters for mkuserimg, but everytime it gets stuck on the boot animation.
simg2img ./system.img system.raw
sudo mount -t ext4 -o loop system.raw ./mount/system/
sudo mkuserimg.sh -s mount/system/ system_new.img ext4 /system 3221028864
I've also tried
sudo mkuserimg.sh -s mount/system/ system_new.img ext4 /system 3195826176
Neither one works. The first one gets the file size of the .raw files to match, but the number of blocks (per tune2fs) differ. The second one gets the number of blocks to match, but not the .raw file sizes.
The base system.img I have flashes without any problems.
Appreciate any help!

Did you disabled the encryption in the boot.img ? It might be getting stuck since the signatures don't match. Have a look at the boot.img used to root. The fstab entries are relaxed. I think there is another change from stock.

gee one said:
Did you disabled the encryption in the boot.img ? It might be getting stuck since the signatures don't match. Have a look at the boot.img used to root. The fstab entries are relaxed. I think there is another change from stock.
Click to expand...
Click to collapse
Definitely using a boot.img with encryption disabled. Using this one: http://forum.xda-developers.com/apps/supersu/wip-android-6-0-marshmellow-t3219344
I've tried running both stock system.img through the repack process and a AOSP built system.img and both images stop working once run through mkuserimg
Maybe I'll give the ElementalX kernel a try.

Related

Why don't my boot.img files boot?

Ok so I customized a boot.img (init.rc file) and repacked it using mkbootfs and mkbootimg. For the life of me, I can't get these boot imgs to boot. Any ideas why? The same exact stuff worked fine on my Hero.
chuckhriczko said:
Ok so I customized a boot.img (init.rc file) and repacked it using mkbootfs and mkbootimg. For the life of me, I can't get these boot imgs to boot. Any ideas why? The same exact stuff worked fine on my Hero.
Click to expand...
Click to collapse
well some more detail would be really helpful in troubleshooting. hopefully you're able to get something ... im still new to the style HTC uses for their kernels.
is the kernel booting and not loading the init.rc properly (possible adb output?) or is the kernel not even loading properly? how far along with the boot screens do you get?
are you using --cmdline and --base?
Good call. I should probably post the commands I used. lol
Ok so I did change my init.rc but for testing purposes I just unpacked the stock boot.img and immediately repacked it. the commands are as follows:
Code:
$ mkbootfs boot.img-ramdisk | gzip > ramdisk-boot
$ mkbootimg --kernel boot.img-kernel --ramdisk ramdisk-boot --cmdline "no_console_suspend=1 console=null" -o newBoot.img --base 0x19200000
Then generates a boot.img file successfully but it still does not boot. Any ideas?
Edit: And of course I renamed newBoot.img to boot.img and included it in an update.zip which all flashed with no errors. Just never gets past the first HTC Evo 4G boot screen
chuckhriczko said:
Edit: And of course I renamed newBoot.img to boot.img and included it in an update.zip which all flashed with no errors.
Click to expand...
Click to collapse
im still beginning in building boot.img files for HTC android phones. my experience is with building a straight zImage kernel file with an initramfs compiled into the zImage kernel file for a Samsung android phone.
hopefully somebody can comment with some better insight, on mkbootfs, etc as I'm also very curious what the best command is for our EVO.
my only comment is a side note to the flashing process and hopefully this method will speed up testing for you and everybody else. i wrote the commands ROM and recovery/normal android mode independent. this is how i would quickly test kernels on my samsung android based phone, assuming it works the same on HTC?
adb push boot.img /sdcard/boot.img
adb push flash_image /sdcard/flash_image (only have to do once)
cat /sdcard/flash_image > /data/flash_image (only have to do once)
chmod 755 /data/flash_image (only have to do once)
/data/flash_image boot /sdcard/boot.img
reboot the phone to test ... hopefully that simplifies the kernel testing process!
thanks for posting up all your detail, its insightful and helpful!
--base 0x20000000 <~ change to
btw moving thread to q&a
toastcfh said:
--base 0x20000000 <~ change to
btw moving thread to q&a
Click to expand...
Click to collapse
Worked perfectly. Thanks Toast.

ext4 extraction from system.sin issues

Hi,
As you probably know, ext4 image can be extracted from system.sin but cannot be mounted. When trying to mount it, it fails with :
[ 1476.821582] EXT4-fs (loop0): bad geometry: block count 262144 exceeds size of device (144631 blocks)
I open this thread just to share what I did around the issue and maybe have some helpful quotes about it
Here is what I did (under linux)
# First create an zero filled file. Size is system partition size (262144 blocks of 4096 each)
dd if=/dev/zero of=/home/xperia/virtualfs bs=4096 count=262144
# Attach file to loopback
sudo losetup /dev/loop0 /home/xperia/virtualfs
# Format it with same features as system partition on phone
sudo mkfs.ext4 -O has_journal,^ext_attr,^dir_index,^flex_bg,^huge_file,resize_inode,filetype,extent,sparse_super,large_file,^uninit_bg,^dir_nlink,^extra_isize -v /dev/loop0
# Write extracted system.sin.ext4 extracted image to loopback
sudo dd if=system.sin.ext4 of=/dev/loop0
# Mount filesystem
sudo mount /dev/loop0 /mnt
It can be mounted and I can have folder structure but I can't work with files. Editing default.prop gives me a non readable file.
But we can go a step ahead as we can now mount the image.
Still some issues have to be worked out.
The poit is, why we cant mount system.img on ICS but we can on GB?
maybe someone can contact with sony t oask
im extracting the .sin to .img like always but its impossible to mount.. what are you using to extract the .sin to a .ext4?
BTW, thanks for the info, i've been trying to modify system.img since ICS appeared.
EDIT: of, ext4 can be extracte with flashtool ~.~
maybe we need to read something from system.partinfo
Yakandu said:
The poit is, why we cant mount system.img on ICS but we can on GB?
maybe someone can contact with sony t oask
im extracting the .sin to .img like always but its impossible to mount.. what are you using to extract the .sin to a .ext4?
BTW, thanks for the info, i've been trying to modify system.img since ICS appeared.
EDIT: of, ext4 can be extracte with flashtool ~.~
maybe we need to read something from system.partinfo
Click to expand...
Click to collapse
Yes Flashtool can extract image from system.sin.
partinfo is partition information used by loader in flashmode to identify where to flash image on phone. (Something like start nand address of system partition)
so, any ideas why ext4 cant be mounted? maybe its encrypted or something..
Sorry for double post, i found a solution
Flash the system through a .ftf with flashtools
Flash a custom kernel with recovery (or the nozomi recovery)
Backup nandroid
We get a system.ext4.tar ··· move it to your developement folder
Create a folder (mkdir system)
Enter nautilus with root acces
Extract system files to the created folder
Modify whatever you want
Make a flashable system.img with: "./mkuserimg.sh -s /system ./system.img ext4 ./temp 1024M"
AND ITS WORKING!
Yakandu said:
Sorry for double post, i found a solution
Flash the system through a .ftf with flashtools
Flash a custom kernel with recovery (or the nozomi recovery)
Backup nandroid
We get a system.ext4.tar ··· move it to your developement folder
Create a folder (mkdir system)
Enter nautilus with root acces
Extract system files to the created folder
Modify whatever you want
Make a flashable system.img with: "./mkuserimg.sh -s /system ./system.img ext4 ./temp 1024M"
AND ITS WORKING!
Click to expand...
Click to collapse
This solution is already known
But my goal is to be able to mod a system partition without having to flash it before. And more, understand why extracted system image cannot be mounted and how to work this out
oh, ok xD
i didnt know that solution, its new for me
Yakandu said:
Sorry for double post, i found a solution
Flash the system through a .ftf with flashtools
Flash a custom kernel with recovery (or the nozomi recovery)
Backup nandroid
We get a system.ext4.tar ··· move it to your developement folder
Create a folder (mkdir system)
Enter nautilus with root acces
Extract system files to the created folder
Modify whatever you want
Make a flashable system.img with: "./mkuserimg.sh -s /system ./system.img ext4 ./temp 1024M"
AND ITS WORKING!
Click to expand...
Click to collapse
Have you already tried flashing this img on your device? I have already tried this solution twice but didn't succeed (@Spectre51 that's why I haven't replied your PM yet). system.img was succesfully created but I got boot loop when I flashed it on my device.
Hi Androxyde,
I figured it out, basically we have to dig further in sin format as new ext4 sins skips part of the file. See my thread for more details.
PS: Thanks for flashtool, it's a great tool!
LeTama
letama said:
Hi Androxyde,
I figured it out, basically we have to dig further in sin format as new ext4 sins skips part of the file. See my thread for more details.
PS: Thanks for flashtool, it's a great tool!
LeTama
Click to expand...
Click to collapse
:good:

[Q] [SOLVED] Failed to create my own system.img

Hi all,
I'm trying to create my own system.img for the Nexus 7 2013 Wifi from the stock system.img from https://developers.google.com/android/nexus/images 5.0.2 LRX22G. Basically I did it the common way using the android repack tools http://forum.xda-developers.com/showthread.php?t=2600364 and I'm also using branch android-5.0.2_r1 from the git repo.
I'm flashing with the simple:
Code:
fastboot flash system mysystem.img
The problem I'm having is, even with an unmodified tree from system.img, the image I created always get the device stuck at the boot Google logo screen. If I flash the original system.img, then it is fine, so I think my flashing part is working.
The command line I used to create the image is:
Code:
./mkuser.img.sh -s /path/to/loop_mounted_system/ mysystem.img ext4 system 880803840
which will run:
Code:
make_ext4fs -s -T -1 -l 880803840 -a system mysystem.img /path/to/loop_mounted_system/
Has anyone here actually managed to create a working system.img?
Any suggestions would be much appreciated, thanks!
UPDATE: Using ext2simg instead of mkuserimg.sh/make_ext4fs fixes the problem!

booting custom kernel

SOLVED: I was using the G980F boot.img instead of G985F image. THANKS everyone
The device won't reboot if I unpack and repack the boot.img on S20
Did someone else here succeed in flashing a new boot.img ? THANKS
Code:
[email protected]:~/GS20_kernel_build$ unpackbootimg -i boot.img
BOARD_KERNEL_CMDLINE androidboot.hardware=exynos990
BOARD_KERNEL_BASE 10000000
BOARD_PAGE_SIZE 2048
[email protected]:~/GS20_kernel_build$ mkbootimg --kernel boot.img-zImage --ramdisk boot.img-ramdisk.gz -o boot_repacked.img
[email protected]:~/GS20_kernel_build$ heimdall flash --BOOT ./boot_repacked.img
[...]
Downloading device's PIT file...
PIT file download successful.
Uploading BOOT
100%
BOOT upload successful
Ending session...
Rebooting device...
modem__ said:
The device won't reboot if I unpack and repack the boot.img on S20
Did someone else here succeed in flashing a new boot.img ? THANKS
Code:
[email protected]:~/GS20_kernel_build$ unpackbootimg -i boot.img
BOARD_KERNEL_CMDLINE androidboot.hardware=exynos990
BOARD_KERNEL_BASE 10000000
BOARD_PAGE_SIZE 2048
[email protected]:~/GS20_kernel_build$ mkbootimg --kernel boot.img-zImage --ramdisk boot.img-ramdisk.gz -o boot_repacked.img
[email protected]:~/GS20_kernel_build$ heimdall flash --BOOT ./boot_repacked.img
[...]
Downloading device's PIT file...
PIT file download successful.
Uploading BOOT
100%
BOOT upload successful
Ending session...
Rebooting device...
Click to expand...
Click to collapse
You need to make a tar file containing the img and flash it with odin. You need a Windows computer for that. Linux won't do sadly
If you don't feel like making a flashable zip file you can just use dd to install it from within TWRP (via terminal on console or ADB) if you have that installed:
dd if=boot_repacked.img of=/dev/block/by-name/boot
No Windows/Odin required.
sjevtic said:
If you don't feel like making a flashable zip file you can just use dd to install it from within TWRP (via terminal on console or ADB) if you have that installed:
dd if=boot_repacked.img of=/dev/block/by-name/boot
No Windows/Odin required.
Click to expand...
Click to collapse
dd always scares me lol.
You sure this works with S20? Even Fastboot fllashing doesn't work so I doubt this will
JanBoyGamer23 said:
dd always scares me lol.
You sure this works with S20? Even Fastboot fllashing doesn't work so I doubt this will
Click to expand...
Click to collapse
My phone wouldn't boot last night after I tried flashing my own boot image and this was how I put the previous one back. It booted right up.

Repack Stock Firmware with Android 10 for Odin

I am trying to de-bload/modify the original stock firmware and flash it to my phone using odin without installing TWRP. I have already successfully flashed Magisks this way. However, all the guides I found on modifying the system.img seem to be outdated and do not work anymore.
Here is my current workflow (all on Debian 10)
Code:
tar xvf AP_*.tar.md5 #from original stock rom package or magisk_patched_*.tar) into sub-directory
lz4 -d system.img.lz4
simg2img system.img system.raw.img #either the Debian version or fresh compile from https://github.com/anestisb/android-simg2img
mkdir sys
sudo mount -t ext4 -o loop system.raw.img sys/
# Do a bunch of changes in the mounted image e.g. delete Samsung bloatware
sudo umount sys/
img2simg system.raw.img system.img
lz4 -B6 --content-size system.img system.img.lz4
tar --owner=1000 --group=1000 -H ustar -cvf AP_modified.tar *
md5sum -t AP_modified.tar >> AP_modified.tar
mv AP_modified.tar AP_modified.tar.md5
Unfortunately, the resulting file does not work because odin hangs or odin finishes and the phone is stuck in a boot loop. Anybody knows what I am missing here. Bootloader is unlocked, as I said, I could successfully flash the modified AP_* from magisk.

Categories

Resources