Boot Image Manipulation Toolkit

magiskboot CLI Reference Manual

The comprehensive developer manual for magiskboot, the standalone native binary that powers Magisk's boot image unpacking, repacking, ramdisk CPIO modification, DTB patching, and hex-pattern editing across all Android boot header versions (v0–v4).

Core Capabilities of magiskboot

  • Universal Boot Header Support: Parses and constructs legacy v0/v1/v2, modern v3/v4 (GKI), and vendor_boot structures.
  • Ramdisk Compression Agnostic: Auto-detects and compresses gzip, zopfli, xz, lzma, bzip2, lz4, and lz4_legacy formats.
  • Direct CPIO Operations: Injects, deletes, replaces, and extracts files inside ramdisk archives without unpacking to disk.

Command Syntax & Operations Reference

1. Unpack & Repack Boot Images

Unpack & Repack Syntax
# Unpack boot.img or init_boot.img into kernel, ramdisk.cpio, dtb, header: $magiskboot unpack boot.img # Repack modified components back into new-boot.img: $magiskboot repack boot.img [new-boot.img] # Clean up extracted temporary working files: $magiskboot cleanup

2. CPIO Ramdisk Operations

CPIO Ramdisk Commands
# Check if a specific file exists in ramdisk: $magiskboot cpio ramdisk.cpio "exists init" # Extract a file from ramdisk: $magiskboot cpio ramdisk.cpio "extract init init.extracted" # Add a file with specific permissions (mode 0755): $magiskboot cpio ramdisk.cpio "add 0755 init magiskinit" # Apply standard Magisk patch (backup stock init -> rename to init.real -> inject magiskinit): $magiskboot cpio ramdisk.cpio "patch"

3. In-Place Binary Hex Patching

Hex Patch Syntax
# Replace hex pattern 1 with hex pattern 2 inside a binary file: $magiskboot hexpatch kernel <hex_from> <hex_to>

4. Compression & Decompression

Stream Compression Commands
# Auto-detect compression format and decompress to raw stream: $magiskboot decompress ramdisk.cpio.gz ramdisk.cpio # Compress raw stream with specific algorithm (gzip, lz4, lz4_legacy, xz): $magiskboot compress=lz4_legacy ramdisk.cpio ramdisk.cpio.lz4

Android Boot Header Specifications (v0 through v4) Supported

Over Android's evolution, Google has repeatedly overhauled the structure of the boot image container. magiskboot contains built-in parsing logic for all Android boot image header versions:

Header Version Android OS Era Key Architectural Characteristics
Header v0 – v2 Android 7.0 – 10 Monolithic boot.img holding kernel, ramdisk, secondary bootloader, and device tree blobs (DTB).
Header v3 Android 11 – 12 Kernel and generic ramdisk bundled; DTB moved to dedicated dtb vendor partition.
Header v4 (GKI 2.0) Android 13 – 16 Boot image contains ONLY the Google-certified generic kernel (GKI); generic ramdisk is relocated entirely to init_boot.img.

Advanced Scripting: Manual Boot Image Patching Pipeline

Developers building custom automated recovery tools can replicate Magisk App's exact patching sequence using standard shell commands:

Complete Manual Magisk Patch Workflow
# 1. Unpack original boot image $magiskboot unpack boot.img # 2. Patch the extracted ramdisk CPIO archive $magiskboot cpio ramdisk.cpio "patch" # 3. Repack into new boot image $magiskboot repack boot.img magisk_patched.img # 4. Clean temporary build artifacts $magiskboot cleanup
Source & Verification Standard

Checked against official upstream repository topjohnwu/Magisk on Magisk v30.7 (February 23, 2026).