topjohnwu / Magisk

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

Nothing installed in Lineage /system/addon.d/ via Magisk app Direct Install + fix_env #3820

Open mdoggydog opened 3 years ago

mdoggydog commented 3 years ago

I installed Magisk by using the "patch boot.img and flash with fastboot" method, since the installation instructions say that using the installer zip via a custom recovery is no longer recommended. On the next LineageOS OTA update, Magisk was not preserved, and I had to manually patch the boot.img and flash with fastboot again.

I discovered that /system/addon.d/99-magisk.sh was never installed, thus the OTA update would have no way to preserve Magisk.

Digging through the code, it appears that /system/addon.d/99-magisk.h is only installed when a Magisk installer zip is used via a custom recovery.

A related problem: even if Magisk is initially installed via installer-zip/custom-recovery, it appears that updating Magisk via the MagiskManager app will never update an existing /system/addon.d/99-magisk.sh either.

This issue is basically a duplicate of #3782, which I think got prematurely closed because I did not explain the problem well enough the first time. Please see my last comment in #3782 for more analysis of this problem.

osm0sis commented 3 years ago

It's supposed to install at some point via the app Direct Install too: https://github.com/topjohnwu/Magisk/blob/cd96454886852917a6fcbe1e4da4246e2aaffac6/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt#L133-L134

There was a plan to remove the unneeded installer code duplication and have everything run and maintained in one place via the shell scripts, but I'm not sure where that's at now.

mdoggydog commented 3 years ago

Yep... all the bits are there. This probably needs just a one- or two-line fix MagiskInstaller.kt, along the lines of cp /data/adb/addon.d.sh /system/addon.d/99-magisk.sh spelled the correct way (well, after testing if the /system/addon.d/ directory exists). But maybe there is some tricky subtlety involving security contexts or file ownership or something; this android system-level stuff is all new to me.

Half of the lines of code in https://github.com/topjohnwu/Magisk/blob/b6643b7bfcb05b81fc10dc786bc7ad073e581d69/scripts/flash_script.sh#L78-L85 are just ensuring that the target directory exists and is writable; I don't know if the writeability is an issue outside of the recovery environment.

osm0sis commented 3 years ago

So looks like this was intentional. John said "I do not want to involve system rw at anytime during boot. This just opens up a whole can of worms..."

I won't close this as #wontfix since he may still change his mind. It would just need to use Magisk's own system mirror and rw it if the addon.d directory exists. 🤞

mdoggydog commented 3 years ago

I'm sorry if I'm missing something, but I just don't understand that comment in the context of this bug report, which is about install-time not boot-time. The essential core of this issue is:

That means that some devices out there are getting 99-magisk.sh and some are not, and it only depends on how the user decided to install Magisk (and in neither case does this installation happen at boot time).

How does "system rw at anytime during boot" come into this?

mdoggydog commented 3 years ago

(To rephrase again: logically, either 99-magisk.sh should be installed, or it shouldn't, so either MagiskInstaller.kt has a bug, or the .zip installer has a bug. And people installing via the .zip do not seem to be complaining....)

osm0sis commented 3 years ago

He means "while booted", hopefully that clears up the context for you.

mdoggydog commented 3 years ago

Ohhhhhhh! Yes, that clears it up a lot! Thank you! I now understand why it is the way it is right now.

It would be really nice if this difference between the two installation methods was mentioned in the installation documentation (https://topjohnwu.github.io/Magisk/install.html), because it is a pretty significant difference in behavior for a ROM that supports addon.d. One way, Magisk magically survives future OTA updates; the other way, the user has to manually intervene before the next reboot....

(In any case, at least the next confused schmuck like me that is trying to figure out what is going on will have this bug report to stumble upon. :^))

Tremolo4 commented 3 years ago

Could this issue appear as well when updating magisk through the app, after having initially installed via zip?

And is the only result that Magisk is not installed after the update?

Context: Me and other users of my device (beryllium) recently started getting bootloops after each system update. Reflashing the same system update (1), opengapps (2) and Magisk zip (3) fixes it, I'm trying to rule out Magisk.

I'm thinking maybe we were getting the bootloops because of an outdated 99-magisk.sh, since it was never updated during magisk update via magiskmanager.

twu2 commented 3 years ago

please re-open issue #3908 , I think it's different issue with this.

outloudvi commented 3 years ago

Hi. Just reporting that the survival script worked through manual LineageOS zip flashing after a fresh install of Magisk 22. Previously since several weeks (I think maybe 5-6) ago the survival script had stopped working on my device, even after uninstalling and re-flashing Magisk's latest 21. LineageOS version is 17.1.

ElCoyote27 commented 3 years ago

I think I'm also seeing this on LOS: https://github.com/topjohnwu/Magisk/issues/4394 Magisk doesn't install on LOS 18.1 and 17.1 unless an old zip is used.

brianjmurrell commented 3 years ago

Digging through the code, it appears that /system/addon.d/99-magisk.h is only installed when a Magisk installer zip is used via a custom recovery.

But I did install Magisk by flashing the ZIP (even though it's reported as not being supported, however the boot patching is just too much of a palaver IMHO -- #4172) from TWRP on my Oneplus 6 (A/B device) running LineageOS 18.1 and Magisk did not survive the OTA update.

Given that I have an A/B device and OTA updating LineageOS on that also updates the recovery to use the LineageOS recovery, can the Magisk apk->zip be flashed with Lineage recovery? I'm not at all familiar with Lineage recovery and have always used TWRP.

osm0sis commented 3 years ago

addon.d-v2 is only guaranteed to work from a booted OTA. Lineage intentionally didn't want it working in recovery and TWRP only has it working in the _9 branch with some hacks I suggested currently.

brianjmurrell commented 3 years ago

@osm0sis I'm afraid I'm not up-to-speed enough to know what all of that means.

What are my options for installing Magisk on my LineageOS 18.1 flashed Oneplus6 (A/B device)? Only TWRP and Patching Images?

Will either survive a LineageOS Updater OTA update?

osm0sis commented 3 years ago

For Magisk addon.d script to install it must currently be installed from recovery, then if you have an A/B device (i.e. addon.d-v2) then the only way to be sure the addon.d script runs is to do the OTA through the system settings updater app.

brianjmurrell commented 3 years ago

@osm0sis That's what I did the last time. Almost. :-) However I used TWRP recovery instead of Lineage Recovery. Are you saying that if I flash with Lineage Recovery (i.e. adb sideload Magisk-v23.0.zip) it will survive future OTA updates?

osm0sis commented 3 years ago

Hmm I believe either recovery should work. It can still install the addon.d script to /system in Lineage Recovery last time I checked.

But the Magisk apk must be flashed in recovery for the addon.d script to be installed. If it's not working after that then there's something else weird going on, separate from this issue.

qouoq commented 3 years ago

Non A/B device (Xiaomi Mi 5 - gemini) and unsure how relevant my case is, my recent experience is that starting from Magisk flashed through recovery (following the official supported install procedure), it survives through OTA with TWRP as recovery, but not through OTA with LOS as recovery.

brianjmurrell commented 3 years ago

So I did install via Lineage Recovery and adb sideload Magisk-v23.0.zip and while flashing it did do all sorts of stuff and said it was successful at the end but looking in the Magisk app on the device it says "Installed N/A" but also says "A/B No" but we know that's not true for a Oneplus 6.

In the Magisk app though, Check SafetyNet does seem to pass but Google Pay is still saying my device is not supported even after a force stop, clear cache, clear storage. Google Pay was working the last time I flashed with TWRP on LineageOS 18.1.

ElCoyote27 commented 3 years ago

My recent (a few hours) experience is that 22.x and 23.x do not survive an OTA update of LOS. In order to do that, I had to wipe and downgrade to 21.4 without updating Magisk after that.

ossilator commented 3 years ago

on my klte (non-a/b), v23 (installed via TWRP) survives LOS 18.1 OTA updates.

osm0sis commented 3 years ago

Not sure why regular addon.d (i.e. A-only devices) wouldn't work in LOS Recovery, but, again, that's a different issue from this.

Edit: Oh wait, I know why, LOS Recovery doesn't support decrypting /data. 😛

Well known if you check the logs: https://github.com/topjohnwu/Magisk/blob/master/scripts/addon.d.sh#L39-L40

So yeah probably TWRP only for A-only too.

Rihcus commented 3 years ago

@osm0sis I'm afraid I'm not up-to-speed enough to know what all of that means.

What are my options for installing Magisk on my LineageOS 18.1 flashed Oneplus6 (A/B device)? Only TWRP and Patching Images?

Will either survive a LineageOS Updater OTA update?

Normally no but you have 3 options (ranked from easiest to hardest):

1) open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

2) Reflash the magisk apk (rename to APK to zip) via lineage recovery (same process of flashing gapps) or flash with TWRP

  1. Download and extract the boot.img from lineage os repatch with magisk manager, enter fast boot and flash (this is the most time consuming method and I personally use it as a last resort for updates).

All three methods will retain magisk preferences and modules. Hope this helps (tested lineage os 18.1 OnePlus 8)

Additional recourses:

https://topjohnwu.github.io/Magisk/install.html

brianjmurrell commented 3 years ago

Normally no

That's a pity.

  1. open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

What do you mean exactly by "magisk should be present along with your modules and settings"? Present where?

2shrestha22 commented 3 years ago

Facing same issue, I need to repeatedly pull boot.img patch and flash after Lineage OS OTA each week. Isn't anything possible to do like previous methods where we don't need to re-path boot image after each update?

2shrestha22 commented 3 years ago

open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

@Rihcus I didn't see any options like Install after OTA in recent Magisk Manager version.

Rihcus commented 3 years ago

open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

@Rihcus I didn't see any options like Install after OTA in recent Magisk Manager version.

https://i.imgur.com/FPznfOU.png

https://i.imgur.com/wj2RHvd.jpg

Are you using the latest build of magisk manager and magisk? Also does your device support A/B?

Rihcus commented 3 years ago

Normally no

That's a pity.

  1. open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

What do you mean exactly by "magisk should be present along with your modules and settings"? Present where?

Basically all your settings in magisk will remain intact as will any other add-ons (in magisk manager and magisk hide).

In other words you won't have to set up magisk every time from scratch when updating with install after OTA (sorry if not clear)

brianjmurrell commented 3 years ago

What do you mean exactly by "magisk should be present along with your modules and settings"? Present where?

Basically all your settings in magisk will remain intact as will any other add-ons (in magisk manager and magisk hide).

Understood. But that doesn't answer the actual question asked, which I left quoted above. Does "present" mean the manager app is installed, or does it mean the .apk is available somewhere? Is it left .apk or should it be renamed .zip?

In other words you won't have to set up magisk every time from scratch when updating with install after OTA (sorry if not clear)

Again, also understood. What is not understood is what the phrasing "magisk should be present along with your modules and settings"? Present where and in what form?

Rihcus commented 3 years ago

What do you mean exactly by "magisk should be present along with your modules and settings"? Present where?

Basically all your settings in magisk will remain intact as will any other add-ons (in magisk manager and magisk hide).

Understood. But that doesn't answer the actual question asked, which I left quoted above. Does "present" mean the manager app is installed, or does it mean the .apk is available somewhere? Is it left .apk or should it be renamed .zip?

In other words you won't have to set up magisk every time from scratch when updating with install after OTA (sorry if not clear)

Again, also understood. What is not understood is what the phrasing "magisk should be present along with your modules and settings"? Present where and in what form?

By magisk I meant both the magisk manager app and the modified boot.img (the part which magisk manager uses to allow root access to other apps and magisk modules) will remain installed. You will not need to reinstall the magisk manager APK knor re modify the boot.img (whether that be through flashing the magisk managerAPK as . zip or flashing the boot.img via fast boot).

Infact all install after OTA does is reapply the modified boot.img which was overwriten by lineage OTA updater.

mdoggydog commented 3 years ago

Perhaps it would be a good idea to open a new bug report for whatever this new bug is, and move this discussion there?

This issue here is pretty specific ("nothing installed in /system/addon.d/ via..."), and is still open to track that specific issue (which is that the addon.d scripts --- whether or not they work --- are only installed in specific installation workflows).

brianjmurrell commented 3 years ago

Perhaps it would be a good idea to open a new bug report for whatever this new bug is, and move this discussion there?

If it's a different problem, sure? But is it? I don't honestly know.

This issue here is pretty specific ("nothing installed in /system/addon.d/ via..."), and is still open to track that specific issue (which is that the addon.d scripts --- whether or not they work --- are only installed in specific installation workflows).

But how do we know my issue is not in fact being caused by that also?

2shrestha22 commented 3 years ago

open magisk manager before starting lineage os updater (important), minimize magisk manager and run lineage os updater do not reboot when prompted, go back to magisk manager click install magisk and click install after OTA and reboot when prompted (magisk should be present along with your modules and settings)

@Rihcus I didn't see any options like Install after OTA in recent Magisk Manager version.

https://i.imgur.com/FPznfOU.png

https://i.imgur.com/wj2RHvd.jpg

Are you using the latest build of magisk manager and magisk? Also does your device support A/B?

I am using latest Magisk Manager Build and my device doesn't support A/B.

osm0sis commented 3 years ago

It is a different issue. You guys need to stop using this as a help thread. Go use xda for troubleshooting. I'll lock this if you're not contributing anything to resolve this specific issue going forward.

Iey4iej3 commented 3 years ago

Hmm I believe either recovery should work. It can still install the addon.d script to /system in Lineage Recovery last time I checked.

But the Magisk apk must be flashed in recovery for the addon.d script to be installed. If it's not working after that then there's something else weird going on, separate from this issue.

I don't know whether the following is acceptable: producing a flashable zip file which includes the patched boot image and the necessary addon.d script, and letting the user flash it manually in the recovery?

christophehenry commented 1 year ago

So… Wait… If zip installation — which installs the addon.d script — is deprecated and boot.img flash with fastboot doesn't install the addon.d script, what is the correct way to have Magisk survive the updates? I don't think it is explained in the documentation. Are we supposed to reflash Magisk with adb after each update? This feels like a regression, no?

2shrestha22 commented 1 year ago

So… Wait… If zip installation — which installs the addon.d script — is deprecated and boot.img flash with fastboot doesn't install the addon.d script, what is the correct way to have Magisk survive the updates? I don't think it is explained in the documentation. Are we supposed to reflash Magisk with adb after each update? This feels like a regression, no?

It is explained in documentation that for non A/B devices user must reinstall Magisk. https://topjohnwu.github.io/Magisk/ota.html

qouoq commented 1 year ago

Alternatively one could copy scripts/addon.d.sh to /system/addon.d/99-magisk.sh after having flashed a patched image. I did that two months ago and my two following updates (through TWRP) have preserved Magisk.

Needed to make /system writeable, which I did with Termux and mount --remount / -w, but maybe that would be safer to copy the file in TWRP.

osm0sis commented 1 year ago

confirmed = current behavior isn't as expected. And the recovery zip still works perfectly though isn't the recommended install method anymore.

SPYazdani commented 1 year ago

 Hi $contact_first_name $contact_last_name, We've received your case $acase_name (# $acase_case_number) on $acase_date_entered Status$acase_statusReference$acase_case_numberDescription$acase_description On 05/09/2022, 03:58, @.*** wrote:confirmed = current behavior isn't as expected, and the recovery zip still works perfectly though isn't the recommended install method anymore.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @github.com>

qouoq commented 1 year ago

Would it make sense to update the install documentation to mention either or both of these methods (zip install / manual copy of addon.d script) for non A/B devices ?

SPYazdani commented 1 year ago

 Hi $contact_first_name $contact_last_name, We've received your case $acase_name (# $acase_case_number) on $acase_date_entered Status$acase_statusReference$acase_case_numberDescription$acase_description On 06/09/2022, 03:17, @.*** wrote:Would it make sense to update the install documentation to mention either or both of these methods (zip install / manual copy of addon.d script) for non A/B devices ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @github.com>

osm0sis commented 1 year ago

Zip still works on A/B as well.

This issue exists and is open because copying the addon.d script should be part of the Direct Install option in the app, and when fix_env runs after first install via a patched boot.img. The goal is feature parity.

P.S. Spam bot reported. 🙄

SPYazdani commented 1 year ago

 Hi $contact_first_name $contact_last_name, We've received your case $acase_name (# $acase_case_number) on $acase_date_entered Status$acase_statusReference$acase_case_numberDescription$acase_description On 06/09/2022, 05:10, @.*** wrote:It still works on A/B as well.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented. Message ID: @github.com>

infinity0 commented 1 year ago

My own /system/addon.d/99-magisk.sh exists but is empty. When installing via recovery, writing to /system using cp fails silently because the disk is full, even if you make it writable and use blockdev --setrw. (You can see the error via adb push however, again in recovery, also echo a > /mnt/system/xxx does fail.) In other words, the current technique is also busted even when it is active.

I'm using LineageOS 19.1 (Android 12) with MicroG on a OnePlus 8T (KB2003), it is an A/B device. Issue originally uncovered at arovlad/bromite-webview-overlay#5.

OTA A/B install previously worked on LineageOS 18.1 (Android 11) but I never explicitly checked if /system/addon.d/99-magisk.sh was empty or not; I assume it wasn't and something new in Android 12 is making this fail.

infinity0 commented 1 year ago

OTOH, the file is fine on a OnePlus 5T (without A/B) running LineageOS 19.1 (Android 12) without MicroG with MindTheGapps, so maybe it is a MicroG issue or a device-specific issue or an issue specific to A/B, I will investigate further.

Still, Magisk may want to detect that cp has failed (e.g. by checking the file isn't size 0) and warn the user, as it seems the busybox implementation of cp is a bit broken in this regard. The core root functionality works though.

infinity0 commented 1 year ago

LineageOS devs tell me the reason is because MicroG sets WITH_GMS = true leading to lack of extra space in the system partition, so that makes sense, I'll follow this up with them. As I said though Magisk might still want to explicitly detect the failure.

vvb2060 commented 1 year ago

This should be expected behavior, i.e. addon.d will only be written if installed via recovery. However, I think writing to the system partition is a bad idea, even in recovery.

vvb2060 commented 1 year ago

addon.d script is part of the recovery installation. When you patch boot image, it has been indicated that you don't need addon.d script because you don't use custom recovery.

osm0sis commented 1 year ago

I disagree. If /system/addon.d is detected during installation of any type then there should be feature parity, especially considering the installation instructions list recovery installs as deprecated.

These are custom ROMs that allow system rw for GApps so writing to system should not be concerning.