Universal Flashing Method

How to Extract & Patch Android Boot Images with Magisk

The definitive technical walkthrough for patching stock Android boot partitions using Magisk. Learn how to extract boot.img and init_boot.img from official firmware archives (Google Factory Images, OnePlus payload.bin, Xiaomi Fastboot TGZ, Samsung Odin AP tarballs), understand how magiskboot injects magiskinit into the ramdisk, and flash safely via Fastboot.

Decision Matrix: Which Partition Image Do You Need?

  • Devices Launched on Android 13, 14, 15, or 16 (GKI 2.0): Patch init_boot.img (Google Pixel 7/8/9, OnePlus 11/12, Xiaomi 13/14, POCO F5/F6). Under GKI 2.0, boot.img contains only the raw Linux kernel without a ramdisk.
  • Devices Launched on Android 12 or Earlier: Patch boot.img (Pixel 6 and older, OnePlus 10 Pro and older, POCO X3 Pro).
  • Samsung Galaxy Smartphones: Patch the full AP_[model]_[build].tar.md5 archive via Magisk, then flash via Samsung Odin.

How to Extract Stock Boot Images Across 5 Firmware Formats

1. Google Pixel Factory Images (ZIP)

  1. Download the official factory image from developers.google.com/android/images.
  2. Extract the main zip archive. Inside, locate the nested archive: image-[device]-[build].zip.
  3. Unzip that nested archive and extract init_boot.img (Pixel 7+) or boot.img (Pixel 6/older).

2. OnePlus, Oppo & Realme Firmware (payload.bin)

Full OTA updates for OxygenOS/ColorOS contain partitions bundled inside payload.bin. Use the open-source tool payload-dumper-go:

payload.bin Extraction Commands
# Extract init_boot from payload.bin (OnePlus 11/12) $payload-dumper-go -p init_boot payload.bin # Extract boot from payload.bin (OnePlus 10 and older) $payload-dumper-go -p boot payload.bin

3. Xiaomi, Redmi & POCO Fastboot ROMs (TGZ)

  1. Download the official Fastboot ROM (packaged as .tgz, NOT a Recovery zip).
  2. Extract the TGZ archive using 7-Zip or tar.
  3. Open the extracted folder and navigate to the images/ subfolder to find boot.img or init_boot.img.

4. Motorola & Nothing Phone Factory Images

  1. Download the official stock firmware zip using Motorola Rescue and Smart Assistant (LMSA) or Nothing developer portals.
  2. Unzip the firmware package to find boot.img or init_boot.img located directly in the root directory.

Step-by-Step Walkthrough: Patching via Magisk App

Step 1: Push Stock Image to Phone

ADB Transfer
# Install official Magisk APK $adb install -r Magisk-v30.7.apk # Push stock boot or init_boot image to Download folder $adb push init_boot.img /sdcard/Download/

Step 2: Patch Inside Magisk App

  1. Open the Magisk App on your Android device.
  2. Tap the Install button on the top Magisk status card.
  3. Under Method, select "Select and Patch a File".
  4. Use the file picker to select /sdcard/Download/init_boot.img (or boot.img).
  5. Tap "LET'S GO!". Magisk will unpack the ramdisk, inject magiskinit, disable verity flags, repack the cpio archive, and output the patched file to:
    /sdcard/Download/magisk_patched_[random_string].img

Step 3: Pull Patched Image to Computer

ADB Pull Command
# Pull patched image back to your PC terminal working directory $adb pull /sdcard/Download/magisk_patched_*.img magisk_patched.img

Step 4: Flash via Fastboot CLI

Fastboot Flashing Commands
# 1. Reboot phone into Fastboot / Bootloader mode $adb reboot bootloader # 2. Verify device is recognized in fastboot $fastboot devices # 3. For Android 13+ GKI devices (Pixel 7/8/9, OnePlus 11/12, etc.): $fastboot flash init_boot magisk_patched.img # 4. For Android 12 and older devices (Pixel 6, OnePlus 10 Pro, etc.): $fastboot flash boot magisk_patched.img # 5. Reboot into Android $fastboot reboot

What Happens Internally During the Patching Process?

When you tap "LET'S GO!" in Magisk, the app executes its internal native binary magiskboot:

Internal magiskboot Architecture
1. Header Parsing: Reads Android boot header (v0, v1, v2, v3, or v4). 2. Decompression: Extracts ramdisk (detecting gzip, lz4_legacy, lz4, xz, or lzma). 3. CPIO Extraction: Unpacks root filesystem cpio tree. 4. Hijack Injection:Replaces /init with magiskinit binary; renames stock /init -> /init.real. 5. AVB Flag Patch: Disables dm-verity and androidboot.verifiedbootstate enforcement. 6. Repack: Repacks cpio, compresses with optimal algorithm, and regenerates boot image.

Troubleshooting Boot Image Patching Errors

Magisk app throws "! Unsupported/Unknown image format" error during patch.

This error means the file selected is not a raw Android boot image (it may be a compressed zip, an Odin tar package on non-Samsung devices, or a corrupted download). Verify that the file ends in .img and has a non-zero byte size.

Why does my phone bootloop after flashing a patched boot.img on Android 14?

On devices launched with Android 13+, the ramdisk was moved out of boot.img and placed into init_boot.img. Patching boot.img corrupts the raw Linux kernel. Flash your stock boot.img back, and patch init_boot.img instead.

Source & Verification Standard

Last Reviewed: August 19, 2026 • Verified With: Magisk v30.7 • Primary upstream: topjohnwu/Magisk. Primary reference: topjohnwu/Magisk on GitHub.