Home / Guide / Root

Magisk Root Guide: Patching Boot and init_boot Images

The core of every Magisk root: choosing between boot and init_boot, patching the image, flashing it correctly and checking the result.

Stock boot.img file transformed into a Magisk patched image

What patching actually does

Rooting with Magisk revolves around a single file. Your phone’s boot process starts from a boot image that contains the kernel and a small ramdisk, a miniature file system with the first program Android runs. Magisk modifies that ramdisk so that its own program, magiskinit, runs first. Everything else, from the root daemon to module mounting, follows from that one change.

Because only the boot-time image is modified, the system, vendor and product partitions remain exactly as the manufacturer shipped them. That is the meaning of systemless root, and it is why a Magisk root can be reversed by flashing the original image back.

This guide covers the method recommended by the official documentation for current devices: patch the image in the Magisk app, then flash the result. Device-specific details vary, so treat this as a framework and check notes for your model before you start.

Before you begin

  • Unlocked bootloader. Without it, the phone will refuse to boot a modified image. Unlocking usually erases all data.
  • Full backup. Photos, messages, authenticator apps and anything else you cannot lose.
  • Stock firmware for your exact build. The build number is in Settings → About phone. The image you patch must come from that build.
  • Platform tools on your computer. Google’s SDK platform-tools package provides adb and fastboot. Samsung users need Odin instead.
  • The official Magisk app. Installed from the GitHub Releases page.
  • A charged battery and a reliable USB cable. Interruptions during flashing are a common source of trouble.

Step 1: Work out which image to patch

This is the step that trips people up most often. Open the Magisk app and look at the Ramdisk line on the home screen, then compare it with how your device launched.

SituationImage to patch
Phone launched with Android 13 or later and has an init_boot partitioninit_boot.img
Ramdisk shows Yes and there is no init_boot partitionboot.img
Some devices that keep the ramdisk in vendor_bootvendor_boot.img (check device notes)
Older phones where Ramdisk shows Norecovery.img, using the recovery mode method
Samsung phonesThe full AP tar file from the firmware package

Phones that launched with Android 13, such as the Pixel 7 series and many later models, moved the generic ramdisk into a separate init_boot partition. Patching boot.img on those devices does nothing useful, and the app will later report Magisk as not installed. Phones that launched earlier and were upgraded to Android 13 or newer usually keep their original layout.

Step 2: Extract the image from your firmware

How you get the image depends on how your manufacturer distributes firmware.

  • Factory images (Pixel and similar). Download the factory zip for your build, open the inner image zip, and copy boot.img or init_boot.img.
  • Payload-based OTA packages. Many brands ship a payload.bin file. Open-source payload extractor tools can pull individual images out of it.
  • Samsung. Download the full firmware for your model and region. You will use the file beginning with AP_.

Whatever the source, the build number must match. An image from a different build can boot loop the phone or cause features such as Wi-Fi to fail.

Step 3: Patch the image in the Magisk app

  1. Copy the image (or Samsung AP file) to the phone’s internal storage.
  2. Open the Magisk app and tap Install on the Magisk card.
  3. Leave the options at their defaults unless your device notes say otherwise.
  4. Choose Select and Patch a File, then pick your image.
  5. Tap Let’s Go. The app unpacks the image, injects magiskinit, patches the ramdisk, and repacks it.
  6. The log ends with the path of the output, normally Download/magisk_patched-xxxxx.img (or a .tar for Samsung).

Copy the patched file to your computer. Use adb pull rather than MTP file transfer if possible, because MTP has been known to corrupt large files silently.

adb pull /sdcard/Download/magisk_patched-xxxxx.img

Step 4: Flash the patched image

Devices that use fastboot

adb reboot bootloader
fastboot flash init_boot magisk_patched-xxxxx.img   # init_boot devices
fastboot flash boot magisk_patched-xxxxx.img        # boot devices
fastboot reboot

Use only the line that matches your device. Flashing to the wrong partition is not usually destructive, because the partition sizes and formats differ and fastboot often refuses, but if it succeeds the phone may not boot until you flash the correct stock image back.

On some devices with Android Verified Boot, the official notes also mention disabling verification flags in vbmeta. Read your device notes; most current Pixel-style devices do not need this when only boot or init_boot is changed with an unlocked bootloader.

Samsung devices

Load the patched AP tar in Odin’s AP slot along with the BL, CP and CSC files from the same firmware, disable auto-reboot, flash, and then boot directly into the stock recovery to factory reset when the documentation calls for it. Samsung’s process has several device-specific steps, and the official installation notes describe them carefully.

Step 5: Confirm root is working

After the phone boots, open the Magisk app. The Magisk card should now show an installed version. If the app asks for additional setup and reboots the phone, let it; this is normal on first install.

To confirm root from a computer, run:

adb shell
su
id

Your phone will display a superuser prompt for the Shell. Grant it, and id should report uid=0(root). You can now revoke shell access in the Superuser tab if you do not need it routinely.

When the app says Magisk is not installed

If the phone boots normally but the app shows N/A for the installed version, the patched image is not the one the phone booted from. The usual causes are:

  • Patching boot.img on a device that boots from init_boot.
  • Flashing to the inactive slot on an A/B device. Use fastboot getvar current-slot to check, and flash the active slot or simply use the unslotted partition name.
  • Using an image from a different firmware build.
  • A corrupted transfer of the patched file.

Re-extract the image from the correct firmware, patch again, and flash again. It is tedious but almost always solves the problem.

Updating Android after rooting

An over-the-air update replaces your patched image with a new stock one. You can keep root through updates on A/B devices with this sequence:

  1. In the Magisk app, tap Uninstall → Restore Images. Do not reboot.
  2. Install the system update through Settings, but do not tap Restart when it finishes.
  3. Return to Magisk, tap Install → Install to Inactive Slot (After OTA).
  4. Reboot. The phone switches to the updated slot with Magisk already patched in.

On devices without A/B slots, or when an update is applied by a full factory image, simply patch the new build’s image and flash it again using the steps above.

Removing root cleanly

To return to stock, tap Uninstall → Complete Uninstall in the Magisk app. It restores the backed-up original images and removes the app. If the backups are missing or the phone does not boot, flash the stock boot or init_boot image for your build with fastboot. Relocking the bootloader is a separate decision; only relock after confirming every partition is completely stock, because relocking with modified images can leave a device unbootable.

Understanding A/B slots

Many modern phones keep two copies of key partitions, labelled slot A and slot B. Only one slot is active at a time; the other receives the next system update in the background. This design is what makes seamless updates possible, and it also affects rooting.

When you run fastboot flash boot file.img without a suffix, fastboot writes to the currently active slot, which is normally what you want. Problems appear when someone flashes boot_a explicitly while the phone is running from slot B, or when an interrupted update has switched slots unexpectedly. Checking the active slot takes one command:

fastboot getvar current-slot

The same logic explains the Install to Inactive Slot option in the Magisk app. After an OTA has been written to the other slot, Magisk patches that slot’s image before the phone switches to it, so you arrive in the updated system already rooted.

Keeping a patched image on hand

Store the patched image alongside the stock image on your computer. If an experiment goes wrong and you flash stock to recover, you can restore root in seconds by flashing the patched file again, provided the firmware build has not changed. Label both files with the build number so there is never any doubt about which belongs to which update.

A word on risk

Patching and flashing are routine operations that thousands of people perform every day, yet they still carry risk. Unlocking the bootloader may affect warranty terms with some manufacturers and can cause certain apps, especially banking, payment and streaming apps, to refuse service. A careful approach, with backups and the correct firmware at hand, keeps those risks manageable and every step reversible.

Checklist

  • Bootloader unlocked and data backed up.
  • Correct image chosen: init_boot, boot, vendor_boot or Samsung AP.
  • Image taken from the exact installed firmware build.
  • Patched in the official Magisk app and copied with adb pull.
  • Flashed to the correct partition and active slot.
  • Root confirmed in the app and with su from ADB.
  • Stock image saved for updates and emergencies.