[Miscellaneous Android Development] diplomatic:
Bootless root with Magisk and MTK-SU

This guide is obsolete. Follow the new one for support for the latest Magisk

-----------------------------------------------------------------------------------------------------------------------------------

Get full root with Magisk on a locked bootloader!​

A major new development in MTK rooting is here. Now you can have Magisk on locked down devices! It runs entirely from the data partition: no need to modify boot or system. Any app that wants root access can have it. All Magisk Manager features are there as well.

Now for the not-so-fine print: Read this whole post before starting. Only use this on devices on which you can recover the firmware through an outside channel such as recovery mode, download tool, etc. It's still unclear how safe this is to run on locked devices. After launching this system, there is still significant potential to brick your device. While precautions have been taken to block modifications to the boot partition, not everything has or can be accounted for. You must anticipate when a superuser action might alter your boot or system partitions and avoid doing that command. Do not try to update Magisk through Magisk Manager's Direct Install!... Even though testing has shown that that feature will fail, it might succeed with future versions of MM or on specific devices.

REQUIREMENTS

Advanced skills and experience using the Thanks button

A device compatible with mtk-su

mtk-su R19 or higher

Magisk not installed on device

LIMITATIONS

Cannot modify boot partition unless bootloader is unlocked

Cannot modify system/vendor partitions unless boot partition is altered

Only Magisk versions up to 18.1 are currently supported--Magisk 19.x has lost the required 'magisk --startup' functionality

Your mileage may vary with Android 9

INSTRUCTIONS

Make sure you meet all the requirements, including the first one.

Download and install the init.d scripts support app. Make sure this app gets installed on the internal storage, not the external SD. (Support the developer.)

Make a folder named 'init.d' on your internal storage. Also make a 'bin' folder inside 'init.d'. Set up the init.d app up like this:

Try to acquire root privileges: unchecked

Run scripts at boot time: checked

Execution delay: No delay

Selected folder: /storage/emulated/0/init.d

Execute all files: unchecked

Remember that the folder structure has to be exactly as described, unless you manually edit the path in the script. You can also, in principle, use a different app if you want, but in that case you have to edit the package name path in the script as well.

Download and install the Magisk Manager apk. For Android 9, the highest version that will work is 7.1.1. The latest version should be usable for Android 8.x and lower, but 7.1.1 may be better in all cases. Make sure this app is installed on the internal storage, not external SD.

In MM, go to Settings, Update Channel, Custom, and enter this URL: https://raw.githubusercontent.com/topjohnwu/magisk_files/841e978604f989d04549013cd4dcc7e34aea5288/stable.json . This will freeze the update version of Magisk at 18.1. That's necessary for MM to create the right environment for Magisk modules to work.

Download the current su-boot script, unzip it, and put suboot.sh inside your /sdcard/init.d folder.

Download the current mtk-su zip and put your appropriate mtk-su file in your /sdcard/init.d/bin folder.

Download the Magisk 18.1 zip (not 19.x or higher). Extract the arm/magiskinit file and move it to your /sdcard/init.d/bin folder. That is the only file you will need from that zip. (Support the developer.)

Now you should be ready to launch the Magisk core. Either reboot or tap 'Run scripts now'. The process will take a few seconds before telling you that 1 script has finished. If it ran successfully, last execution result will show something like this:

Temporary root by diplomatic@XDA
Home URL:
https://xdaforums.com/android/development/amazing-temp-root-mediatek-armv8-t3922213
--------------------------------------------------

UID: 0 cap: 3fffffffff selinux: permissive
source type magisk does not exist
Error in: allow magisk (null) (null) (null)
client: launching new main daemon process

That output was made by the latest mtk-su & suboot script. If you get a different result, then something may have gone wrong.

At this point, you should be able to run 'su' or do a root request from an app and get a prompt.

When you open Magisk Manager, it will prompt you with Requires Additional Setup. On this window, you can tap Yes. This is safe. Make sure that you have done step 5 before doing this.

Turn off update checking in MM. Never try to do a direct-install Magisk Update on a locked device.

DOWNLOAD (UPDATED 2019-12-28)

suboot.zip

FAQ

My init.d app does not start at boot time

It may be that your OS is not allowing the app to run in the background. Some OSs are too aggressive in managing background apps. Look in Settings for any background management or battery optimization or similar features, and disable them for the init.d app. The same tweak could benefit Magisk Manager.

My Magisk modules will not load properly. What is going on?

This method can only launch root after the init.d app starts up and runs the script. This is late in the boot cycle. Up to that point, root is not available. Unfortunately, many Magisk modules need to be loaded early in the boot process to work properly. I don't think there is much that can be done about that. (Perhaps a warm reboot would help, but that would cause problems of its own.)

Can I modify or reimplement the suboot script and distribute it?

Yes, absolutely. You may do whatever you want with the suboot.sh script. However, you may not distribute the mtk-su zip or binary. Instead, please ask your users to download the latest release from this thread.

CREDITS

Huge thanks to [MENTION=5312578]mrmazak[/MENTION] for helping me get this up and running on Android Pie