[ASUS ZenFone 8] bnsmb:
Hi

As far I understand your log you want to

- install the OS

- install Magisk

- enabe access via adb

(there is no task to install TWRP in the logs)

This can be done with the script with a TWRP version that can handle encrypted /data partitions (TWRP version 3.6 or newer if I remember correctly)

Please note that this installation method for Magisk is only valid for Magisk up to version 25.x. From Magisk version 26.x on a different installation method is necessary

(see https://xdaforums.com/t/how-to-inst...rtition-using-a-script.4456621/#post-88429939)

The meaning of the error message

is:

In Android 13 (probably also in 12, but I'm not sure), Android always uses encryption for the files in the /data partition. The initial key used for encryption is generated by the OS during the first reboot after OS installation. The encryption key is stored in one of the phone's partitions and is required to access the files and directories in /data.

A prerequisite for this approach is that there are no files in the /data partition at the first reboot (except for some subdirectories in /data, which are not encrypted at all).

If the Android operating system finds unencrypted files on the /data partition before the initial encryption was done, it fails with an error message and requests a factory reset: The factory reset will then delete all files on the /data partition, and the next reboot will succeed.

So, if you install and customize the Android operating system via scripts, it is mandatory not to write any files or directories to /data before the first reboot of the newly installed operating system.

This is the problem with your task sequence: the tasks install some files in /data and thus the first start of the operating system fails.

The necessary task sequence to do what you want is:

# This task is optional ; the task install_os will reboot the phone from the TWRP image if it's not already booted from the TWRP image
#
./prepare_phone.sh boot_phone_from_twrp_image force

# install the new OS
#
./prepare_phone.sh install_os no:reboot:factory_reset:/data/backup/Redmi_9T/lineage-18.1-20210514-UNOFFICIAL-juice.zip

# install Magisk only in the boot partition -- do not store any files in /data
#
./prepare_phone.sh install_magisk_in_boot_partition_only:noreboot:next

# add the init scripts to enable adb to the ramdisk in the boot partition -- do not store any files in /data
#
# until now nothing was written to the /data partition therefor the reboot into the new OS will succeed
#
./prepare_phone.sh enable_adb:reboot

# now the phone booted the first time from the new OS (task parameter "reboot") and the OS initialized the encryption for the /data partition
# Therefor we can now write files to /data (either while booted into the OS or while booted into an TWRP image with support for accessing encrypted /data partitions)

./prepare_phone.sh install_magisk_in_data_adb_only:noreboot:copy_apk:use_apk

# optional: enable root access via adb
#
./prepare_phone.sh enable_root_access_for_the_shell:reboot

# Note that the last task executed before the task to install the Magisk App must reboot the phone
# into the Android OS
#
./prepare_phone.sh install_the_magisk_app

To create a new task group with these tasks add the task group defintition below to the file prepare_phone.include. Or, to avoid updating the file prepare_phone.include after each update of that file:

Create a new additional include file with the task group definition:

Spoiler content hidden.

Then you can use task group like this

./prepare_phone.sh -i ./install_os_and_magisk.include -i default --list_task_groups INSTALL_OS_AND_MAGISK

or

./prepare_phone.sh -i ?./install_os_and_magisk.include INSTALL_OS_AND_MAGISK

To double check the tasks in the groups do

./prepare_phone.sh -i ./install_os_and_magisk.include -i default --list_task_groups INSTALL_OS_AND_MAGISK

e.g

Spoiler content hidden.

Note:

There is a bug in the current version of the script install_magisk_via_twrp.sh :

Either download the current version from here

https://bnsmb.de/files/public/Android/install_magisk_via_twrp.sh

or add the task

boot_phone_into_android

after the task

install_magisk_in_data_adb_only:reboot:copy_apk:use_apk

regards

Bernd