[Guide] Magisk Modules Disabler for booting into Magisk core-only Mode

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
@zgfg you definitely did something wrong (or Magisk messed up your magisk_patched.img). Nothing in your ramdisk but my folder and a folder called "backup" and an init file. Why don't you upload your magisk_patch.img and let me try.
 
Last edited:

zgfg

Senior Member
Oct 10, 2016
4,549
1,954
233
@zgfg you definitely did something wrong. Nothing in your ramdisk but my folder and a folder called "backup" and an init file. Why don't you upload your magisk_patch.img and let me try.
Yes, before flagging ramdisk only had backup folder and init file - I added your overlay.d per instructions.
But patching with works perfect - just overlay.d is ignored and there is no Core Only mode - I just left it on the phone and continue ed to use (Android, Magisk and everything fully functioning)

Link to my boot image as it was patched by Magisk Canary 20407:
https://mega.nz/file/YhsREBYR#nL0VCgyed1bCs9cXYVLi0HdRh3TRi8lI5UJ2z98sON4

Link also to my stock boot image as originally extracted from the full OTA package (I didn't try to unpack yet by AIK to check its ramdisk content):
https://mega.nz/file/pociRQSS#3juycICtl6EwzWhT6NVE8WFBI37a0QZXvx0xIM_mpsA

Btw, as I edited my previous post, the same your method (so the same my PC environment and steps) works excellent on Huawei P9, stock Oreo - however, its ramdisk folder (unpacked image) is full of stuff

Thank you for your prompt help and interest
 
  • Like
Reactions: Tecalote

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
Yes, before flagging ramdisk only had backup folder and init file - I added your overlay.d per instructions.
But patching with works perfect - just overlay.d is ignored and there is no Core Only mode - I just left it on the phone and continue ed to use (Android, Magisk and everything fully functioning)

Link to my boot image as it was patched by Magisk Canary 20407:
https://mega.nz/file/YhsREBYR#nL0VCgyed1bCs9cXYVLi0HdRh3TRi8lI5UJ2z98sON4

Link also to my stock boot image as originally extracted from the full OTA package (I didn't try to unpack yet by AIK to check its ramdisk content):
https://mega.nz/file/pociRQSS#3juycICtl6EwzWhT6NVE8WFBI37a0QZXvx0xIM_mpsA

Btw, as I edited my previous post, the same your method (so the same my PC environment and steps) works excellent on Huawei P9, stock Oreo - however, its ramdisk folder (unpacked image) is full of stuff

Thank you for your prompt help and interest
Something wrong with your magisk_patched.img. Install a stable version of magisk and try again.

Edit: no, it's your boot.img. there is nothing in your ramdisk.

Edit2: You need to find a different method of unpacking your boot image. I don't see your phone as being one that is supported for osmosis's method.
 
Last edited:
  • Like
Reactions: Tecalote

zgfg

Senior Member
Oct 10, 2016
4,549
1,954
233
Something wrong with your magisk_patched.img. Install a stable version of magisk and try again.

Edit: no, it's your boot.img. there is nothing in your ramdisk.
This is not "my" boot.img (second link in my previous post) but Xiaomi's stock boot image

You could patch it yourself by Magisk Manager, you will get the same as was my patched image (first link)

Or you could download the whole official firmware (Mi 9T, QFJEUXM 11.0.5 EEA Stable) and unzip to extract the original boot.img:
https://mirom.ezbox.idv.tw/en/phone/davinci/

I don't see a wrongdoing from my side ?

Thank you for your thoughts anyway

EDIT: Could you please suggest what else to add (if misssing from the stock and hance also patched and flagged ramdisk unpacked folders), to make it properly execute the shell script in overlay.d)
 
Last edited:
  • Like
Reactions: Tecalote

zgfg

Senior Member
Oct 10, 2016
4,549
1,954
233
This is not "my" boot.img (second link in my previous post) but Xiaomi's stock boot image

You could patch it yourself by Magisk Manager, you will get the same as was my patched image (first link)

Or you could download the whole official firmware (Mi 9T, QFJEUXM 11.0.5 EEA Stable) and unzip to extract the original boot.img:
https://mirom.ezbox.idv.tw/en/phone/davinci/

I don't see a wrongdoing from my side ?

Thank you for your thoughts anyway

EDIT: Could you please suggest what else to add (if misssing from the stock and hance also patched and flagged ramdisk unpacked folders), to make it properly execute the shell script in overlay.d)
Following up, I just unpacked (and later successfully repacked) stock recovery.img from the same Xiaomi Mi 9T and obtained the full ramdisk folder here:
https://mega.nz/file/sp83WCTR#46xihtEltppMoj2CLm2nYOjvoNMW35-5ZcFr83cD4PY

Maybe the expected stuff "missing" from ramdisk folder in boot.img is here (screenshot)?!

But stock recovery can be replaced by TWRP (or Orange Fox), and MIUI still boots and works just fine then, hence it doesn't miss all this stuff that is in ramdisk folder in the stock recovery image
 

Attachments

Last edited:

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
Following up, I just unpacked (and later successfully repacked) stock recovery.img from the same Xiaomi Mi 9T and obtained the full ramdisk folder here:
https://mega.nz/file/sp83WCTR#46xihtEltppMoj2CLm2nYOjvoNMW35-5ZcFr83cD4PY

Maybe the expected stuff "missing" from ramdisk folder in boot.img is here (screenshot)?!

But stock recovery can be replaced by TWRP (or Orange Fox), and MIUI still boots and works just fine then, hence it doesn't miss all this stuff that is in ramdisk folder in the stock recovery image
A person can boot TWRP so try putting the overlay.d folder in your stock recovery image and boot that.
 

zgfg

Senior Member
Oct 10, 2016
4,549
1,954
233
A person can boot TWRP so try putting the overlay.d folder in your stock recovery image and boot that.
If using TWRP, then TWRP is in recovery partition, no more stock recovery - so I don't see how TWRP can inject overlay.d to the stock recovery image

Or you meant by TWRP to inject overlay.d to the boot image - but TWRP also cannot unpack boot to reach the ramdisk folder (and to repack)

Btw, whatever it was in the stock recovery is gone and is not really needed for the system (except for OTA when it comes), because happily using (official by twrp.me) TWRP instead

I can only manually add empty ".disable_magisk" file to /cache, by using TWRP - then it will boot to Safe node but it is mo more about this method :)

Anyway, thank you for the feedback

Asking if maybe @osm0sis could also take a look and advice what to add to the patched Magisk boot image to let the overlay.d script properly execute and force Magisk to boot to the Safe mode

I can test and provide logs if possible - thanks all

A person can boot TWRP so try putting the overlay.d folder in your stock recovery image and boot that.
Sorry, did you think I should unpack stock boot.img, put overlay.d there to the ramdisk folder, repack and flash - but then it will not boot to Magisk (?)
 
Last edited:

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
If using TWRP, then TWRP is in recovery partition, no more stock recovery - so I don't see how TWRP can inject overlay.d to the stock recovery image
If you have TWRP, there is no need for this at all. In TWRP file manager you delete the bad module and reboot.

I would think you would still be able to "boot" a modded stock recovery image. This would possibly install the .disable_magisk file and you would just restart your phone after booting it.

Edit: tried on a Nexus 5X and it didn't work...
 
Last edited:

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,234
263
Halifax
TWRP is run from memory, so on A/B devices with boot-as-recovery (TWRP in the boot partition) you can of course dump the partition and modify to add /overlay.d to the ramdisk and it'll be there next boot. AK3 could be used to do this on-the-fly. :good:
 

zgfg

Senior Member
Oct 10, 2016
4,549
1,954
233
If you have TWRP, there is no need for this at all. In TWRP file manager you delete the bad module and reboot.

I would think you would still be able to "boot" a modded stock recovery image. This would possibly install the .disable_magisk file and you would just restart your phone after booting it.

Edit: tried on a Nexus 5X and it didn't work...
Ofc, I can manipulate /data/adb/ from TWRP and I know how.
I don't have a bootloop either - I clearly wrote all that in my first post, sorry if you overlooked.
I also wrote that adb wait-for-devices shell magisk -remove-modules works, too, so plenty of other options to resolve a potential bootloop

I'm just interested to see if this method can be made to work also on this device - ie, to see how to make the script from overlay.d to properly execute .
It's not a life or death situation, but it may help to improve the method to help for other devices without TWRP and where adb shell magisk does not work at the time before Magisk starts booting modules

TWRP is run from memory, so on A/B devices with boot-as-recovery (TWRP in the boot partition) you can of course dump the partition and modify to add /overlay.d to the ramdisk and it'll be there next boot. AK3 could be used to do this on-the-fly. :good:
Thanks, interesting.
However, Xiaomi devices are not A/B, I have both boot and recovery (so I put Magisk to boot and TWRP to recovery), and system is not read-only (although system partition is almost full so it is highly recommended to force systemless), albeit it is Android 10 - hence some strange mix of new and old stuff :)
 

ErriK89

Senior Member
Oct 19, 2010
66
17
28
Milan
Hi all, I'm trying to build magisk core patched img but I cannot do it because maybe I'm not extracting properly boot.img
Is there anyone that can do the build for me? In case I will share patched_boot.img
 

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
Hi all, I'm trying to build magisk core patched img but I cannot do it because maybe I'm not extracting properly boot.img
Is there anyone that can do the build for me? In case I will share patched_boot.img
Go to the linked folder in the op and use that one....

Edit: never mind, you have a different phone. Sure, upload your magisk_patched.img.
 
Last edited:

eduuk

Member
Nov 2, 2018
27
9
0
If anyone wants to experiment with this idea, here's the basic setup I used for my boot.img to fully reset the /data/adb directory for the soft brick issue (related to a magisk.db failure) I was seeing in the last canary.

Unpack the current magisk_patched.img for your device using my Android Image Kitchen (AIK) project, then create:

ramdisk/overlay.d/init.resetmagisk.rc:
Code:
on post-fs-data
    exec u:r:magisk:s0 root root -- /sbin/init.resetmagisk.sh
ramdisk/overlay.d/sbin/init.resetmagisk.sh:
Code:
#!/system/bin/sh
rm -rf /data/adb/* && reboot
So, pretty simple stuff, and I'm sure it could be applied to some sort of Core Only workaround until @topjohnwu decides what he wants to do with all those Core Only boot.img Pull Requests. :cowboy:
Attempted something even easier with no success. Further info at https://github.com/topjohnwu/Magisk/issues/2978
 
Sep 12, 2019
8
0
0
Losing my mind. Help is appreciated.

So I am in the situation of
1. not having TWRP, not being able to boot into it.
2. and having lost root probably because of some faulty magisk module.
3. My device is booting into fastboot since a crash, probably caused by faulty module.

I recovered the stock boot image via fastboot. I can boot my device. Without root privileges.
I tried to patch the stock boot image with magisk Manager.
I flashed the magisk_patched.img via fastboot. Result: Again the device boots into fastboot mode and not into os.

I unpacked and repacked the magisk_patched.img as you describe here. To no avail. As soon as I flash the patched boot image, the device boots into fastboot instead of os.

OP7P GM1913, Android 10 OOS 10.0.9

This is really frustrating and I am stuck. Do you have any Ideas?
 

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,835
5,535
253
So I am in the situation of
1. not having TWRP, not being able to boot into it.
2. and having lost root probably because of some faulty magisk module.
3. My device is booting into fastboot since a crash, probably caused by faulty module.

I recovered the stock boot image via fastboot. I can boot my device. Without root privileges.
I tried to patch the stock boot image with magisk Manager.
I flashed the magisk_patched.img via fastboot. Result: Again the device boots into fastboot mode and not into os.

I unpacked and repacked the magisk_patched.img as you describe here. To no avail. As soon as I flash the patched boot image, the device boots into fastboot instead of os.

OP7P GM1913, Android 10 OOS 10.0.9

This is really frustrating and I am stuck. Do you have any Ideas?
Flash your magisk_patched.img. in a command window, before it boots into fastboot, run this:

adb wait-for-device shell magisk --remove-modules

If that doesn't work, this works for some:

1. adb reboot bootloader
2. fastboot flash boot magisk_patched.img
3. Powered off phone completely
4. Powered on phone and as soon as I saw the G logo pressed and held Volume Down until it boots into Safe Mode
5. Phone eventually booted into Safe Mode as noted by lower left of your screen. You aren't able to access anything magisk related in here but we did just disable magisk modules for the next normal boot!
6. Reboot
 
Sep 12, 2019
8
0
0
Flash your magisk_patched.img. in a command window, before it boots into fastboot, run this:

adb wait-for-device shell magisk --remove-modules
This does not work. The phone goes into fastboot mode after a while.

If that doesn't work, this works for some:
1. adb reboot bootloader
2. fastboot flash boot magisk_patched.img
3. Powered off phone completely
4. Powered on phone and as soon as I saw the G logo pressed and held Volume Down until it boots into Safe Mode
5. Phone eventually booted into Safe Mode as noted by lower left of your screen. You aren't able to access anything magisk related in here but we did just disable magisk modules for the next normal boot!
6. Reboot
This also fails.

Yet, I managed to boot into a working version of TWRP. I deleted some magisk modules that I installed prior to the error.
It did not help. Still landing into fastboot.
 
Sep 12, 2019
8
0
0
This does not work. The phone goes into fastboot mode after a while.


This also fails.

Yet, I managed to boot into a working version of TWRP. I deleted some magisk modules that I installed prior to the error.
It did not help. Still landing into fastboot.
Selfreply as I found a solution. Maybe useful to others.

1. I restored the stock boot.img by flashing it via fastboot.
2. Since all attempts to patch it with Magisk and flash it lead into fastboot/bootloop, I decided to remove the magisk folders via TWRP.
3. Then i booted into the unrooted stock OS. There I once again flashed the latest update.zip of the os. I am on OOS 10.0.9 EU.
4. I downloaded the lastest magisk.zip and flashed it via TWRP. Trying to boot into the patched boot image did not work at first but did eventually work the second time, so repeat 1,2 and 3 if you are back at fastboot looping.
5. Once booted into the OS i uninstalled the persisting Magisk Manager and installed the new .apk
6. From there Magisk did the final steps to install and there I was again, rooted.

Classical case of "it works and I don´t know why". Boy, what a night. Also I am a noob.