[ASUS ZenFone 8] bnsmb:
IMHO one drawback of the recoveries used for LineageOS-based ROMs is that some important tools are missing in the ramdisk used for the recovery and that adb is not enabled by default in the recovery of the user builds.

This post contains instructions to fix these issues without recreating the ROM image.

The ROMs /e/ 2.x, LMODroid 4.2, LineageOS 20, and LineageOS 21 for the ASUS Zenfone 8 use the ramdisk on the partition vendor_boot when they are booted in recovery mode (tested only with images for the ASUS Zenfone 8 but I assume this is true for other ROMs without a ramdisk in the boot partition).

To add files to the ramdisk that is used for the recovery mode in one of the ROMs listed above, proceed as follows.

Either install Magisk or enable root access via adb in the Developer settings if this setting is available in the ROM.

If Magisk is not installed on the phone, extract the executable magiskboot for the CPU in your phone from the Magisk apk file and copy it to the phone.

See here for instructions how to do that, e.g. to extract the executable for Android phones with an ARM 64 Bit CPU do:

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

Note that Magisk is only required to change the ramdisk on the vendor_boot partition - it is not mandatory to install Magisk on the phone.

Open an adb shell and issue as user root:

# change the path to magiskboot in the variable MAGISKBOOT according to your environment
#
MAGISKBOOT="/data/adb/magisk/magiskboot"

# get the current boot slot
#
CUR_SLOT=$( getprop ro.boot.slot_suffix )

# create the working directory
#
mkdir -p /data/develop/vendor_boot${CUR_SLOT}
cd /data/develop/vendor_boot${CUR_SLOT}

# extract and unpack the partition vendor_boot
#
dd if=/dev/block/by-name/vendor_boot${CUR_SLOT} of=./vendor_boot${CUR_SLOT}.img

mkdir image
cd image

${MAGISKBOOT} unpack -h ../vendor_boot${CUR_SLOT}.img

# unpack the ramdisk from the vendor_boot partition
#
mkdir ramdisk
cd ramdisk

${MAGISKBOOT} decompress ../ramdisk.cpio - | cpio -idm

(remember the compression format printed by magiskboot - it is required later to compress the cpio file with the ramdisk again. Example: Detected format: [lz4_legacy] )

The contents of the directory with the uncompressed ramdisk.cpio file should look like this:

Spoiler content hidden.

Now you can change, add, or delete files for the ramdisk in the directory with the uncompressed cpio file.

(see the notes below for how to automatically enable adb in the recovery)

Keep in mind that some links in the ramdisk are absolute symbolic links and other are only mount points for the other partitions.

When everything is done repack the file ramdisk.cpio and create the new image file for the partition vendor_boot:

# only to be sure that the environment variables are set ...
#
MAGISKBOOT="/data/adb/magisk/magiskboot"

CUR_SLOT=$( getprop ro.boot.slot_suffix )

mv ../ramdisk.cpio ../ramdisk.cpio.org

# re-create the cpio file with the files for the ramdisk
#
find . | cpio -o | ${MAGISKBOOT} compress=lz4_legacy - ../ramdisk.cpio

# ... and recreate the image for the vendor_boot partition

cd ..

${MAGISKBOOT} repack ../vendor_boot${CUR_SLOT}.img

Finally, flash the new image file to the partition vendor_boot:

dd if=./new-boot.img of=/dev/block/by-name/vendor_boot${CUR_SLOT}

and reboot into the recovery mode to check the new ramdisk contents.

Notes

This approach does not work for the StatixOS and the OmniROM. For the OmniROM I recommend to install TWRP into the boot partition.

/data is not automatically mounted if booting into the recovery from /e/, LMODroid, LineageOS 20.x, and LineageOS 21.x.

Workaround: Boot from a TWRP image for the installed OS to also access the files in /data -- see the post How to use TWRP if LineageOS 20.x is installed for how to create a TWRP image for these ROMs

access via adb is not automatically enabled when booting into a recovery for non-debuggable builds from the ROMs mentioned in this post

see https://github.com/LineageOS/android_bootable_recovery for details how to enable the automatic start of the adb after booting into the recovery for these ROMs

Spoiler content hidden.

Additional kernel parameter used while booting into the recovery mode can be added to the line cmdline= in the header file for the vendor_boot partition.

Be aware that the partition vendor_boot is overwritten with each OS update. But the instructions used here can easily be combined in a script in order to apply them automatically after an operating system update, for example.

A script to enable adb in the ramdisk from the partition vendor_boot can be downloaded from here:

enable_adb_in_recovery_ramdisk.sh

To use the script, copy it to the phone and execute it in an adb session. The scripts needs no parameter.

The script enables adb access in the vendor_boot partition for the active slot. The script does not change the partition if adb is already enabled in the ramdisk on the partition.

The script searches the executable magiskboot in the directories /data/adb/magisk and /data/local/tmp; if magiskboot is in another directory set the environment variable MAGISKBOOT before executing the script. To change the ramdisk from another partition set the variable VENDOR_BOOT_PARTITION before executing the script.

Spoiler content hidden.

Trouble Shooting

If the phone hangs booting into recovery after changing the ramdisk on the vendor_boot partition, check the compression method used to recreate the ramdisk - it must be the compression method used to compress the original ramdisk

default.prop in the ramdisk for the recovery is a symbolic link to prop.default but you should not use the link.

If the adb access does not work after booting into the recovery first check if the adb is running at all on the phone using the command

adb devices

Examples:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/ASUS_ZENFONE8/Statix/20240106 ] $ adb devices
List of devices attached

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/ASUS_ZENFONE8/Statix/20240106 ] $

In this case the adb daemon was not started at all - check the rc files in the ramdisk

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/ASUS_ZENFONE8/e/e-2.0t/test ] $ adb devices
List of devices attached
M6AIB760D0939LX unauthorized

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/ASUS_ZENFONE8/e/e-2.0t/test ]

In this case the adb is running on the phone, but the authorization check for adb is enabled. Double check that the property ro.adb.secure is set to 0 in the file prop.default for the ramdisk.

Test Environment

All tests were done on an ASUS Zenfone 8.

Tests were done with these ROMs:

/e/, OS image file: e-2.0-t-20240514401453-dev-sake.zip

LineageOS 20, OS Image file: lineage-20.0-20240528-nightly-sake-signed.zip

LineageOS 21, OS Image file: sake-2024-05-31-r3-noGMS-ksu-signed-FULL.zip (downloaded from https://github.com/mikooomich/android_device_asus_sake/releases)

LMODroid, OS Image file: LMODroid-4.2-20240613-RELEASE-sake.zip

StatixOS, OS image file: statix_sake-20240508-14-v7.5-UPSIDEDOWNCAKE.zip

OmniROM, OS image file: current latest build for Android 14