[GUIDE] OTA Tools LPUnpack

Search This thread

Y_Marques

New member
Jun 30, 2015
3
0
Hello,

After unpacking the super image I get successfully the contained images, but I'm having a problem at the moment of mounting them:
wrong fs type, bad option, bad superblock on /dev/loop10, missing codepage or helper program, or other error.
The ony way I could make it work is as follows (but of course I don't have write access):
Code:
sudo mount -o ro system_a.img ./mount
Also I cannot modify any of the permissions once mounted.

I didn't have this issue modifying Android Images previous to the dynamic partition implementation. Someone had experience this issue?
 

Lossyx

Senior Member
Jan 14, 2014
1,561
853
OnePlus 7T Pro
Google Pixel 7 Pro
Hello,

After unpacking the super image I get successfully the contained images, but I'm having a problem at the moment of mounting them:

The ony way I could make it work is as follows (but of course I don't have write access):
Code:
sudo mount -o ro system_a.img ./mount
Also I cannot modify any of the permissions once mounted.

I didn't have this issue modifying Android Images previous to the dynamic partition implementation. Someone had experience this issue?
You need to deduplicate the blocks first. Which you can do by running e2fsck -E unshare_blocks, but first you need to resize the partition to give enough space.

If anyone's wondering, here's how you can directly modify logical partition and flash it back to your device.


Big thanks to @thohac for pretty much telling me how to do it and getting me in the right track.
 

Y_Marques

New member
Jun 30, 2015
3
0
You need to deduplicate the blocks first. Which you can do by running e2fsck -E unshare_blocks, but first you need to resize the partition to give enough space.

If anyone's wondering, here's how you can directly modify logical partition and flash it back to your device.


Big thanks to @thohac for pretty much telling me how to do it and getting me in the right track.

Thank you for te guidance, it worked as expected. The shared post is very useful too.
 

dewettie

Senior Member
Sep 15, 2013
67
26
Anyone can help how to repack an unpacked super.img?
Try to delete an app in the product and system.img and post the instructions to repack everything into a super.img again.
My goal is to remove most of the preinstalled Google apps.

Here is the firmware link
It is for a different device but the principle should work the same

It seems the firmware is non-A/B.

How do you get this size?
3)--device super: The size of the “super” partition on the device. It must match exactly, and it must be evenly divisible by the sector size (512 bytes).

After repacking I also get this error, is it normal?
'Invalid sparse file format at header magic'
 

Y_Marques

New member
Jun 30, 2015
3
0
Anyone can help how to repack an unpacked super.img?
Try to delete an app in the product and system.img and post the instructions to repack everything into a super.img again.
My goal is to remove most of the preinstalled Google apps.

Here is the firmware link
It is for a different device but the principle should work the same

It seems the firmware is non-A/B.

How do you get this size?
3)--device super: The size of the “super” partition on the device. It must match exactly, and it must be evenly divisible by the sector size (512 bytes).

After repacking I also get this error, is it normal?
'Invalid sparse file format at header magic'

There is multiple ways to get the size of the super partition. One of the most convenient ones is to reboot the devices in the bootloader and run
Code:
fastboot getvar partition-size:super
.

The invalid sparse message after repacking the super image is normal afaik.
 

Lossyx

Senior Member
Jan 14, 2014
1,561
853
OnePlus 7T Pro
Google Pixel 7 Pro
Anyone can help how to repack an unpacked super.img?
Try to delete an app in the product and system.img and post the instructions to repack everything into a super.img again.
My goal is to remove most of the preinstalled Google apps.

Here is the firmware link
It is for a different device but the principle should work the same

It seems the firmware is non-A/B.

How do you get this size?
3)--device super: The size of the “super” partition on the device. It must match exactly, and it must be evenly divisible by the sector size (512 bytes).

After repacking I also get this error, is it normal?
'Invalid sparse file format at header magic'
Unpacking the super is not the best way. You should dump product with dd or payload bin. Or at least I think that's the best way.
 
Last edited:

giubenez

Member
Mar 30, 2011
42
8
I edited the vendor.img followed this guide but something strange happens:


$stat -c '%n %s' *
super.img 3758096384
product.img 1596944384
system.img 1128718336
vendor.img
544976896

$../otatools/bin/lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:3758096384 --group main:3270639616 --partition system:readonly:1128718336:main --image system=./system.img --partition vendor:readonly:544976896:main --image vendor=./vendor.img --partition product:readonly:1596944384:main --image product=./product.img --sparse --output ./super.new.img
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition system will resize from 0 bytes to 1128718336 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition vendor will resize from 0 bytes to 544976896 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition product will resize from 0 bytes to 1596944384 bytes
Invalid sparse file format at header magic
Invalid sparse file format at header magic
Invalid sparse file format at header magic


BUT....

$stat -c '%n %s' super.new.img
super.new.img
3248851200

which is not divisible by 512!

Shouldn't it be 3758096384 ?
 
  • Like
Reactions: lebigmac

Lossyx

Senior Member
Jan 14, 2014
1,561
853
OnePlus 7T Pro
Google Pixel 7 Pro
I edited the vendor.img followed this guide but something strange happens:


$stat -c '%n %s' *
super.img 3758096384
product.img 1596944384
system.img 1128718336
vendor.img
544976896

$../otatools/bin/lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:3758096384 --group main:3270639616 --partition system:readonly:1128718336:main --image system=./system.img --partition vendor:readonly:544976896:main --image vendor=./vendor.img --partition product:readonly:1596944384:main --image product=./product.img --sparse --output ./super.new.img
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition system will resize from 0 bytes to 1128718336 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition vendor will resize from 0 bytes to 544976896 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition product will resize from 0 bytes to 1596944384 bytes
Invalid sparse file format at header magic
Invalid sparse file format at header magic
Invalid sparse file format at header magic


BUT....

$stat -c '%n %s' super.new.img
super.new.img
3248851200

which is not divisible by 512!

Shouldn't it be 3758096384 ?
That guide seems awfully complicated, unless it's trying to accomplish something different.

You can use my guide (s). I've made the vendor partition R/W and resized couple of times now.

 

giubenez

Member
Mar 30, 2011
42
8
That guide seems awfully complicated, unless it's trying to accomplish something different.

You can use my guide (s). I've made the vendor partition R/W and resized couple of times now.


thank you for your response.
I started from a super partition, so i guess i have to use lpmake to rebuild the super.img.
I just need to edit the fstab to disable avb/dm-verity manually by removing the avb keys.
However, without changing the partition size, I cannot modify (see here ) the file.

If I use
$ e2fsck -E unshare_blocks vendor.img
without resizing the partition I cannot edit the file.
 

Lossyx

Senior Member
Jan 14, 2014
1,561
853
OnePlus 7T Pro
Google Pixel 7 Pro
thank you for your response.
I started from a super partition, so i guess i have to use lpmake to rebuild the super.img.
I just need to edit the fstab to disable avb/dm-verity manually by removing the avb keys.
However, without changing the partition size, I cannot modify (see here ) the file.

If I use
$ e2fsck -E unshare_blocks vendor.img
without resizing the partition I cannot edit the file.
You don't need to touch the super partition at all.
Again, look at my guide, I do resize the partition to make space.

With my method, just resize it to 2 or 3GB, unshared its blocks. Then in order it flash it just resize the logical partition on device.

Previously I resized vendor, unshared its block, but I couldn't resize it back because now if was bigger than before so you had to delete other stuff. Being the vendor, that would be dangerous.
Although, you could resize to minimum size and just resize the logical partition in fastbootd.

If you do want to resize the partition and then back, I used this command to get the size.

ls -l --block-size=4k partition.img
 

giubenez

Member
Mar 30, 2011
42
8
You don't need to touch the super partition at all.
Again, look at my guide, I do resize the partition to make space.

With my method, just resize it to 2 or 3GB, unshared its blocks. Then in order it flash it just resize the logical partition on device.

Previously I resized vendor, unshared its block, but I couldn't resize it back because now if was bigger than before so you had to delete other stuff. Being the vendor, that would be dangerous.
Although, you could resize to minimum size and just resize the logical partition in fastbootd.

If you do want to resize the partition and then back, I used this command to get the size.

ls -l --block-size=4k partition.img
Again, it seems to me that we are not talking the same language. I don't have a OP 7T, but a Doogee S96, I posted here bacause we are talking of lpunpack.

Your guide start with talking of payload.bin, I googled what it is but I don't have any stock rom nor OTA update.

I don't have vendor image, at least I can't see it from fastboot or adb.
I can't boot, i flashed TWRP but I'm not able to disable dm-verity (AVB) so my phone goes directly to the recovery after boot.

The only fstab with avb flags I found is on /dev/block/platform/bootdevice/by-name/super --(lpunpack)--> vendor/etc/fstab.mt6785

I just need to remove the avb flags, save and repack with lpmake. I don't need more space for that, I just have to edit the plain thext file and repack everything.
Nevertheless I cannot edit fstab.mt6785 without increasing the size of the partition. Is it normal? Even though I delete a wav file and unshare_blocks i cannot edit fstab.mt6785.

Thank you for your help, any suggestion is appreciated.
 

Lossyx

Senior Member
Jan 14, 2014
1,561
853
OnePlus 7T Pro
Google Pixel 7 Pro
Again, it seems to me that we are not talking the same language. I don't have a OP 7T, but a Doogee S96, I posted here bacause we are talking of lpunpack.

Your guide start with talking of payload.bin, I googled what it is but I don't have any stock rom nor OTA update.

I don't have vendor image, at least I can't see it from fastboot or adb.
I can't boot, i flashed TWRP but I'm not able to disable dm-verity (AVB) so my phone goes directly to the recovery after boot.

The only fstab with avb flags I found is on /dev/block/platform/bootdevice/by-name/super --(lpunpack)--> vendor/etc/fstab.mt6785

I just need to remove the avb flags, save and repack with lpmake. I don't need more space for that, I just have to edit the plain thext file and repack everything.
Nevertheless I cannot edit fstab.mt6785 without increasing the size of the partition. Is it normal? Even though I delete a wav file and unshare_blocks i cannot edit fstab.mt6785.

Thank you for your help, any suggestion is appreciated.
My bad, but given we're in the 7T section and you didn't mention your device beforehand I assumed you had a 7T.
--- My thoughts below will be all over the place, hopefully, I don't confuse you. ---

I think your device does a vendor partition, my output the same as yours of the first link you linked.
Although it should be somewhere in /dev/block/dm-x (or if there is something similar)?.
When I mounted vendor with TWRP and ran "df -h" I could see it being mounted to dm-9 for example.
Although, in your case, I see your TWRP is not properly updated for dynamic partitions so it might be hard to mount it.

I guess this is the need lpunpack. But I still believe you can follow the steps I linked, but you are just getting the vendor in another way(extracting from super partition).

On that note, I'm not sure I see the need to repack the super partition. I never touched the super partition even though vendor is in it. I just resized. unshared it blocks, resized it, and flashed it.

Fastbootd is the new interface to handle logical partitions.
Moving Fastboot to Userspace | Android Open Source Project

Other than this I am afraid I cannot help you more. I myself am still inexperienced when it comes to this, especially regarding lpunpack.
 
Last edited:

lebigmac

Account currently disabled
Jan 31, 2017
1,342
995
that works only on userdebug builds (custom ROM?)
Did you try running those commands inside TWRP which is an engineer build?
The result should carry over into android.
You can double check this by extracting the avbctl app from inside TWRP and run it inside Android. It will say that dm-verity is already disabled.
 

beta.0

Senior Member
Jul 26, 2016
54
9
Has anyone been able to repack Amlogic super.img with lpmake?

I extracted odm, product, system & vendor from an OTA zip, converted them to sparse and replaced the originals from an older aml_upgrade_package.img (extracted using xVortex kitchen v5).

lpmake built the image without any error but when I flash it to the device it goes into a boot loop, only getting to the boot logo before restarting.

Maybe xVortex is not rebuilding the full upgrade package correctly? It's an S905X4 based device.
 
Last edited:
  • Like
Reactions: ytagger

ytagger

Senior Member
Sep 23, 2020
50
13
Has anyone been able to repack Amlogic super.img with lpmake?

I extracted odm, product, system & vendor from an OTA zip, converted them to sparse and replaced the originals from an older aml_upgrade_package.img (extracted using xVortex kitchen v5).

lpmake built the image without any error but when I flash it to the device it goes into a boot loop, only getting to the boot logo before restarting.

Maybe xVortex is not rebuilding the full upgrade package correctly? It's an S905X4 based device.
I'm having the same issue with a super partition pulled from my device with edl
 

Top Liked Posts

  • There are no posts matching your filters.
  • 12
    Please see this URL https://android.googlesource.com/platform/build.git/+/eec4a7cba4face3370acb6293ab357879920b467 and this for more information.

    Hi everyone. I'm surprised I havent seen a thread about ota tools yet and lpunpack. This zip file contains a lot of useful tools for modifying super.img and making super.img as well as other tools found in other toolkits. This was just compiled using aosp master. The most useful function is the lpunpack tool which can extract a super.img into system, vendor, odm and product images.


    Browse individual files

    Download HERE
    • Extract super.img from device

    Code:
    adb shell
    Code:
    su
    Code:
    dd if=/dev/block/by-name/super of=/sdcard/super.img
    Code:
    exit
    Code:
    exit
    Code:
    adb pull /sdcard/super.img


    • Extract super.img with lpunpack

    Usage on PC(linux):
    Code:
    ./lpunpack - command-line tool for extracting partition images from super
    
    Usage:
      ./lpunpack [options...] SUPER_IMAGE [OUTPUT_DIR]
    
    Options:
      -p, --partition=NAME     Extract the named partition. This can
                               be specified multiple times.
      -S, --slot=NUM           Slot number (default is 0).

    **Make sure <output_directory> already exists as this tool will not create a directory for you and will error if not found.**
    **If you run this command with no slot specified, it will output 0 byte empty b images.


    To extract all A images:
    Code:
    ./lpunpack --slot=0 <path-to-super.img> <output_dir>

    To extract all B images:
    Code:
    ./lpunpack --slot=1 <path-to-super.img> <output_dir>



    This program can take a couple minutes to run. After it is complete, your $output_dir will contain vendor, system, product and odm with either _a or _b.
    Thanks for reading!


    :cowboy:ALL CREDIT GOES TO HANETZER @ntzrmtthihu777 FOR ALL OF THIS INFORMATION :cowboy:
    He taught me, I just wrote this!​
    2
    build an arm version of lpunpack ?
    For android?
    You can take the build tree from my github (I cannot post external links due to the small number of posts).
    2
    Hello,

    After unpacking the super image I get successfully the contained images, but I'm having a problem at the moment of mounting them:

    The ony way I could make it work is as follows (but of course I don't have write access):
    Code:
    sudo mount -o ro system_a.img ./mount
    Also I cannot modify any of the permissions once mounted.

    I didn't have this issue modifying Android Images previous to the dynamic partition implementation. Someone had experience this issue?
    You need to deduplicate the blocks first. Which you can do by running e2fsck -E unshare_blocks, but first you need to resize the partition to give enough space.

    If anyone's wondering, here's how you can directly modify logical partition and flash it back to your device.


    Big thanks to @thohac for pretty much telling me how to do it and getting me in the right track.
    1
    I did not understand: this tool can extract .img partition or only extract them from phone?

    Example: I want to extract product.img partition to edit it and then reconvert to .img and then flash it to phone. Is this possible?

    you need to convert it using simg2img then mount the img to edit it then when done use img2simg to convert back into android sparse img then can b flashed
    1
    can't get it to work... it always says "bash: ./lpunpack: Permission denied"

    can someone help?

    trying to run it in mint4kitchen with all updates
    Probably need to chmod it..
    Code:
    chmod +x lpunpack
    OR
    Code:
    chmod 755 lpunpack