[ASUS ZenFone 8] bnsmb:
The first post of this thread includes instructions to create an "ugly" TWRP image for use with LineageOS based ROMs that do not support TWRP out of the box anymore.

But unfortunatley, it doesn't seeem to be possible to create a TWRP image for all LineageOS based ROMs. Even worse, it looks like every other release of an LineageOS based ROM requires a TWRP image for that version.

I've read some posts and blog entries that TWRP is no longer needed for LineageOS as all necessary tasks can be performed with the recovery from the LineageOS, but I don't think so.

After booting the phone into LineageOS recovery, adb is not enabled by default in the user builds; that may be safe , but it's not very useful because you can't use the adb access to the phone in recovery mode for automatic tasks via script. And access via adb can be enabled in the recovery GUI ...

I finally figured out how to "fix" this problem (see How to add files to the ramdisk used for the recovery boot), but there is another drawback: /data is not mounted if the phone is booted into the LineageOS recovery and so far I do not know if /data can be mounted while the phone is booted into the LineageOS recovery.

In TWRP, adb is enabled by default and TWRP can mount /data and decrypt the user files if necessasry - this is also true for the "ugly" TWRP images created for the LineageOS based ROMs. And not to mention the other features of TWRP that are not part of the LineageOS recovery (e.g. a local terminal, the various functions of the twrp binary, etc).

Since I need these features to install and customize these ROMs for my development and testing purpose, and I do not want to manually create the TWRP image for each new OS version, I wrote a small Linux shell script to create a TRWP image for these ROMs:

./create_ugly_twrp_image.sh

create_ugly_twrp_image.sh uses the official TWRP image for the phone and the boot partition from the phone (or an image file with the boot partition) to create a TWRP image for that OS.

The usage for the script is:

[ OmniRom 14 Dev - xtrnaw7@t15g / ] $ /data/develop/android/scripts_on_linux/create_ugly_twrp_image.sh -h

create_ugly_twrp_image.sh - "create" an TWRP image for an Android OS version not supporting TWRP (e.g an OS based on Lineage 20.x or newer)

Usage: create_ugly_twrp_image.sh [-h] [-v] [boot_partition|boot_partition_image_file] [noprop|-p]

[ OmniRom 14 Dev - xtrnaw7@t15g / ] $

Spoiler content hidden.

The script supports some environment variables - see the verbose usage above for details.

To be able to detect this TWRP image later in scripts, the script copies some properties from the current running OS to the new TWRP image; these properties are (as of 26.06.2024):

# properties for the TWRP image - the values for these properties are copied to the TWRP image if they exist in the running OS
#
PROPERTIES_TO_COPY_TO_THE_TWRP_IMAGE="
ro.lineage.build.version
ro.statix.version
ro.omni.version
ro.lmodroid.build_name
ro.build.description
ro.build.display.id
"

The properties to copy are hardcoded in the script; properties that are not defined in the running OS are ignored.

The script uses the executable magiskboot from Magisk to unpack and repack the TWRP images.

The magiskboot executable for x86 in the Magisk apk file is a static linked binary that can be executed on any of the modern Linux distributions for x86 PCs.

To get that executable download the Magisk apk file from https://github.com/topjohnwu/Magisk/releases and extract the executable magiskboot for x86 using the commands:

unzip -p Magisk-v27.0.apk lib/x86/libmagiskboot.so >magiskboot && chmod 755 magiskboot

The script can be downloaded from here: create_ugly_twrp_image.sh.sh

Test Environment

All tests were done on an ASUS Zenfone 8.

Tests were done with these ROMs:

/e/, tested with images files for versions 1.21 and 2.0

LineageOS 20, various OS image files

LineageOS 21, various OS image files (downloaded from https://github.com/mikooomich/android_device_asus_sake/releases)

LMODroid, various OS image files

StatixOS, various OS image files