If you already have Magisk installed, it is strongly recommended to upgrade directly via the Magisk app using its “Direct Install” method. The following tutorial is only for the initial installation.
Before you start:
adb and fastbootDownload and install the latest Magisk app. In the home screen, you should see:

The result of Ramdisk determines whether your device has ramdisk in the boot partition. If your device does not have boot ramdisk, read the Magisk in Recovery section before continuing.
(Unfortunately, there are exceptions as some devices’ bootloader accepts ramdisk even if it shouldn’t. In this case, you will have to follow the instructions as if your device’s boot partition does include ramdisk. There is no way to detect this, so the only way to know for sure is to actually try. Fortunately, as far as we know, only some Xiaomi devices are known to have this property, so most people can simply ignore this piece of information.)
If you are using a Googlebook or a Samsung device, you can now jump to the Googlebooks or Samsung Devices section.
If your device has boot ramdisk, you need to patch the partition image that contains the ramdisk (boot.img, init_boot.img, or vendor_boot.img).
If your device does NOT have boot ramdisk, you need to patch recovery.img.
You can either extract the raw .img file yourself, or provide the full official firmware package (OTA .zip, payload.bin, or factory image .zip), or even a direct HTTPS link to it and let the Magisk app extract the target image automatically.
Quick recap, at this point, you should have known and prepared:
boot.img, init_boot.img, vendor_boot.img, or recovery.img) based on (1)Let’s continue to Patching Images.
.img (boot.img, init_boot.img, vendor_boot.img, recovery.img), an OTA .zip / payload.bin, or a factory image .zip.zip, factory image .zip, or .img file to stream and extract the target image on the fly without downloading the full archive firstadb pull /sdcard/Download/magisk_patched-[version]_[random_strings].imgfastboot flash boot /path/to/magisk_patched-[version]_[random_strings].img or fastboot flash init_boot /path/to/magisk_patched-[version]_[random_strings].img or fastboot flash vendor_boot /path/to/magisk_patched-[version]_[random_strings].img or fastboot flash recovery /path/to/magisk_patched-[version]_[random_strings].img vbmeta partition, you can patch the vbmeta partition with command:fastboot flash vbmeta --disable-verity --disable-verification vbmeta.img (note that it may wipe your data)Warning: NEVER flash patched image shared by others or patch image on another device even if they have the same device model! You may need to do a full data wipe to recover your device. ALWAYS patch boot image on the same device where you want to install Magisk.
The easiest way to uninstall Magisk is directly through the Magisk app. If you insist on using custom recoveries, rename the Magisk APK to uninstall.zip and flash it like any other ordinary flashable zip.
In the case when your device does not have ramdisk in boot images, Magisk has no choice but to hijack the recovery partition. For these devices, you will have to reboot to recovery every time you want Magisk enabled.
When Magisk hijacks the recovery, there is a special mechanism to allow you to actually boot into recovery mode. Each device model has its own key combo to boot into recovery, as an example for Galaxy S10 it is (Power + Bixby + Volume Up). A quick search online should easily get you this info. As soon as you press the key combo and the device vibrates with a splash screen, release all buttons to boot into Magisk. If you decide to boot into the actual recovery mode, long press volume up until you see the recovery screen.
As a summary, after installing Magisk in recovery (starting from power off):
(Note: You CANNOT use custom recoveries to install or upgrade Magisk in this case!!)
Googlebooks support seamless A/B system updates, allowing you to apply official OTA updates while preserving Magisk without reflashing from a USB drive. Follow the OTA Upgrade Guides to install system updates and retain root access.
Before proceeding, please acknowledge that:
To verify whether or not Magisk can be installed in your Samsung device, you first must check the OEM Lock and KnoxGuard (RMM) status. To do so, go to Settings -> Device Care -> Maintenance Mode and enable it, then boot your device in Download mode with its key combo.
Possible OEM Lock values are the following:
To unlock your bootloader, follow the instructions below. If no OEM Lock value is shown in Download mode, your device is probably not unlockable due to market limitations (USA/Canada devices).
Possible KnoxGuard values are the following:
Active, Locked: your device has been remotely locked by your telecom operator or your insurance company.Prenormal: your device is temporarily locked, reaching 168h of uptime should trigger unlock.Checking, Completed, Broken: your device is unlocked.Having KnoxGuard active will prevent you from installing/running Magisk regardless of your bootloader lock state.
AP tar file to your device. It is normally named as AP_[device_model_sw_ver].tar.md5AP tar fileadb pull /sdcard/Download/magisk_patched-[version]_[random_strings].tarsamloader on your PC to flash magisk_patched-[version]_[random_strings].tar as AP, together with BL, CP, and CSC (NOT HOME_CSC because we want to wipe data) from the original firmware.samloader finished flashing. Agree to do a factory reset if asked.Once you have rooted your Samsung device, you can no longer upgrade your Android OS through OTA. To upgrade your device’s OS, you have to manually download the new firmware zip file and go through the same AP patching process written in the previous section. The only difference here is in the flashing step: do NOT use the CSC tar, but instead use the HOME_CSC tar as we are performing an upgrade, not the initial install.
boot, init_boot, recovery, or vbmeta partitions back to stock! You can brick your device by doing so, and the only way to recover from this is to do a full firmware restore with data wipe.AP tar file with reasons mentioned above. Always patch AP in the Magisk app and use that instead.This installation method is deprecated and is maintained with minimum effort. YOU HAVE BEEN WARNED!
Installing using custom recoveries is only possible if your device has boot ramdisk. Installing Magisk through custom recoveries on modern devices is no longer recommended. If you face any issues, please use the Patch Image method.
.apk file extension to .zip, for example: Magisk-v31.0.apk → Magisk-v31.0.zip. If you have trouble renaming the file extension (like on Windows), use a file manager on Android or the one included in the custom recovery to rename the file.Warning: the
sepolicy.rulefiles of modules may be stored on thecacheormetadatapartition (the pre-init partition). DO NOT WIPE THECACHEORMETADATAPARTITION, or active modulesepolicy.rulefiles will be lost until the modules are reinstalled.