AnyKernel3 Documentation

repository·master·Indexed 23 days ago

https://github.com/osm0sis/anykernel3

A template for creating flashable update.zip files for kernel releases. AnyKernel3 allows developers to apply kernels to various ROMs and modify ramdisk or system files using a suite of shell-based command methods for file manipulation, system patching, and boot partition management. It supports multi-partition and multi-slot (A/B) zips, automatic architecture detection for optional binaries, and configurable installation behaviors via __anykernel.sh__.

Tokens
2.4K
Snippets
3
Records
6
Agent score
31%

What's inside AnyKernel3

  1. Create a flashable AnyKernel3 zip

    master

    Follow these steps to package your kernel release into an AnyKernel3 flashable zip:

    1. Kernel Files: Place your kernel build product (e.g., Image.gz-dtb or zImage) in the zip root. Include any required dt, dtb, recovery_dtbo, dtbo, system_dlkm, or vendor_dlkm files in the root as well.
    2. Ramdisk/Modules: Place ramdisk files in /ramdisk (or /vendor_ramdisk for multi-partition vendor_boot v3 support). Place module files in /modules using their full path (e.g., /modules/system/lib/modules).
    3. Patches: Place patch files (used with AK3 file editing commands) in /patch (or /vendor_patch for vendor_boot v3).
    4. Configuration: Modify anykernel.sh to define your kernel's name, boot partition location, ramdisk file permissions, and ramdisk modification methods. You can optionally add banner or version files to the root to display them during flashing.
    5. Packaging: Use zip to create the final package, ensuring you exclude git and documentation files.

    Important Notes:

    • The LICENSE file must remain in the final zip.
    • For broadest compatibility, modify existing ramdisk files rather than replacing them entirely.
    • If using a recovery that requires signature verification (e.g., Cyanogen Recovery), you must sign the zip separately.
    • For debugging, append the suffix -debugging to your zip filename to enable the creation of a debug .tgz of /tmp.
    zip -r9 UPDATE-AnyKernel3.zip * -x .git README.md *placeholder
  2. Create multi-partition and multi-slot flashable zips

    master

    AnyKernel3 supports advanced zip structures for complex installations.

    Multi-partition zips

    To target multiple partitions (e.g., boot and recovery), remove the ramdisk and patch folders from the zip. Instead, include -files folders named after the partitions:

    • boot-files/ (contains Image.gz, ramdisk/, patch/, etc.)
    • recovery-files/ (contains Image.gz, ramdisk/, patch/, etc.)

    When scripting, set BLOCK= (without slot suffix) and RAMDISK_COMPRESSION= for each new target partition, then call reset_ak.

    Multi-slot (A/B) zips

    To create a zip that installs to both the active and inactive slots:

    1. Layout the zip for the active slot normally.
    2. Set SLOT_SELECT=inactive.
    3. Set BLOCK= (without slot suffix) for the target partition.
    4. Set RAMDISK_COMPRESSION= for the target slot.
    5. Call reset_ak keep to retain existing patches and ramdisk files for the next slot installation.
  3. Maintain device-specific branches using Git

    master

    To keep your device-specific AnyKernel3 builds up-to-date with the main repository, use a branching workflow:

    1. Fork the AnyKernel3 repository on GitHub.
    2. Clone your fork locally.
    3. Add the original repository as an upstream remote.
    4. Create a new branch for your device (e.g., git checkout -b <devicename>).
    5. Configure the branch for your device (remove unused folders like ramdisk or patch, delete README.md, add your anykernel.sh and kernel images).
    6. Commit and push the device branch to your origin.

    To update, pull the latest changes from the upstream master branch into your local master, then merge or cherry-pick those changes into your device-specific branches.

    git clone https://github://<yourname>/AnyKernel3
    git remote add upstream https://github.com/osm0sis/AnyKernel3
    git checkout -b <devicename>
    # ... make changes ...
    git push --set-upstream origin <devicename>
  4. Configure AnyKernel3 properties and variables

    master

    AnyKernel3 uses variables defined in __anykernel.sh__ to control the installation behavior. Key properties include:

    • do.devicecheck=1: Requires at least one device.name# property to match the device's ro.product.device or similar build.prop values.
    • do.modules=1: Pushes contents of the modules directory to the root (/) with correct permissions. On A/B devices, this applies only to the active slot.
    • do.systemless=1: When combined with do.modules=1, creates an "ak3-helper" Magisk/KernelSU module to replace system files (including .ko files).
    • do.cleanup=1: Removes the working directory in /tmp/anykernel after installation. Set to 0 for debugging.
    • do.cleanuponabort=0: Keeps the working directory in /tmp/anykernel if installation is aborted.
    • supported.versions=: Matches against ro.build.version.release. Supports exact matches (e.g., 7.1.2) or ranges (e.g., 7.1.2 - 9).
    • supported.patchlevels= / supported.vendorpatchlevels=: Matches against security patch dates in YYYY-MM format. Supports open-ended ranges (e.g., 2019-04 - or - 2019-06).
    • BLOCK=: The target partition. Use auto for device-agnostic detection, or a partition name like boot, recovery, or vendor_boot.
    • IS_SLOT_DEVICE=: Set to 1 or auto to enable automatic detection of the active slot suffix for A/B devices.
    • RAMDISK_COMPRESSION=: Set to auto for auto-detection, or force a format like gz, lzo, lzma, xz, bz2, lz4, lz4-l, cpio, or none.
    • PATCH_VBMETA_FLAG=: Set to auto (default), 0 (keep original), or 1 (force patch).
    kernel.string=KernelName by YourName @ xda-developers
    do.devicecheck=1
    do.modules=1
    do.systemless=1
    do.cleanup=1
    do.cleanuponabort=0
    device.name1=maguro
    device.name2=toro
    device.name3=toroplus
    device.name4=tuna
    supported.versions=6.0 - 7.1.2
    supported.patchlevels=2019-07 -
    supported.vendorpatchlevels=2013-07
    
    BLOCK=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot;
    IS_SLOT_DEVICE=0;
    RAMDISK_COMPRESSION=auto;
    PATCH_VBMETA_FLAG=auto;
  5. Use AnyKernel3 command methods in __anykernel.sh__

    master

    AnyKernel3 provides a suite of shell-based command methods for manipulating files, partitions, and system properties during installation.

    File and String Manipulation

    • replace_string <file> <if search string> <original string> <replacement string> <scope>: Replaces strings in a file. Use global for <scope> to replace all instances.
    • replace_section <file> <begin search string> <end search string> <replacement string>: Replaces a block of text between two markers.
    • remove_section <file> <begin search string> <end search string>: Removes a block of text.
    • insert_line <file> <if search string> <before|after> <line match string> <inserted line>: Inserts a line relative to a match.
    • replace_line <file> <line replace string> <replacement line> <scope>: Replaces a specific line.
    • remove_line <file> <line match string> <scope>: Removes a specific line.
    • prepend_file, insert_file, append_file: Adds file contents based on a search string.
    • replace_file <file> <permissions> <patch file>: Replaces a file and sets its permissions.

    System Patching

    • patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>: Modifies fstab entries.
    • patch_cmdline <cmdline entry name> <replacement string>: Updates kernel command line entries.
    • patch_prop <prop file> <prop name> <new prop value>: Updates build.prop entries.
    • patch_ueventd <ueventd file> <device node> <permissions> <chown> <chgrp>: Updates ueventd files.

    Boot and Partition Management

    • dump_boot, split_boot, unpack_ramdisk, repack_ramdisk, flash_boot: Granular control over the boot image lifecycle.
    • flash_generic <partition name>: Flashes an image to a specific partition.
    • write_boot: The default method for unpacking, repacking, and flashing (includes dtbo, system_dlkm, and vendor_dlkm automatically).

    Utilities

    • ui_print "<text>": Prints messages to the recovery UI.
    • abort "<text>": Aborts the installation.
    • file_getprop <file> <property>: Retrieves a property from a file.
    • contains <string> <substring>: Checks if a string contains a substring.
    • backup_file <file> / restore_file <file>: Backs up or restores files.
  6. Include optional binaries for expanded functionality

    master

    AnyKernel3 includes standard ARM builds for core tools. To enable advanced features, you can place specific binaries in the /tools directory.

    To support multiple architectures in a single zip, move ARM builds to tools/arm and x86 builds to tools/x86. This enables automatic architecture detection.

    Supported optional binaries include:

    • mkbootfs: For broken recoveries or booted flash support (deprecated).
    • flash_erase, nanddump, nandwrite: MTD block device support.
    • dumpimage, mkimage: DENX U-Boot uImage format support.
    • mboot: Intel OSIP Android image format support.
    • unpackelf, mkbootimg: Sony ELF kernel.elf format support (repacks as AOSP standard boot.img).
    • elftool (with unpackelf): Sony ELF kernel.elf support (repacks as ELF for older Sony devices).
    • mkmtkhdr (with unpackelf): MTK device boot image section headers support for Sony devices.
    • futility + chromeos test keys directory: Google ChromeOS signature support.
    • boot_signer-dexed.jar (deprecated) + avb keys directory: Google Android Verified Boot 1.0 (AVBv1) custom signature support.
    • rkcrc: Rockchip KRNL ramdisk image support.