Skip to content

Instantly share code, notes, and snippets.

@haise0
Last active November 30, 2023 06:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haise0/f3c1f24b0a7a9150603dfd00985c0042 to your computer and use it in GitHub Desktop.
Save haise0/f3c1f24b0a7a9150603dfd00985c0042 to your computer and use it in GitHub Desktop.
A guide to extracting LG KDZ firmware update files in order to unpack the super.img held therein.

Extracting KDZs and their super.img partition held within

LG KDZ formats are a pain in the ass. Various tools and scripts have been made for the extraction of said KDZs; not many, if any at all, work with the current KDZ format (v3).

The script mentioned below for extraction should work with all three formats, i.e old, older, and new.

Prerequisites

  • Windows (preferably with WSL), or Linux/Mac with a Windows VM
    • NOTE: Unfortunately I am not yet aware of a method for Unix systems that does not require a VM or Wine for the time being. Looking into the 7zip method of extraction may fix this.
  • Python 3 and Pip
  • With pip, install zstandard
    • pip install zstandard
  • 7zip, preferably the zstandard variant:
  • Probably going to want both Linux and Windows at your disposal for easy filesystem mounting. If running Windows, this can be done easily with WSL. See here. Alternatively, 7zip is perfectly capable of opening and/or extracting ext4 filesystems by itself.
  • If running Linux as your host machine, you'll probably have to use a Windows VM, or to use Wine if 7zip works with it. I don't know whether or not this is the case and I haven't bothered to actually check.
  • Grab iscgar's kdz extractor.
    • NOTE: Click on the "raw" button and then go ahead and just save that page to your preferred location if you aren't familiar with GitHub gists.
    • For this guide we'll assume you've saved this file as "kdz_extractor.py"

The Process

We'll assume that you are inside of a Windows environment, and that our workspace is the plain and simple Desktop.

  1. Create a folder for your extracted images to be placed into; i.e for the V60, "V60_extracted"

  2. Ensure that your KDZ and kdz_extractor.py are on the Desktop, or if working elsewhere, are in the same folder together.

  3. Within Windows Terminal or alternatively Powershell, run:

    • python3 kdz_extractor.py -e <where to extract> <kdz to extract> An example command, with our working directory as the Desktop, our folder for extraction being "V60_extracted" and our KDZ file having the name "V600TM10p_00_TMO_US_OP_0511.kdz" would be:
    • python3 kdz_extractor.py -e V60_extracted V600TM10p_00_TMO_US_OP_0511.kdz
  4. The script will print some information about the file and hang for a few minutes while it gets ready. It will continue to print output once it's working on what chunk it's currently working with and in what partition it resides in. It is important to not cancel the script or get impatient. It takes some time.

  5. Once the extraction is complete, within the folder for extracted images, you should see quite a lot of different files. What we will focus on is "0.super.img." The number prefix may vary.

  6. Open this folder in Explorer and select the super partition file. Right click, and within the context menu, choose:

    • "7-Zip > Open Archive... > #"

    This will open said archive and you will be met with eight files, four of them with .ext extensions. The "Comment" column will provide the labeling. If you see system, vendor, and product, then the file with the comment of "/" is the odm partition. If you see vendor, product, and odm, the "/" comment file will be system.

  7. From here it is simple click and drag. Place the four .ext files into a directory of your choice, and rename each of them to the corresponding file; i.e 4.ext to vendor.raw.

  8. If using a bash terminal, you can mount these files with no issues to a folder of your choice. I had success with:

    • sudo mount -t ext4 -o loop system.raw system/

If you're using 7zip, you can simply open the archive, or extract it directly.

Notes

  • For some reason, some KDZs throw an error upon extraction talking about a headers issue where it is expecting a certain amount of bytes but gets something different. It is on my todo list to take a look at it and patch it to work if/when that happens. I have only run into this on two of the Stylo 6 KDZ files. The V60 Android 10 KDZ file worked with zero issues. Android 11 is yet to be tested.

Special Thanks

  • iscgar for the updated and functional KDZ extractor.
  • mcmilk for the simply awesome 7-Zip variant with far more functionality.
  • Igor Pavlov's 7-Zip for being a progressive yet classic program for Windows and providing people everywhere with a wide variety of compression and decompression capabilities.
@baljeetkhairwal
Copy link

baljeetkhairwal commented Jul 17, 2023

Good Work.Please give detailed guide and also work on extraction+flashable zip converter using custom recovery for new kdz.

@cuynu
Copy link

cuynu commented Oct 13, 2023

requires use windows just for 7-Zip to open super.img?, there is an linux tool can unpack and repack them called lpunpack and lpmake, its in google android repo

@Rofikkernel
Copy link

not work extract v40 kdz but succes extract v60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment