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
Source & Verification Standard

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