How to patch a boot image with Magisk
Patching a stock image in the Magisk app and flashing it with fastboot is the main install method in Magisk's documentation. You don't need TWRP. This guide covers the whole process, plus the parts people get stuck on: finding the right image for your exact build, A/B slots, fastboot boot versus flash, and what fastboot's errors mean.
Last updated 16 sourcesHow we check pages
Before you start
- Your phone's bootloader must be unlocked. Unlocking erases the phone. Brand-specific steps: Pixel, Samsung, Xiaomi, Redmi and POCO, OnePlus, Nothing and Motorola.
- A computer with Android's
adbandfastboot(Google's SDK Platform-Tools, latest version) and a good USB cable. - The stock firmware for the exact build your phone is running (Settings → About phone → Build number).
- On a Samsung phone, follow the Samsung guide instead: you patch the firmware's whole
APfile and flash it in Download mode, not with fastboot.
The process
Patching and flashing at a glance
- 1Pick the image
init_boot,boot,vendor_bootorrecovery - 2Get it from your buildSame build number as the phone
- 3Patch in the appOn the phone you're rooting
- 4Flash with fastbootWrites the active slot
- 5Reboot, finish setupThe Magisk card shows a version
Not sure which method applies to your phone at all? Start at how to install Magisk or answer three questions in the root method checker.
Which image: init_boot, boot, vendor_boot or recovery?
Magisk patches the image that holds the phone's boot ramdisk. Where that ramdisk lives depends on how old the phone's design is:
| Your phone | Patch | Why |
|---|---|---|
Firmware contains init_boot.img (normally phones that launched with Android 13 or later) | init_boot.img | AOSP moved the generic ramdisk out of boot into init_boot for devices launching with Android 13; boot then holds only the kernel. |
Firmware has init_boot.img, but the kernel is Android 12 GKI or older | boot.img | Magisk's installer only uses init_boot with a kernel newer than Android 12 GKI. Check with adb shell uname -r: a version containing android12-, or 5.4 and older, means boot.img. |
No init_boot.img, Ramdisk: Yes | boot.img | Phones that launched with Android 12 or earlier keep their layout after upgrading. |
Ramdisk is in vendor_boot (a few devices) | vendor_boot.img | Supported since Magisk v30.3; the first stable release with it was v30.6. The app doesn't detect these devices for you: your device's community will say so. |
| Ramdisk: No | recovery.img | No ramdisk in boot, so Magisk takes over recovery. See Magisk in recovery. |
The most common mistake is patching boot.img on a phone that uses init_boot: the flash succeeds, but Magisk never starts and the app shows Not Installed (v31.1) or Installed: N/A (v30.7). When in doubt, look inside your firmware package. If it only has a payload.bin, list its contents with payload-dumper-go -l payload.bin.
Getting the stock image for your exact build
The image has to come from the same build as the one installed on the phone. Compare Settings → About phone → Build number with the firmware's version before you download. Use a full package: an incremental (delta) OTA only contains changes, not complete images.
- Google Pixel: Google's factory images or full OTA images, or let v31.1 fetch it. See the Pixel guide.
- Samsung: the full firmware from Samsung's servers with samloader-rs; you patch the whole
APfile. See the Samsung guide. - OnePlus, Nothing, Xiaomi, Motorola: the full update package or fastboot ROM for your build. Where each brand's comes from: device guides.
- Custom ROMs: the image inside the ROM's own zip.
Packages that only contain payload.bin
Full OTA zips for A/B phones usually hold one payload.bin instead of separate images. You have three options:
- Give the whole zip or
payload.binto the Magisk app. Both v30.7 and v31.1 extractinit_boot.img(orboot.imgif there is none) and patch it in one go. - Extract it on your computer with a payload dumper such as payload-dumper-go, then copy the image to the phone:
- Use Magisk's own tool.
magiskboot extract payload.binpulls outinit_bootorboot. Since v31.1, magiskboot can be built to run on Linux and macOS computers.
Our run: a Pixel 7 update
We downloaded Google's full update for the Pixel 7, Android 17 build CP3A.261005.002.A1 (October 2026), checked it against the SHA-256 Google lists, and let Magisk's own tool pick the image. With no partition named, magiskboot extract chose init_boot, the same choice the app makes on this phone. The update's own metadata names the exact build, which is how you check a package matches your phone (compare it with Settings → About phone → Build number):
Lines 17 to 36 of the unedited output. Full log · how it was made
What the Magisk app can patch directly
| Feature | v30.7 | v31.1 |
|---|---|---|
Raw .img file | Yes | Yes |
payload.bin | Yes | Yes |
Full OTA or ROM .zip | Yes | Yes |
Pixel factory image .zip | NoNested zip not read | Yes |
Samsung AP tar | Yes | Yes |
| HTTPS link to a package | No | YesEnter image URL |
| Fetch the Pixel image for you | No | YesPixels only |
Take vendor_boot or recovery from a package | NoExtract it yourself | NoExtract it yourself |
init_boot.img if it is there, otherwise boot.img.Can I just download a boot.img?
No. There is no universal boot.img, and no “boot img APK”. The image has to come from the exact firmware build installed on your phone, and Magisk's documentation is blunt about pre-patched files: never flash a patched image shared by someone else, or one patched on another device, even the same model. Treat any website offering a downloadable patched boot.img as a red flag. The only app you need is the Magisk app, which patches the image you give it.
Patch and flash, step by step
Each step has a Done box so you can keep your place. Your progress is saved in this browser only.
-
Install the Magisk app and check “Ramdisk”
2 minutesInstall the Magisk APK from the download page (it links to the official GitHub release) and open it. The home screen shows a Ramdisk value. Yes: patch
init_boot.img,boot.imgorvendor_boot.img(see which image). No: patchrecovery.img(see Magisk in recovery). -
Get the image (or the whole package)
10 to 30 minutesGet the stock image from the firmware for the exact build on your phone, as described in getting the stock image, and copy it to the phone. You can also copy the whole package: both v30.7 and v31.1 extract
init_boot.imgorboot.imgfrom apayload.binor a full OTA zip themselves. v31.1 also reads Pixel factory image zips and links. Forvendor_bootorrecovery, extract the raw image yourself. -
Patch it in the Magisk app
2 minutes- Tap Install in the Magisk card.
- If you are patching
recovery.img, tick Recovery Mode. - v30.7: choose Select and Patch a File and pick the file.
v31.1: choose Patch firmware / image, then Select from storage, Enter image URL (a direct HTTPS link to a full OTA zip, factory image zip or.img), or on Pixels Download latest Pixel factory image, which Magisk's guide says fetches the image matching your current build. In the source it falls back to the newest build if yours isn't listed, so check that the build shown under the option matches yours. - Start. The app writes
magisk_patched-[version]_[random].imgto the phone's Download folder, for examplemagisk_patched-30700_aB3dE.imgfrom v30.7 (a.tarfor Samsung).
Patch on the same phoneMagisk's documentation warns: never flash a patched image shared by someone else, or one patched on another phone, even the same model. You may need a full data wipe to recover.
-
Flash the patched image
5 minutesCopy the file to your computer with
adb pull(Magisk's guide warns that MTP is known to corrupt large files). Reboot to the bootloader and flash it to the partition the original came from. Use the real file name.Copy and flash$adb pull /sdcard/Download/magisk_patched-30700_aB3dE.img $adb reboot bootloader $fastboot devices # flash ONE of these, matching the image you patched $fastboot flash init_boot magisk_patched-30700_aB3dE.img $fastboot flash boot magisk_patched-30700_aB3dE.img $fastboot flash vendor_boot magisk_patched-30700_aB3dE.img $fastboot flash recovery magisk_patched-30700_aB3dE.img $fastboot rebootOn A/B phones this writes the active slot only, which is what you want. See A/B slots. If a command fails, look up the message in fastboot errors.
-
Finish setup
2 minutesReboot and open the Magisk app. If your data was wiped, v30.7 shows a small "stub" app that downloads the full app; with v31.1, install the Magisk APK again yourself (the stub was removed). The app then shows an Additional setup prompt: accept it and it reboots once more. The Magisk card should show an installed version.
If it shows Not Installed (v31.1) or Installed: N/A (v30.7), see Magisk installed but root not working. If the phone does not boot, see fixing a Magisk bootloop.
How a working install looks in v31.1
- A version under Magisk, here
31.1 (31100), means Magisk started from your patched image. That's the only line that proves it. - Zygisk is off after a fresh install. Turn it on in Settings only if a module you want needs it, then reboot.
- This line is the app's own version and shows a number whether or not Magisk runs. If the Magisk card says Not Installed, see root not working.
What patching actually changes: our runs
To show exactly what the Magisk app does to your image, we ran Magisk v31.1's own patch script (assets/boot_patch.sh, taken from the official APK) with the Magisk files from the same APK, on two of Google's real images: a Pixel 7's init_boot.img (the case for phones that launched with Android 13 or later) and a generic Android 12 boot.img. We did this on a computer with magiskboot built from the v31.1 source, because a computer can't run the phone's ARM build. Nothing was flashed or booted; this shows the files, not a phone. The flags are the ones the app uses on an encrypted A/B phone.
Pixel 7, Android 17: init_boot.img
| Google's stock init_boot.img | After Magisk patched it | |
|---|---|---|
| Kernel | None (size 0): the kernel lives in boot | None; boot is never touched |
| Ramdisk (compressed, lz4_legacy) | 2,714,528 bytes | 2,396,273 bytes |
init | Android's own, 2.96 MB | magiskinit from the APK, 184 KB (same SHA-256) |
| Added by Magisk | Nothing | overlay.d/sbin/magisk.xz (146 KB) and init-ld.xz (1.54 KB) |
| Backup inside the image | None | .backup/init.xz (the original init, 955 KB), .backup/.rmlist, .backup/.magisk |
| Magisk's own status check | 0 (stock) | 1 (patched by Magisk) |
| Image size | 8 MiB | 8 MiB |
The script's complete output. The lines starting with a dash are the progress messages the app also shows while it patches:
Lines 14 to 69 of the unedited output. Full log · how it was made
The one line that looks like an error, Exec format error, is the script asking the phone's ARM magisk binary for its pre-init partition, which a computer can't run; on a phone that name is saved in the image. There are no kernel patch attempts, because init_boot has no kernel. Opening the result confirms the swap, and that Magisk recorded the stock image's SHA1 so it can restore it later:
Lines 61 to 76 of the unedited output. Full log · how it was made
Restoring it with the uninstaller's command gave back Android's init byte for byte and the stock file list exactly: full log.
So a patched image is your own image with one swap: magiskinit runs first instead of Android's init, keeps the original next to it, and starts it after setting Magisk up (how that works). Magisk swaps init and adds its own files; everything else in the image is yours, unchanged. That is why only an image from your exact build works.
Generic Android 12 kernel: boot.img
Phones that launched with Android 12, such as the Pixel 6, keep the ramdisk in boot.img next to the kernel. We ran the same script on Google's generic boot image android12-5.10-2026-07_r2:
| Google's stock image | After Magisk patched it | |
|---|---|---|
| Kernel | 46,929,092 bytes | Byte-identical, untouched |
| Ramdisk (compressed, lz4_legacy) | 1,380,091 bytes | 1,118,008 bytes |
init | Android's own, 2.52 MB | magiskinit from the APK, 184 KB (same SHA-256) |
| Added by Magisk | Nothing | overlay.d/sbin/magisk.xz (146 KB) and init-ld.xz (1.54 KB) |
| Backup inside the image | None | .backup/init.xz (the original init, 842 KB), .backup/.rmlist and .backup/.magisk |
| Magisk's own status check | 0 (stock) | 1 (patched by Magisk) |
| Image size | 64 MiB | 64 MiB |
The script's output for this image:
Lines 11 to 69 of the unedited output. Full log · how it was made
The same harmless Exec format error appears. This time the image has a kernel, so the script also tries its optional kernel patches. Failed to patch, three times, is the script trying three optional kernel patches that its comments say are for Samsung kernels only (RKP, defex and PROCA). Google's kernel doesn't contain them, so it stays unchanged.
We then opened the patched image with the same tool:
Lines 13 to 61 of the unedited output. Full log · how it was made
.backup/.magisk records the patch settings and the SHA1 of the stock image, which is how the app knows what Restore Images must put back. The same run shows that restoring returns Android's init byte for byte: see what uninstalling restores.
A/B slots: which one gets flashed?
Most recent phones have two copies of each system partition, called slots A and B (boot_a, boot_b, init_boot_a and so on). Updates are written to the slot you are not using, and the phone switches slots on the next reboot (AOSP). For patching this means:
fastboot flash init_boot file.imgwrites the active slot only. fastboot adds the current slot's suffix for you; its help text says the default is the "current active slot". That is the slot the phone boots, so it is the right one.- Don't flash both slots with
--slot allunless you know both hold the same build. After an update, the other slot holds the previous build, and a patched image must match the build it boots. - Check which slot is active with
fastboot getvar current-slot.fastboot getvar slot-countanswers2on A/B phones. - Get the image from the build in the active slot. Settings shows the running build, which is the active slot's.
Keeping root through later system updates uses the inactive slot on purpose: see keeping root after an OTA.
fastboot boot or fastboot flash?
fastboot flash boot file.img | fastboot boot file.img | |
|---|---|---|
| What it does | Writes the image to the partition | Loads it into RAM and boots it once ("Download and boot kernel from RAM") |
| After a reboot | Still rooted | Back to whatever is on the partition |
Works with init_boot.img | Yes | No: it has no kernel to boot |
| Supported by every bootloader | Yes, once unlocked | No: some refuse it |
Magisk's guide uses fastboot flash. fastboot boot can be a way to test a patched boot.img first on phones that allow it: if the phone starts and the app shows Magisk as installed, Install → Direct Install writes Magisk to the boot partition, the same way an upgrade does. On init_boot phones there is no test boot; flash, and keep the stock image ready to flash back.
Do I need to flash vbmeta?
Usually not. Magisk's guide lists disabling verification on a separate vbmeta partition as optional (fastboot flash vbmeta --disable-verity --disable-verification vbmeta.img, using the stock vbmeta.img) and warns it may wipe your data. For phones without a separate vbmeta partition, the app handles the flags inside the image itself.
Fastboot and patching errors
Search for the message you see. fastboot's own messages are the same everywhere; messages from the phone (shown after FAILED (remote: ...)) depend on the manufacturer, so yours may be worded differently.
< waiting for any device >
Meaning: fastboot on your computer can't see a phone in bootloader mode. It waits until one appears.
Fix: Make sure the phone shows its bootloader screen (adb reboot bootloader), not Android or recovery. Run fastboot devices: an empty list means a USB problem. Try another cable and a port directly on the computer. On Windows, the phone needs a USB driver for fastboot mode (Google's USB driver for Pixels, the maker's driver otherwise).
"Flashing is not allowed in Lock State" or similar
Meaning: the bootloader is still locked, so it refuses to write partitions. The exact wording depends on the manufacturer.
Fix: Unlock first. AOSP's command is fastboot flashing unlock, which only works once OEM unlocking is on in Developer options, and wipes the phone. Brand steps: device guides.
"partition not found", "No such partition" or "partition does not exist"
Meaning: the phone has no partition with that name. The common case is fastboot flash init_boot on a phone that launched before Android 13 and has no init_boot.
Fix: Patch and flash boot.img instead. Check what your firmware contains (see which image).
"Flashing is not allowed for partition" or a request to use fastbootd
Meaning: on phones with dynamic partitions, the bootloader's fastboot only writes some partitions (AOSP lists bootloader, radio, boot and recovery) and leaves the rest to fastbootd, a fastboot mode that runs in Android's recovery.
Fix: Run fastboot reboot fastboot, wait for the fastbootd screen, and flash again. fastboot getvar is-userspace answers yes when you are in fastbootd.
"Write to device failed", "Status read failed" or "Read from device failed"
Meaning: the USB connection dropped in the middle of a transfer.
Fix: Use another cable and a port directly on the computer (not a hub or front-panel port), and update to the latest Platform-Tools. Then flash again: an interrupted write leaves the partition incomplete.
cannot load 'magisk_patched...img': No such file or directory
Meaning: fastboot can't find the file on your computer.
Fix: Run the command in the folder that holds the file, or give its full path. Copy the real file name: it contains a version number and random letters.
fastboot boot fails with "unknown command" or "not supported"
Meaning: this bootloader doesn't allow booting an image from RAM, or the image has no kernel (an init_boot.img never does).
Fix: Use fastboot flash instead. See fastboot boot or flash.
Magisk app: "! No boot image found" or "! Process error"
Meaning: the app couldn't find init_boot.img or boot.img in the file you picked. Typical causes: an incremental OTA, a zip that isn't a firmware package, or (on v30.7) a Pixel factory image zip, whose images sit in a second zip inside.
Fix: Use a full OTA or extract the raw image yourself (see getting the stock image).
Magisk app: "! Boot image patched by unsupported programs"
Meaning: the image was already modified by another root tool, so it isn't stock.
Fix: Magisk's script asks you to "restore back to stock boot image": take a clean image from the original firmware.
Magisk app: "! Unable to unpack boot image"
Meaning: the file isn't a boot image format Magisk's magiskboot understands: often a corrupted copy, a sparse image or the wrong file.
Fix: Copy the image again (with adb push, not MTP) and check you picked the right file.
Flash succeeded but the phone won't boot, or the app shows Not Installed or N/A
See bootloop after flashing and root not detected. The usual cause is an image from a different build, or boot.img patched on an init_boot phone.
No match. Try another word from the error message.
Magisk in recovery (phones with no boot ramdisk)
If your boot partition has no ramdisk, Magisk takes over the recovery partition. Patch recovery.img with Recovery Mode ticked and flash it with fastboot flash recovery. You then boot "through recovery" every time you want root. From power off:
- Power on normally: Android starts without Magisk.
- Recovery key combination, then release all buttons at the splash screen: Android starts with Magisk.
- Recovery key combination, then hold Volume Up: the real recovery mode.
The key combination depends on the model (Magisk's guide gives Power + Bixby + Volume Up for the Galaxy S10). In this setup you cannot use a custom recovery to install or upgrade Magisk. A/B phones never need this method: Magisk always treats them as having a boot ramdisk.
What about TWRP or other custom recoveries?
Magisk's documentation describes installing through a custom recovery (renaming the APK to .zip and flashing it) as deprecated and "maintained with minimum effort", and not recommended on modern devices. The patching method above works without one. More on the other routes: install methods.
Sources
This page is written from the sources below. If anything here disagrees with them, the upstream source is correct.
- Magisk installation guide (topjohnwu)
- Magisk changelog (topjohnwu)
- MagiskInstaller.kt: how the app reads and patches files (Magisk source)
- util_functions.sh: find_boot_image and the init_boot kernel check (Magisk source)
- Magisk app strings: menu and button names (Magisk source)
- Magisk tools: magiskboot extract (topjohnwu)
- Generic boot partition and init_boot (Android Open Source Project)
- A/B system updates (Android Open Source Project)
- Implement A/B updates: slot suffixes and fastboot variables (Android Open Source Project)
- fastboot command-line help and messages (AOSP platform/system/core)
- Move fastboot to userspace (fastbootd) (Android Open Source Project)
- Lock and unlock the bootloader (Android Open Source Project)
- payload-dumper-go README (ssut)
- GKI android12-5.10 release builds (Android Open Source Project)
- boot_patch.sh at v31.1 (Magisk source)
- Full OTA images for Nexus and Pixel devices: Pixel 7 (panther) (Google)
Found a mistake or something out of date? Tell us and we will check it against the source and fix the page. Confirmed corrections are listed in the corrections log.
Report a problem with this page