[ASUS ZenFone 8] bnsmb:
In Magisk v26.0 the developer changed the code so that it's not possible anymore to install Magisk into the boot partition while booted from a recovery image.

from the Magisk change log:

"This means that any installation of Magisk v26+ using custom recovery will be incomplete; a subsequent re-installation through the Magisk app after booting up is required."

The installation of Magisk v26.x while booted into the recovery (for example using my script install_magisk_via_twrp.sh; see How to install Magisk into the boot partition using script) will succeed but executing the Magisk app after the necessary reboot will end with this dialog:

View attachment 5889965

After pressing OK in that dialog Magisk will reinstall itself in the boot partition and reboot. And afterwards Magisk works again. But that step needs user intervention.

Without executing this additional step Magisk won't work. There is no way to trigger this reinstallation via an CLI command that is usable in a script (at least I did not found it until now ...)

Unfortunately, Magisk also does not execute the init scripts from /data/adb/post-fs-data.d or /data/adb/service.d in this state.

Therefor the automatic installation of Android, TWRP, Magisk, etc like implemented in the tasks in prepare_phone.include (see How to install and configure the Android OS for details) will fail.

To get around this I added some code to the script install_magisk_via_twrp.sh to support the installation of Magisk v26:

install_magisk_via_twrp.sh version v3.1.0.0 (or newer) can now be used to also install Magisk v26 into the boot partition. There are two new parameter for the script install_magisk_via_twrp.sh to select the method to use for the installation:

oldmethod - install Magisk into the boot partition while booted into a recovery

newmethod - install Magisk into the boot partition image while booted into the Android OS

The installation using the "newmethod" only works if their is a working adb connection to the running Android OS on the phone.

Without one of the two new parameter the script will check the Magisk apk file to detect the necessary method to install Magisk into the boot partition. The default method if no apk file is used is still the old method.

Patching the boot image with Magisk v26 is done using these steps:

boot the phone from a TWRP image

create an image of the boot partition while booted from the TWRP image

copy the boot partition image and the Magisk executables to a directory that can be accessed by the user shell while booted into the Anroid OS

boot the phone into the Android OS

patch the boot partition image using the Magisk binaries (that can be done by the non-root user shell)

reboot the phone from a TWRP image

install the patched boot image via dd or fastboot

To do an automatic installation via script using Magisk v26 I added another task to prepare_phone.include:

install_magisk_v26_in_boot_partition

This task will install Magisk using the new method described above.

Because the installation of Magisk v26 needs a working adb connection the tasks in prepare_phone.include will first install Magisk v25.x and enable adb via Magisk init script like before. After this is done Magisk v26 can be installed via script.

So the new task list to install and configure the Android OS using the tasks in the file prepare_phone.include is:

DEFAULT_TASKS="
enable_disable_abort_on_error:enable
boot_phone_from_twrp_image
install_os:noreboot:factory_reset
install_twrp:noreboot:next
#
# first install Magisk v25.x into the boot partition; this installation is necessary to
# enable the access via adb to the phone; the Magisk installation will be overwritten later
# with Magisk v26 or newer
#
install_magisk_in_boot_partition_only:noreboot:next
enable_adb:reboot
#
install_magisk_in_data_adb_only:noreboot:copy_apk
enable_root_access_for_the_shell:reboot
wait_for_access_via_adb:120:kill
#
# the next step is necessary to install Magisk v26 or newer
#
install_magisk_v26_in_boot_partition:active:reboot
install_the_magisk_app

wait_for_access_via_adb:120:kill
enable_disable_abort_on_error:disable
install_essential_scripts
install_essential_apps
install_essential_magisk_modules
enable_root_access_for_apps:reboot
execute_script_on_the_phone:ignorerc
"

To distinguish between the apk files for Magisk v25 and Magisk v26 two new variables must be defined in the config file prepare_phone.conf for the tasks in prepare_phone.include:

MAGISK_v26_APK_FILE="/data/backup/Android/EssentialApps/Magisk-v26.1.apk"
MAGISK_v25_APK_FILE="/data/backup/Android/EssentialApps_Backup/Magisk-v25.2.apk"

see here for the log of an update of Magisk v25 to Magisk v26 via script using the command

./prepare_phone.sh install_magisk_v26_in_boot_partition

see here for the log of an automated installation using the tasks in prepare_phone.include with the installation of Magisk v26 using the command

./prepare_phone.sh all

Testenvironments for the installation of Magisk v26 via script

an ASUS Zenfone 8 running

OmniROM 13 with MicroG and Magisk v26.1

OmniROM 12 with MicroG and Magisk v26.1

ASUS Android 13 and Magisk v26.1

ASUS Android 12 and Magisk v26.1

LineageOS 19 and Magisk v26.1

All tests were done using TWRP 3.7.0.12