Rooting with Magisk does not modify the system partition the way older root methods did. Instead, it patches the boot image itself and injects its files at boot time, which keeps the system partition untouched and lets you pass most SafetyNet and Play Integrity checks that older root methods failed outright. The flashing step is short, but getting the source file and the slot targeting wrong is where most failed attempts happen.
Magisk patches an existing boot image; it does not create one from nothing. You need the stock boot.img that matches your device's exact current firmware build — not an older or newer version, since the boot image is tightly coupled to the kernel and vendor partition it will run alongside. This comes from one of two places:
payload.bin as most current factory images are.fastboot, if you know the currently active slot (see below), which guarantees an exact match to what is actually running.Copy the stock boot.img onto the device's internal storage (adb push boot.img /sdcard/), open the Magisk app, and select Install > Select and Patch a File, pointing it at the copied image. Magisk produces a new file, typically named magisk_patched-<version>-<random>.img, in the Download folder. Pull this back to your PC:
adb pull /sdcard/Download/magisk_patched-XXXXX.img .
On A/B devices, flashing the patched boot image to the wrong slot leaves the currently running slot unpatched and does nothing, or worse, on some devices leaves the inactive slot in a state that fails verified boot on the next slot switch. Check the active slot before flashing:
fastboot getvar current-slot
This returns a or b. Flash to the same slot that is currently active — you generally do not want to patch the inactive slot, since it will be overwritten by the next OTA update anyway and patching it accomplishes nothing until you manually switch to it.
fastboot flash boot magisk_patched-XXXXX.img
On a device with named slots, Fastboot appends the active slot automatically when you omit an explicit slot suffix, so this command alone is correct for most cases. If you need to target a slot explicitly:
fastboot flash boot_a magisk_patched-XXXXX.img
Reboot normally afterward with fastboot reboot. Do not run fastboot -w or wipe userdata as part of this process — a Magisk patch does not require a data wipe, and unlike a full ROM flash, adding one here only causes unnecessary data loss.
After the device finishes booting, open the Magisk app. It should report itself as installed with a version number rather than showing the "not installed" state. A quick functional check is running a root-requiring command over ADB:
adb shell su -c id
This should return output including uid=0(root). If it instead prompts for a permission grant on the device screen the first time, that is expected — approve it, and subsequent calls will not prompt again for that same requesting app or shell session.
A boot loop after flashing a patched image almost always traces back to one of two causes: the stock boot.img did not actually match the currently installed firmware build, or the patch was applied by a Magisk version incompatible with that Android release. Recovery is straightforward since the system partition was never touched — boot back into Fastboot and reflash the original, unpatched boot.img for the active slot, which restores the device to its pre-root state exactly.
Because Magisk patches the boot image rather than the system partition, a standard OTA update overwrites the patched boot image with an unpatched stock one on the inactive slot, which silently removes root the next time the device switches slots after the update installs. Magisk's own app includes an "Install to Inactive Slot" option specifically for this: after an OTA downloads but before the device reboots to apply it, running this option re-patches the newly updated boot image on the inactive slot in place, so root survives the update instead of needing to be redone manually from a PC every time.
Older or budget devices without A/B seamless updates only have a single boot partition rather than boot_a/boot_b, which simplifies this process since there is no slot to determine beforehand. On these devices, fastboot getvar current-slot returns nothing meaningful (or an error), and the plain fastboot flash boot magisk_patched-XXXXX.img command targets the only boot partition that exists, with no slot suffix ever needed.