### Complete Install Script Skeleton Source: https://context7.com/osm0sis/anykernel3/llms.txt A basic structure for an AnyKernel3 installation script, including dumping the boot image, performing ramdisk edits, and writing the modified boot image. ```sh ### anykernel.sh – complete install script skeleton . tools/ak3-core.sh; dump_boot; # --- ramdisk edits go here --- write_boot; # repack_ramdisk + flash_boot + flash_generic for vendor/dtbo images ``` -------------------------------- ### Define AnyKernel3 Properties Source: https://context7.com/osm0sis/anykernel3/llms.txt Configure device compatibility, module handling, and installation behavior. Set `do.devicecheck` to 1 to abort if the device name does not match. ```sh ### anykernel.sh – Properties block properties() { ' kernel.string=MyKernel by YourName @ xda-developers do.devicecheck=1 # 1 = abort if device does not match device.name* do.modules=1 # 1 = push /modules contents to / on device do.systemless=1 # 1 (with do.modules) = create ak3-helper Magisk/KernelSU module do.cleanup=1 # 1 = remove /tmp/anykernel working dir after flash do.cleanuponabort=0 # 0 = keep working dir if installation aborts device.name1=blueline # matches ro.product.device / ro.build.product device.name2=blueline_b device.name3= supported.versions=9 - 12 # range or comma-list matched against ro.build.version.release supported.patchlevels=2021-01 - # open-ended minimum security patch date '; } ``` -------------------------------- ### AnyKernel3 Setup and Reset Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Initialize AnyKernel3 with `setup_ak` and reset its state with `reset_ak`. The `keep` option for `reset_ak` retains patches and ramdisk files for subsequent slots. ```shell reset_ak [keep] ``` ```shell setup_ak ``` -------------------------------- ### Dump and Unpack Boot Image Source: https://context7.com/osm0sis/anykernel3/llms.txt Standard procedure to read the boot partition, split it, and extract the ramdisk. Imports AK3 functions and runs setup. ```sh ### anykernel.sh – standard ramdisk-modifying install . tools/ak3-core.sh; # import all AK3 functions and run setup_ak dump_boot; # reads partition → split_img/ and ramdisk/ # equivalent to: split_boot; unpack_ramdisk; ``` -------------------------------- ### Utility Functions: ui_print, abort, contains, file_getprop Source: https://context7.com/osm0sis/anykernel3/llms.txt Provides functions for user output, installation abortion, string checking, and reading properties. Use `ui_print` for messages, `abort` to stop installation on error, `contains` to check for substrings, and `file_getprop` to read build properties. ```shell ui_print "Installing MyKernel v5.15 for Pixel 3..."; # Conditionally apply a tweak only for Android 12+ ver=$(file_getprop /system/build.prop "ro.build.version.release"); if contains "$ver" "12"; then ui_print " Applying Android 12 tweak..."; insert_line init.rc "ak3-a12-tweak" after "on early-init" " setprop ak3.a12 1"; fi; # Abort with a message if a required file is missing [ -f $AKHOME/Image.gz-dtb ] || abort "ERROR: Kernel image not found in zip!" ``` -------------------------------- ### Updating AnyKernel3 with Upstream Changes Source: https://context7.com/osm0sis/anykernel3/llms.txt Guides on forking AnyKernel3, setting up upstream remote, creating device-specific branches, and pulling/cherry-picking upstream improvements. This ensures your custom kernel distribution stays up-to-date with the latest AnyKernel3 features and fixes. ```shell # Fork osm0sis/AnyKernel3 on GitHub, then: git clone https://github.com//AnyKernel3 cd AnyKernel3 git remote add upstream https://github.com/osm0sis/AnyKernel3 # Create a device-specific branch git checkout -b mypixel3 # ... add your anykernel.sh, kernel image, ramdisk files, delete README.md ... git push --set-upstream origin mypixel3 # Pull upstream improvements into master and cherry-pick into device branches git checkout master git pull upstream master git checkout mypixel3 git cherry-pick ``` -------------------------------- ### Granular Repack and Flash Control Source: https://context7.com/osm0sis/anykernel3/llms.txt Split the write phase into `repack_ramdisk` and `flash_boot` for finer control or to skip ramdisk modifications. This example flashes only the kernel image. ```sh ### anykernel.sh – OG AK mode: flash kernel image only, no ramdisk changes . tools/ak3-core.sh; split_boot; # dump + split (skip unpack_ramdisk) # Kernel image replaced in zip root, no ramdisk work needed: repack_ramdisk; # rebuild ramdisk cpio (uses original if unchanged) flash_boot; # assemble and write new boot.img to partition ``` -------------------------------- ### AnyKernel3 Configuration Properties Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Defines essential properties for kernel zip installations, including device names, supported Android versions, and patch levels. ```shell 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; ``` -------------------------------- ### Building a Flashable AnyKernel3 ZIP Source: https://context7.com/osm0sis/anykernel3/llms.txt Steps to clone the AnyKernel3 template, place kernel build output and overlay files, edit configuration, and package the final flashable ZIP. Excludes unnecessary files like .git and README. ```shell # 1. Clone the template git clone https://github.com/osm0sis/AnyKernel3 cd AnyKernel3 # 2. Place your kernel build output in the zip root cp /path/to/out/arch/arm64/boot/Image.gz-dtb . # 3. Place ramdisk overlay files (if any) cp my-init.rc ramdisk/ cp my-module.ko modules/system/lib/modules/ # 4. Place partial patch files (if any) cp my-fstab.patch patch/ # 5. Edit anykernel.sh with your kernel's details # - Set kernel.string, device.name*, supported.versions # - Set BLOCK= and IS_SLOT_DEVICE= # - Add ramdisk modification commands # 6. Package the ZIP (exclude git history, README, and placeholder files) zip -r9 UPDATE-MyKernel-v5.15.zip * -x .git README.md \*placeholder # 7. Optional: add -debugging suffix to filename for troubleshooting # UPDATE-MyKernel-v5.15-debugging.zip → creates /tmp debug .tgz on flash ``` -------------------------------- ### Create AnyKernel3 Flashable Zip Source: https://github.com/osm0sis/anykernel3/blob/master/README.md This command creates a compressed flashable zip file for AnyKernel3. It includes all files in the current directory except for the .git repository, README.md, and placeholder files. Ensure the LICENSE file is included for compliance. ```bash zip -r9 UPDATE-AnyKernel3.zip * -x .git README.md *placeholder ``` -------------------------------- ### Configure Partition and Ramdisk Variables Source: https://context7.com/osm0sis/anykernel3/llms.txt Set the boot partition, slot device status, ramdisk compression, and VBMETA patching flag. Use 'auto' for automatic detection where applicable. ```sh # Partition / ramdisk variables (outside properties block) BLOCK=boot; # partition name or /dev/block/... path; "auto" for detection IS_SLOT_DEVICE=auto; # "1" or "auto" for A/B slot detection RAMDISK_COMPRESSION=auto; # auto | gz | lz4 | lzma | xz | bz2 | lz4-l | cpio/none PATCH_VBMETA_FLAG=auto; # auto | 0 (keep) | 1 (force-patch) ``` -------------------------------- ### Create Device Branch Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Create a new branch for your specific device. Replace `` with the name of your device. ```bash git checkout -b ``` -------------------------------- ### File Backup and Restoration Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Use `backup_file` to create backups of files, which can be useful for testing or creating restore packages. `restore_file` can be used to revert changes, but use with caution. ```shell backup_file ``` ```shell restore_file ``` -------------------------------- ### Generic Partition Flashing Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Use `flash_generic` to flash an image to a specified partition. This is automatically included for certain partitions during `write_boot` but can be called independently. ```shell flash_generic ``` -------------------------------- ### Clone AnyKernel3 Repository Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Clone your forked AnyKernel3 repository to your local machine. Replace `` with your GitHub username. ```bash git clone https://github.com//AnyKernel3 ``` -------------------------------- ### Switch to Master Branch Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Switch back to the master branch to prepare for pulling updates or creating new device branches. ```bash git checkout master ``` -------------------------------- ### Flash multiple partitions with reset_ak Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `reset_ak` to prepare AnyKernel3 for flashing a second partition in the same ZIP. `reset_ak keep` preserves ramdisk patches for multi-slot flashing. ```shell . tools/ak3-core.sh; # --- boot partition --- dump_boot; # ... ramdisk edits ... write_boot; # --- switch to recovery partition --- BLOCK=recovery; RAMDISK_COMPRESSION=gz; reset_ak; # cleans up and re-runs setup_ak for new BLOCK dump_boot; # ... recovery ramdisk edits ... write_boot; ``` -------------------------------- ### Print and Abort Operations Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Use `ui_print` to display messages to the user and `abort` to halt the flashing process with an optional message. ```shell ui_print [...] ``` ```shell abort ["" [...]] ``` -------------------------------- ### Push Device Branch to Origin Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Push your newly created device branch to your forked repository on GitHub. This sets the upstream for the branch. ```bash git push --set-upstream origin ``` -------------------------------- ### Flash Arbitrary Partition Image Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `flash_generic` to flash any image file (e.g., `dtbo`, `vendor_dlkm`) to its corresponding block device. Handles dynamic partition resizing and dm-verity patching. ```sh ### anykernel.sh – simple dtbo-only flasher zip . tools/ak3-core.sh; ``` -------------------------------- ### Add Upstream Remote Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Add the official AnyKernel3 repository as a remote named 'upstream'. This allows you to pull the latest changes. ```bash git remote add upstream https://github.com/osm0sis/AnyKernel3 ``` -------------------------------- ### Backup and restore ramdisk files Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `backup_file` to save a copy of a ramdisk file before modification (appends `~`) and `restore_file` to revert changes. Useful for testing or creating undo zips. ```shell backup_file init.rc; # saves ramdisk/init.rc as ramdisk/init.rc~ restore_file init.rc; # reverts ramdisk/init.rc from ramdisk/init.rc~ ``` -------------------------------- ### Boot Image Manipulation Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Commands for dumping, splitting, unpacking, repacking, and flashing boot images. `split_boot` and `unpack_ramdisk` can be used for granular control over ramdisk modifications. ```shell dump_boot ``` ```shell split_boot ``` ```shell unpack_ramdisk ``` ```shell repack_ramdisk ``` ```shell flash_boot ``` ```shell write_boot ``` -------------------------------- ### File Permission Management Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Set permissions for individual files with `set_perm` or recursively for directories and their contents with `set_perm_recursive`. ```shell set_perm [ ...] ``` ```shell set_perm_recursive [ ...] ``` -------------------------------- ### System File Patching Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Patch kernel command line entries with `patch_cmdline`, properties in prop files with `patch_prop`, and device node permissions/ownership in ueventd with `patch_ueventd`. ```shell patch_cmdline ``` ```shell patch_prop ``` ```shell patch_ueventd ``` -------------------------------- ### Line and File Insertion/Removal Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Insert or remove lines within files using `insert_line` and `remove_line`, or replace entire files with `replace_file`. `insert_file` and `prepend_file` allow inserting content from another file. ```shell insert_line ``` ```shell replace_line ``` ```shell remove_line ``` ```shell prepend_file ``` ```shell insert_file ``` ```shell append_file ``` ```shell replace_file ``` -------------------------------- ### Set Permissions Recursively in AnyKernel3 Source: https://context7.com/osm0sis/anykernel3/llms.txt Sets recursive permissions for directories and files within the ramdisk. Directories are set to 755 and files to 644, owned by root:root. Specific init binaries and adbd are given executable permissions and owned by root:shell respectively. ```shell boot_attributes() { set_perm_recursive 0 0 755 644 $RAMDISK/*; # dirs=755, files=644, owned root:root set_perm_recursive 0 0 750 750 $RAMDISK/init* $RAMDISK/sbin; # init binaries executable set_perm 0 2000 750 $RAMDISK/sbin/adbd; # adbd owned root:shell } ``` -------------------------------- ### Granular Ramdisk Unpack Control Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `split_boot` to dump and split the boot image without unpacking the ramdisk, useful for devices with separate init_boot partitions. `unpack_ramdisk` can then be called independently. ```sh ### anykernel.sh – OG AK mode: modify ramdisk without touching kernel . tools/ak3-core.sh; split_boot; # dump partition and split into split_img/; skip ramdisk extract # ... apply ramdisk patches here ... unpack_ramdisk; # extract ramdisk.cpio from split_img/ into ramdisk/ ``` -------------------------------- ### Replace string in ramdisk files with guard Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `replace_string` to substitute `` with `` in a file, guarded by the absence of ``. Pass `"global"` to replace all occurrences. ```shell dump_boot; # Replace CPU control mount option only if tweak not already applied replace_string init.rc "cpuctl cpu,timer_slack" \ "mount cgroup none /dev/cpuctl cpu" \ "mount cgroup none /dev/cpuctl cpu,timer_slack"; write_boot; ``` -------------------------------- ### Set file permissions Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `set_perm` or `set_perm_recursive` to set ownership and permissions on individual files or entire directory trees within the ramdisk. ```shell dump_boot; # Set permissions for a single file set_perm /dev/test.txt 0644 root root; # Set permissions recursively for a directory set_perm_recursive /data/testdir 0755 root root; write_boot; ``` -------------------------------- ### Insert line into ramdisk file Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `insert_line` to add a new line before or after a matched line in a ramdisk file. ```shell dump_boot; # Insert a mount option line after "mount_all /fstab.device" if not already present insert_line init.device.rc "nodiratime" after "mount_all /fstab.device" \ " mount ext4 /dev/block/by-name/userdata /data remount nodiratime"; # Replace the selinux permissive line replace_line init.rc "setenforce 0" " setenforce 1"; # Remove a specific line globally remove_line init.rc "androidboot.selinux=permissive" global; write_boot; ``` -------------------------------- ### String and File Property Operations Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Check for substrings within strings using `contains` and retrieve properties from files using `file_getprop`. ```shell contains ``` ```shell file_getprop ``` -------------------------------- ### Modify kernel command line Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `patch_cmdline` to add or replace a named entry in the kernel command line stored within the boot image header. ```shell dump_boot; # Add or update androidboot.selinux parameter patch_cmdline "androidboot.selinux" "androidboot.selinux=permissive"; write_boot; ``` -------------------------------- ### Fstab Patching Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Modify fstab entries using `patch_fstab`. You must specify the fstab file, a mount name, and the type of field (block, mount, fstype, options, or flags) to alter, along with the original and replacement strings. ```shell patch_fstab block|mount|fstype|options|flags ``` -------------------------------- ### Append file content to ramdisk file Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `append_file` to add the content of a patch file to the end of a ramdisk file, optionally checking if it's already present. ```shell dump_boot; # Append bootscript.sh content to init.tuna.rc if not already present append_file init.tuna.rc "bootscript" init.tuna; # Insert a patch before a specific line insert_file init.rc "ak3-init-patch" before "on property:sys.boot_completed=1" ak3-init; # Completely replace fstab with a patched version and set permissions replace_file fstab.device 0644 fstab.device; write_boot; ``` -------------------------------- ### String and Section Replacement Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Modify files by replacing strings or entire sections. `replace_string` replaces all occurrences if 'global' scope is specified. `replace_section` requires both begin and end search strings. ```shell replace_string ``` ```shell replace_section ``` -------------------------------- ### Modify ueventd rules Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `patch_ueventd` to add or replace a device node entry in a `ueventd` configuration file. ```shell dump_boot; # Set /dev/kgsl-3d0 permissions for GPU access patch_ueventd ueventd.rc /dev/kgsl-3d0 0666 root root; write_boot; ``` -------------------------------- ### Modify Android property Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `patch_prop` to add or update a property in any `.prop` file within the ramdisk. ```shell dump_boot; patch_prop default.prop "ro.debuggable" "1"; patch_prop default.prop "ro.secure" "0"; write_boot; ``` -------------------------------- ### Modify fstab entry Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `patch_fstab` to modify a specific field (block, mount, fstype, options, or flags) within a targeted fstab entry identified by mount name and filesystem type. ```shell dump_boot; # Change /data mount options: replace "data=ordered" with "data=writeback" patch_fstab fstab.device /data ext4 options "data=ordered" "data=writeback"; # Remove barrier option from /cache patch_fstab fstab.device /cache ext4 options "barrier=1" "barrier=0"; write_boot; ``` -------------------------------- ### Update Master Branch Source: https://github.com/osm0sis/anykernel3/blob/master/README.md Pull the latest changes from the upstream master branch into your local master branch. ```bash git pull upstream master ``` -------------------------------- ### Remove section from ramdisk file Source: https://context7.com/osm0sis/anykernel3/llms.txt Use `remove_section` to delete a multi-line block from a file, identified by begin and end search strings. ```shell dump_boot; # Remove the entire "service logd" block from init.rc remove_section init.rc "service logd " "^$"; # Replace the "on post-fs-data" section with custom content replace_section init.rc "on post-fs-data" "^$" \ "on post-fs-data\n mkdir /data/local 0751 root root"; write_boot; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.