topjohnwu / Magisk

The Magic Mask for Android
GNU General Public License v3.0
49k stars 12.59k forks source link

Get Magisk Working on Android 11-based GSI's #3593

Closed onlycs closed 3 years ago

onlycs commented 3 years ago

Hello! I have a Moto G8+ running a Lineage OS 18.1 GSI. Magisk doesn't work. Running v21 goes to bootloader on boot and v20 gets stuck in a bootloop.

I have successfully removed Magisk after each attempt. Could anyone please figure out what is going wrong?

Displax commented 3 years ago

https://github.com/topjohnwu/Magisk/issues/844

onlycs commented 3 years ago

Is there any fix?

onlycs commented 3 years ago

Also what about this? https://mobile.twitter.com/topjohnwu/status/1008056655001468928?lang=en

I have a phh build. (Andy Yan)

onlycs commented 3 years ago

Edit: Got working, flash successful. But magisk manager says "Installed: N/A" and won't let me access modules.

Velosh commented 3 years ago

:/

onlycs commented 3 years ago

Latest Edit 2/23 How to Get Magisk Working on an Android 11-based GSI

Disclaimer

* I am not responsible for bricked devices, dead SD cards, thermonuclear war, 
* or you getting fired because the alarm app failed. Please do some research 
* if you have any concerns about features included in this tutorial
* before following it! YOU are choosing to make these modifications, and if
* you blame me in any way for what happens to your device, I will laugh at you.

Note - when you install magisk use 21.1 and then upgrade (if u want). Flashing above 21.1 will do weird things to the PATH (at least for me) and not let Magisk install be accessed by the manager. Don't upgrade to 21.4, it bootloops. I haven't tried 21.3, lmk if it works. The latest I have tested and confirmed is 21.1. make sure to get the old manager.

Part 0.5(Only if you have phhsu) Note: I haven't tried this myself. Also thanks to @hwti for help in getting rid of phhsu and it's files. If you are using this method, there is no need to do part 1 or part 2, just skip to bypassing SafetyNet if you want or be ok with just Magisk running.

  1. Run phh-securize.sh
  2. Go to TWRP
  3. Open the File Manager (Advanced>File Manager)
  4. Rename /system/bin/resetprop to /system/bin/phh-resetprop
  5. Adjust /system/bin/rw-system.sh and /system/bin/phh-prop-handler.sh to replace all cases of /system/bin/resetprop in those files to /system/bin/phh-resetprop
  6. Remove the SuperSu app(if installed) from /system/app/(package name)
  7. Flash Magisk 21.1 and reboot

Part 1: Flashing

  1. Reboot to TWRP
  2. Mount System
  3. Make The Directory /system_root/sbin
  4. Install Magisk v21.1!
  5. Reboot System

Part 2: Adding Stuff to PATH

  1. Get a Terminal Emulator (Or adb root then adb shell, but make sure you allow root debugging in settings)
  2. If using a Terminal Emulator, type su. Magisk will ask for root access, allow.
  3. Type echo $PATH, and copy output.
  4. Use a text editor that supports editing root files, or a terminal-based text editor if you are comfortable with one (nano, vim, etc.) to edit /init.environ.rc
  5. Edit it to look like this:
    # Stuff Here!!!
    on early-init
    export PATH /sbin:(echo $PATH output here)
    # Stuff Here!!!

Of course, replace the "(echo $PATH output here)" with the actual output you copied on Part 2, step 3. DO NOT USE PARENTHESES!!

For me, it looks like:

on early-init
    export PATH /sbin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
  1. Reboot

Part 3: Passing SafetyNet

  1. Install Riru from Magisk Manager and Reboot
  2. Install EdXposed Manager APK Here
  3. Get the Latest Alpha(non-debug)(SandHook) Download From the EdXposed Manager and flash in Magisk.
  4. Reboot. This next boot will be weird. It will successfully boot once, then go back to the boot logo, then go to lock screen again
  5. Now download+install the HiddenCore module from the EdXposed Manager. No need to flash in MM, the EdXposed Manager will do it. Now, there will be a notification asking you to 'Activate and Reboot'. Do so.
  6. SafetyNet should now be bypassed!

Tested on Andy Yan's LineageOS 18.1 using a Moto G8 Plus (Doha).

hwti commented 3 years ago

@dragonBall561, thank you for the workaround

In my case on Essential PH-1 with phh's Android 11 GSI , before creating /sbin, I had :

[   13.331584] init: cannot execv('/dev/Thu8xtl/magisk'). See the 'Debugging init' section of init's README.md for tips: Permission denied

So something doesn't work with the new installation path. Once the system is booted, the /dev/Thu8xtl/magisk can be executed, so I don't know what is the issue.

Then the PATH change allows /sbin/su (Magisk) to be used instead of /system/xbin/su (phh).

onlycs commented 3 years ago

If you have ANY su installed, uninstall it. Make sure to create /sbin before flashing Magisk.

Also make sure you flash v21.1 because older versions bootloop.

PS: I'm not very good at understanding error messages, I'm just a beginner.

hwti commented 3 years ago

It seems there are two issues :

So running phh-securize.sh (which requires a GSI able to be remounted rw, and needs to be adapted to Magisk >=21 depending on when we launch the script) to remove the builtin su fixes the second problem.

But the resetprop issue must be fixed first, else I lose root. Removing /system/bin/resetprop works, but it breaks the ROM use of the command in boot scripts (I don't know why the current Magisk resetprop doesn't seem to work). Renaming /system/bin/resetprop to phh-resetprop, and adjusting /system/bin/rw-system.sh and /system/bin/phh-prop-handler.sh works.

onlycs commented 3 years ago

Thanks I'll add it to the guide :) Also please lmn how to adjust /system/bin/rw-system.sh and /system/bin/phh-prop-handler.sh, or if I get it wrong in the guide.

hwti commented 3 years ago

@dragonBall561 You are doing too many things.

With the phh-securize.sh and the renaming to phh-resetprop, Magisk can be installed in the default Android 11 location, there is no need to create /sbin and modify PATH any more.

Running phh-securize.sh before installing Magisk is installed like you suggested is actually easier that what I had to do manually, but it requires TWRP (and for example people upgrading from an Android 10 GSI and keeping their patched boot image).

Ideally, Magisk shouldn't overwrite itself when there is a resetprop in the ROM and phh-su should avoid overwriting Magisk. Then the phh-securize.sh could be improved to work even when Magisk runs over phh-su, like I did for the previous install location.

lss4 commented 3 years ago

With the phh-securize.sh and the renaming to phh-resetprop, Magisk can be installed in the default Android 11 location, there is no need to create /sbin and modify PATH any more.

From what I tested on my Razer Phone 2 with Nusantara GSI (which is already securized), renaming to phh-resetprop is indeed mandatory but I'm still not sure about the creating of /sbin (I did anyway, and Magisk works).

Running phh-securize.sh before installing Magisk is installed like you suggested is actually easier that what I had to do manually, but it requires TWRP (and for example people upgrading from an Android 10 GSI and keeping their patched boot image).

Haven't tested this part as from my own experience, major upgrades from GSI to GSI is not straightforward and I usually just back things up with Migrate, make a clean flash, then restore the stuffs I have backed up once I verified everything important is working correctly.

Ideally, Magisk shouldn't overwrite itself when there is a resetprop in the ROM and phh-su should avoid overwriting Magisk. Then the phh-securize.sh could be improved to work even when Magisk runs over phh-su, like I did for the previous install location.

In case I really cannot do anything to the system partition (such as with the new Dynamic Partitioning), it's still necessary to look for ways to at least coexist with phh's resetprop.

UPDATE: With latest Magisk, there's no need to create /sbin anymore as Magisk can put itself to /bin if /sbin is not present. However, if your GSI has /sbin but it's not in $PATH (which is the case for some GSIs), you'll have to delete your /sbin, or Magisk will put itself there which cannot be accessed directly and will not work. As this requires you to modify your system partition, if you're having this issue on a non-vndklite GSI (which can't mount system r/w directly), you'll have to use another one. See #4309 for more information about this.

Skorpion96 commented 1 year ago

i am on an android 13 gsi with no sbin and no twrp, also my boot.img doesn't have a ramdisk, flashing magisk on recovery doesn't work neither, if i do the procedure and release buttons at logo i get into recovery anyway, could you please provide instructions on how to install magisk into the system partition? I tried as well magisk delta system install but it doesn't work on f2fs

Skorpion96 commented 2 months ago

may i say this is working on gsi with magisk 25.2:https://github.com/HuskyDG/magisk-files/issues/118#issuecomment-2381384721 i just had to add on init.rc a service to set selinux permissive and magisk delta init.rc, i also created sbin artificially on init and symlinked/sbin/magisk to /system/bin/su, i'll grab everything Init_magisk.txt instructions as well:Instructions.txt. Seems modules won't work, i can enable the tab by updating the app to magisk 27, NOT update magisk as well, but even if i install a module at reboot it won't properly load. Sad