![]()
GUIDE: Manual flashing of AnyKernel3 kernels
We understand the frustration that arises when a trusted kernel developer ceases to provide direct flashable boot.img files. The shift toward AnyKernel3 zips, while versatile for custom recoveries, creates a barrier for users relying on direct flashing methods. This often occurs due to the absence of a custom recovery, the need to maintain custom AVB (Android Verified Boot) keys, or simply a preference for the raw speed of fastboot over recovery-based installations.
We have compiled this comprehensive guide to bridge that gap. Our objective is to provide a meticulous, step-by-step manual on how to convert an AnyKernel3 zip into a directly flashable boot.img using the magiskboot utility. This process bypasses the need for TWRP or OrangeFox, allowing you to flash custom kernels via fastboot while maintaining the integrity of your device’s specific partition structure.
Understanding the AnyKernel3 Format and Its Limitations
Before executing commands, it is crucial to understand what we are dealing with. The AnyKernel3 format is a packaging standard widely used in the Android development community. Its primary advantage is universality; it is designed to work across various devices and recoveries by utilizing an update-binary script that detects the device’s specific partition layout and injects the kernel (Image) and associated files (DTBs, modules) into the correct locations.
However, this abstraction layer is exactly why direct flashing is not natively supported. An AnyKernel3 zip is not a raw partition image; it is an installer. When a developer stops providing boot.img files, they are essentially forcing the user to rely on the installation script. For users without a custom recovery, or those on devices with strict partition verification (like Pixel devices with custom AVB), this presents a significant hurdle.
By deconstructing the AnyKernel3 zip and repacking the kernel into a raw boot.img, we reintroduce the flexibility of direct fastboot commands. We essentially reverse-engineer the kernel component out of the installer and fuse it with a base boot.img specific to your device.
Prerequisites for Manual Kernel Repacking
We recommend gathering all necessary tools and files before beginning the process. Preparation minimizes the risk of errors during the repacking phase.
Required Software and Tools
- Magiskboot Utility: This tool is part of the Magisk ecosystem and is the core engine for our repacking process. It is capable of unpacking
boot.imgfiles, modifying their contents, and repacking them into a new, functional image.- Note: While
magiskbootis typically associated with rooting, it is a standalone binary that can be used for kernel manipulation even on unrooted devices during the preparation phase.
- Note: While
- Android Platform Tools (ADB and Fastboot): You need these installed on your computer to interact with your device in bootloader mode and to eventually flash the generated image.
- A Command Line Interface (CLI): Whether you are using Windows Command Prompt/PowerShell, macOS Terminal, or Linux Terminal, you need a environment to execute commands.
- The AnyKernel3 Zip File: Download the specific AnyKernel3 zip intended for your device and Android version. Do not use a zip meant for a different device, as this will result in a kernel mismatch and potential bootloops.
- A Base Boot.img: You need a compatible
boot.imgfile for your exact device model and current firmware version. This can be sourced from:- The stock firmware zip for your device.
- A custom ROM installation zip (often found inside
META-INF/com/google/android/). - Crucial: The
boot.imgmust match your current system’s build number or vendor version to ensure compatibility with ramdisks and system partitions.
Step-by-Step Guide to Repacking AnyKernel3 to Boot.img
We will now proceed with the technical execution. We assume you have a basic understanding of file navigation within your operating system.
Phase 1: Extracting the Kernel Image
The AnyKernel3 zip contains several components, but the core kernel is the Image file (often compressed as Image.gz).
- Locate your downloaded AnyKernel3 zip file.
- Extract the contents of the zip file to a folder on your computer. You can use any standard extraction tool like 7-Zip, WinRAR, or the native OS extractor.
- Inside the extracted folder, look for a file named
ImageorImage.gz. This is the raw kernel binary.- Context: In GKI (Generic Kernel Image) devices, this file represents the core Linux kernel.
- For this guide, we recommend creating a dedicated workspace. Let’s call this folder
KernelWork.
Phase 2: Organizing Files for Magiskboot
Proper file organization is the key to a smooth repacking process. We will structure our folders to ensure the magiskboot command executes correctly.
- Create a main folder named
KernelWork. - Inside
KernelWork, create a subfolder namedInput. - Place your downloaded
boot.img(the base image) into theInputfolder. - Place the extracted
Image(from the AnyKernel3 zip) into theInputfolder. - (Optional but Recommended) Rename
Imagetokernel. Whilemagiskbootcan handle generic names, standardizing tokernelensures we know exactly what we are modifying. - Ensure the
magiskbootbinary is accessible. If it is not in your system PATH, place themagiskbootexecutable inside theKernelWorkroot folder for easy access.
Folder Structure Visualization:
KernelWork/
│── magiskboot (executable)
│── Input/
│── boot.img (Base image for your device)
│── Image (Renamed to 'kernel')
Phase 3: Executing the Repack Command
With files in place, we initiate the repacking process. This step fuses the custom kernel (Image) with the ramdisk and partition table data from your base boot.img.
Open your Command Line Interface (Terminal/PowerShell).
Navigate to your workspace directory.
- Command:
cd path/to/KernelWork
- Command:
Run the repack command. This command instructs
magiskbootto take the kernel file from theInputdirectory and inject it into theboot.imglocated in the same directory, generating a new file../magiskboot repack Input/boot.img Input/kernel- Explanation:
./magiskboot: Calls the executable.repack: The specific action to rebuild the image.Input/boot.img: The source boot image (provides the ramdisk and header).Input/kernel: The custom kernel image (replaces the kernel inside the source).
- Explanation:
Wait for the process to complete.
magiskbootwill unpack theboot.img, replace the kernel, and repack everything.Upon successful execution, a new file named
new-boot.imgwill appear in theKernelWorkdirectory (or sometimes in theInputdirectory depending on the version of magiskboot—check both).
Phase 4: Verifying the New Image
Before flashing, we ensure the file was created successfully. Check the file size of new-boot.img. It should be roughly similar to, or slightly larger than, the original boot.img. If it is significantly smaller (e.g., only a few KB), the repack likely failed.
Flashing the Repacked Boot.img
Now that we have a manually created boot.img containing the AnyKernel3 kernel, we can proceed to flash it to the device.
Preparing the Device
- Enable Developer Options: Go to your device settings, tap “Build Number” seven times to unlock developer options.
- Enable USB Debugging: In Developer Options, enable USB Debugging.
- Unlock Bootloader: Ensure your bootloader is unlocked. Direct flashing is impossible with a locked bootloader unless you are flashing signed stock images.
- Boot into Fastboot Mode: Connect your device to the PC and run:Alternatively, power off the device and hold the specific key combination (usually Power + Volume Down).
adb reboot bootloader
Flashing the Image
Once in the bootloader interface (fastboot mode):
Verify the connection:
fastboot devicesFlash the repacked image to the boot partition:
fastboot flash boot new-boot.img- Note: Some devices use
boot_aorboot_b(A/B Partitioning). If you are on Slot A, usefastboot flash boot_a new-boot.img. If Slot B, useboot_b. - Warning: Do not use
fastboot flash kernelunless you are absolutely certain your device uses a separate kernel partition. Most modern devices use a unifiedboot.img.
- Note: Some devices use
For Magisk Users: If you intend to keep root access, you must re-flash the Magisk app after updating the kernel. Kernel updates often overwrite the
boot.img, removing the Magisk patch. To preserve root, patch thenew-boot.imgvia the Magisk App before flashing, or re-install Magisk immediately after flashing the kernel.
Finalizing and Rebooting
- Once the flash command returns
OKAY, you can reboot the device:fastboot reboot - The first boot after a kernel change may take longer than usual as the system compiles specific binary artifacts and initializes the new kernel modules.
Troubleshooting Common Issues
We anticipate that users may encounter specific hurdles during this process. Here are solutions to the most common problems.
Bootloops after Flashing
If your device gets stuck in a boot loop, it is likely due to a kernel mismatch.
- Cause: The
Imagefrom the AnyKernel3 zip is incompatible with your current system vendor or ROM. - Solution: You must restore your original
boot.img. Reboot into fastboot mode and flash your backup:(Always keep a backup of your originalfastboot flash boot boot_backup.imgboot.imgbefore starting this process).
“Magiskboot: command not found”
- Cause: The terminal cannot locate the
magiskbootbinary. - Solution: Ensure you are in the correct directory where the binary resides, or provide the full path to the executable. On Linux/macOS, ensure the binary is executable (
chmod +x magiskboot).
“Sparse chunk format error” or Partition Errors
- Cause: Incompatible
boot.imgbase. - Solution: Ensure the base
boot.imgmatches the Android version and security patch level of your current system. Aboot.imgfrom Android 12 will generally not work correctly with a kernel built for Android 13 due to changes in the boot structure.
Advanced: Understanding the Ramdisk vs. Kernel
It is important to understand what magiskboot repack actually does. The boot.img is generally composed of two main parts:
- The Header: Contains metadata about the image size and partition offsets.
- The Ramdisk: Contains init scripts, prop files, and initial drivers required to mount the system.
- The Kernel: The core executable (
Image).
When you run magiskboot repack boot.img kernel, the utility unpacks your existing boot.img, extracts the kernel and ramdisk, replaces the old kernel with your new one (from the AnyKernel3 zip), and then repacks the ramdisk and the new kernel together. This is why using a base boot.img from the wrong firmware version can break the ramdisk, causing a boot failure even if the kernel itself is valid.
Conclusion
By utilizing the magiskboot utility, we successfully bypass the limitations imposed by the AnyKernel3 zip format. This manual method grants you full control over your kernel installation, allowing for direct fastboot flashing without the dependency on custom recoveries. While the process requires attention to detail—specifically regarding file versions and naming conventions—it is a reliable and robust solution for advanced users.
We encourage all users to verify checksums of their downloaded files and to maintain backups of their original partitions. Custom kernels are powerful tools for performance and battery optimization, but they operate at a low level of the system architecture. Proceed with caution, follow the steps precisely, and enjoy the flexibility of direct kernel management.