[DEV][TEMPLATE] AnyKernel3 - Easily Mod ROM Ramdisk + Pack Image.gz [Flashable Zip]

Search This thread

Surge1223

Recognized Contributor
Nov 6, 2012
2,622
7,466
Florida
Google Pixel 6 Pro
Happy New Year!

Despite me being away on vacation here's a big update to module handling thanks to @nathanchance. If you are currently pushing modules with AK2 you will need to move the files under "modules/" to reflect their destination subfolder to avoid breakage, e.g. "modules/system/lib/modules/", "modules/system/vendor/lib/modules/" and/or "modules/vendor/lib/modules/"; this will be pretty future proof so was worth the while.

update-binary: Change how we handle modules:
https://github.com/osm0sis/AnyKernel2/commit/6b11373d4ae91b10ce4745e380ee3d4b440fbde6

README: Update documentation for modules:
https://github.com/osm0sis/AnyKernel2/commit/218b5774d26f1ff1c0acd3bec273153f5b529cb2

example: Update modules folder for new location handling:
https://github.com/osm0sis/AnyKernel2/commit/a0b6db2784a3cd121a4af768a68ec88fc97c550a

Just something to keep in mind in relation to this. If the rom version has a vbmeta.img that verifies the hash on vendor separate from verity, then users could run into module failures to load since the hash wouldn't match, obvious since custom roms have control of ramdisk its not a huge issue, but say a rom like lineage, which uses 4 AB partitions will have a signed vbmeta.img

https://github.com/LineageOS/android_device_google_wahoo/blob/lineage-15.1/device.mk#L100

you can disable the hashing and salt in aosp and make an insecure plain vbmeta.img but I highly doubt many will implement that. I'm sure everything will be fine for now but just something to keep in mind.

https://android.googlesource.com/pl...0f85abc41491756495b9ea33d966e6e9585/README.md

just interesting to think about because before I used magisk, I used a different su in which I didn't take dtbo patching into consideration and ran into issues
 
Last edited:
  • Like
Reactions: osm0sis

Zackptg5

Recognized Developer
Sep 18, 2014
4,148
7,005
zackptg5.com
Google Pixel 4a
Google Pixel 5a
@osm0sis

A while ago you suggested that I just leave boot img signing for all devices. On further testing, I found boot img signing breaks boot on my lg g2 -> it'll get stuck on fastboot. Just wanted to let you know

Edit: do you know of a way I can detect if a bootimg is signed? I know that the magisk installer does it. I was looking on the avb signing thread by chainfire but wasn't sure if these commands actually sign it or just verify it's signed:
Code:
dalvikvm -cp BootSignature_Android.jar com.android.verity.BootSignature /boot boot.img verifiedboot.pk8 verifiedboot.x509.der boot_signed.img
dalvikvm -cp BootSignature_Android.jar com.android.verity.BootSignature -verify boot_signed.img
 
Last edited:
  • Like
Reactions: osm0sis

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
Here's another fix to modules with many thanks to @nathanchance, improved support for U-Boot uImage, and extends potential support to older Sony ELF devices.

Backend: Only apply contexts to new modules:
https://github.com/osm0sis/AnyKernel2/commit/b0b754c09453d353f123a70d67223fa290c63c18

AK2: add support for repacking as Sony ELF:
https://github.com/osm0sis/AnyKernel2/commit/fb44ff18e1c2cc5cc0c77c0cb38dd50062086e3e

README: update for elftool:
https://github.com/osm0sis/AnyKernel2/commit/c3ca17f3cf33398e0a65cb25830c602c75173e17

AK2: allow U-Boot uImage without ramdisk:
https://github.com/osm0sis/AnyKernel2/commit/79f1c391ea1b31885eea16bb94dd86b954da3fb2
 
Last edited:

attack11

Recognized Developer
Nov 28, 2011
1,264
2,993
Buenos Aires
Motorola Edge 30

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
Yes, but it will override/replace the old modules, modifying system partition

Okay, so you want them in the ramdisk. That's a custom job beyond AK2, but very much doable as long as there's space enough in the boot partition for the ramdisk to contain the modules.

I've never done it, but I imagine you could put them in ramdisk/sbin/modules or ramdisk/modules and then set the appropriate chmod and chown to them in the AK2 Permissions/Ownership section, then you'd just have to add script to the init.rc to bind mount the new modules over the system ones during boot.
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
A few more handy fixes and new features! Thanks again to @nathanchance for finding and fixing the insert_line off-by-one fix. :highfive:

AK2: add reset_ak(), fix patch_cmdline(), improve AVBv1 signing:
- introduce reset_ak function to reset the /tmp/anykernel directory to allow for multi-partition mods; use after changing the AK2 shell (block, etc.) variables again
- make patch_cmdline more intuitive; match the string, and if it doesn't exist add the replacement string, and if so replace with it
- allow AVBv1 signing of recovery by adding simple partition type detection based on name
- restore LD_LIBRARY_PATH after AVBv1 signing to be friendly to recovery when flashed in between other zips

https://github.com/osm0sis/AnyKernel2/commit/d4f81e628e399c8715cfde8d53ee346d1b23f741

AK2: Fix insert_line line validation:
https://github.com/osm0sis/AnyKernel2/commit/96bc564d588ff682fa4e74b334aaf5ddca23cec5

Backend: only replace getprop if needed (and do so more robustly):
https://github.com/osm0sis/AnyKernel2/commit/83df1e3df15409521f6e44776687dba2bbfe8f92

AK2: clarify new patch_cmdline usage:
https://github.com/osm0sis/AnyKernel2/commit/2b7501710d3813aff23efb2277bf1f04f33d7aa7

README: document new patch_cmdline usage
https://github.com/osm0sis/AnyKernel2/commit/153567dcafe10f041949ca24cb4678a80b56b9da

Apologies if you were using the old patch_cmdline(), but this way is far more sensible/intuitive. For an example of both it, and reset_ak() for a multi-partition mod, please see my N5X-6P_BLOD_Workaround_Injector_Addon-AK2-signed.zip on my BasketBuild.
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
Those AK2 devs who use Windows, here's something to make your lives way easier! I'll be adding it to the signing documentation linked in the OP. :good::)

@TKruzze of PA GApps and TK GApps fame (basically the daddy of modern GApps) has come back to release a fantastic Windows tool that all Android mod makers should find helpful!

https://xdaforums.com/android/software-hacking/tool-zip-builder-v4-2-1-build-sign-t3739556

It makes creating and signing a zip from a Magisk module or AnyKernel2 (or any otherwise complete zip contents) git repo a two-click experience, and allows unpacking and easy repacking of any downloaded flashable zip by automatically using the correct different signing processes for both shell-based and edify-based zips. Super cool.

Don't thank me, go thank his thread! :silly:
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
The never requested (nor pull requested.. :silly:;)) but clearly wanted banner support is now added! Get your ASCII-line-art on to really push your kernel's name and brand. :p

Please note that to ensure ease of cherry-picking updates for AK2's backend and core, it's never a good idea to edit the backend (update-binary) or core (ak2-core.sh) files. I'm always open to pull requests and discussion on new features or fixes. :good::)

ak2-core.sh: fix repacking of Sony ELF kernels:
https://github.com/osm0sis/AnyKernel2/commit/e12304ece67ee834858e4a2f34d06f66ac110256

AK2: fix insert_line wc/ash bad number error when missing file:
https://github.com/osm0sis/AnyKernel2/commit/e32f6915ef8f5b9d32d8d0b652f220579dd43578

Backend: fix vendor unmounting:
https://github.com/osm0sis/AnyKernel2/commit/7b09dd8b664cdd5615ffa2241a5ff18620200560

tools: update to latest busybox (1.28.1):
https://github.com/osm0sis/AnyKernel2/commit/7391ede9b942888f547aaf67e82b45e59d6b0cfa

Backend: add custom kernel banner support:
https://github.com/osm0sis/AnyKernel2/commit/b0a2cae9cd3b5e894e9ddd4733d4af467bba8309

Backend: add custom kernel version display support:
https://github.com/osm0sis/AnyKernel2/commit/efa46236894bfe1d1eba355755fe7bd4a328485d

Backend: touch up install whitespace now that we have banner/version display:
https://github.com/osm0sis/AnyKernel2/commit/12289267c5017a8418279bd6bf6c84caf8ee251f

AK2: fix cpio extraction with busybox 1.28+:
https://github.com/osm0sis/AnyKernel2/commit/14e73ecbec636eb72ce82a0d7dc078e23610351c

README: update for banner and version file support:
https://github.com/osm0sis/AnyKernel2/commit/1e3d48355e89e1d8631efc967882e2330b8dc11c

Until the new AIK-mobile version is out, busybox binaries for architectures other than ARM can be easily grabbed from my Busybox Installer Magisk module repo; simply rename to busybox and place in tools.
 
Last edited:

Carotix

Recognized Themer
Jul 20, 2012
9,154
36,857
Ravenna
hi @osm0sis
i'm working on Oreo Rom S8/S8+ .. I noticed that Anykernel2 sets OEM UNLOCK toggle off and then i can't enable it ...
Is this your choose ? is it possible to change something to get the toggle working on or off?
thanks for your great works
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
hi @osm0sis
i'm working on Oreo Rom S8/S8+ .. I noticed that Anykernel2 sets OEM UNLOCK toggle off and then i can't enable it ...
Is this your choose ? is it possible to change something to get the toggle working on or off?
thanks for your great works

It doesn't touch anything like that by default. (Sounds more like my Nexus BootUnlocker zip..) What AnyKernel2 zip are you referring to?
 
  • Like
Reactions: Carotix

Carotix

Recognized Themer
Jul 20, 2012
9,154
36,857
Ravenna
It doesn't touch anything like that by default. (Sounds more like my Nexus BootUnlocker zip..) What AnyKernel2 zip are you referring to?
your last one ... AK2: fix insert_line wc/ash bad number error when missing file .... post #592
I'm saying that because i tried with only stock kernel and oem unlock toggle worked ... (but i had the problem with recovery) ... then i added your Anykernel2 and everything is good but i can't switch the oem toggle on ..... it's always off
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
your last one ... AK2: fix insert_line wc/ash bad number error when missing file .... post #592
I'm saying that because i tried with only stock kernel and oem unlock toggle worked ... (but i had the problem with recovery) ... then i added your Anykernel2 and everything is good but i can't switch the oem toggle on ..... it's always off

Right that doesn't make any sense though, since my example in the repo is for a Galaxy Nexus and has a null zImage, so you shouldn't be flashing it as-is on any device. So, again, what zip are you using? Also, that commit has nothing to do with anything life changing. Some people just found the wc/ash error unsettling despite AK2 working fine, but it does nothing except suggest the target rc file in the insert_line command is missing.
 
Last edited:
  • Like
Reactions: Carotix

Carotix

Recognized Themer
Jul 20, 2012
9,154
36,857
Ravenna
Right that doesn't make any sense though, since my example in the repo is for a Galaxy Nexus and has a null zImage, so you shouldn't be flashing it as-is on any device. So, again, what zip are you using? Also, that commit has nothing to do with anything life changing. Some people just found the wc/ash error unsettling despite AK2 working fine, but it does nothing except suggest the target rc file in the insert_line command is missing.
i was wrong sorry .... my mistake , you are right
thanks
 

Zackptg5

Recognized Developer
Sep 18, 2014
4,148
7,005
zackptg5.com
Google Pixel 4a
Google Pixel 5a
@osm0sis

So I've been working on porting an app but a problem I've run into is that is uses it's own service and rc file. I've got all of that taken care of, however, it requires the creation a selinux domain in sepolicy. The current tool I've been using (sepolicy-inject) doesn't have the capability for creating a new domain like magiskpolicy and supolicy do. Do you know of any way I can do this in twrp or tool I can use (boot scripts run too late so I have to patch sepolicy directly)? I've tried supolicy from supersu but it requires a lib which is a no go. Thanks!
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,775
40,464
Halifax
GT-i9250
Google Nexus 4
@osm0sis

So I've been working on porting an app but a problem I've run into is that is uses it's own service and rc file. I've got all of that taken care of, however, it requires the creation a selinux domain in sepolicy. The current tool I've been using (sepolicy-inject) doesn't have the capability for creating a new domain like magiskpolicy and supolicy do. Do you know of any way I can do this in twrp or tool I can use (boot scripts run too late so I have to patch sepolicy directly)? I've tried supolicy from supersu but it requires a lib which is a no go. Thanks!

I guess try magiskboot/magiskpolicy?
 

ajituchiha

Senior Member
Aug 24, 2014
239
236
24
Kathmandu
is there a way to make it so that it only flashes the kernel and not ramdisk ? P10 Plus has two different partitons for ramdisk and kernel. If I use the ramdisk partition it shows everything flashed properly but the kernel is still the same (means it did not flash) and if I use the kernel partition then it shows ramdisk unknown compression (because it does not detect ramdisk).
I tried to edit ak2-core.sh but I just ended up earsing both ramdisk and kernel image.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 325
    *** NOTE: I will not respond to any requests for support that do not include at least an attached full log and the zip in question; full AK3-debugging.zip debug .tgz preferred (instructions below). ***

    AnyKernel3 -- Flashable Zip Template for Kernel Releases with Ramdisk Modifications


    "AnyKernel is a template for an update.zip that can apply any kernel to any ROM, regardless of ramdisk." - Koush

    The concept of AnyKernel has been around for awhile, (originally by Koushik Dutta/ClockworkMod,) which allowed a device-specific kernel zImage to be flashed over device-specific ROM and use the ramdisk that came with the ROM to reduce the chance of any issues arising from the custom kernel pairing.

    The drawback to this was that some kernels require modifications to the ramdisk to enable/set up kernel features, and in the old AnyKernel format there was no way to do this. Enter AnyKernel2.

    AnyKernel2 pushed the format even further by allowing kernel developers to modify the underlying ramdisk for kernel feature support easily using a number of included command methods along with properties and variables to customize the installation experience to their kernel. AnyKernel3 adds the power of topjohnwu's magiskboot for wider format support by default.

    A script based on Galaxy Nexus (tuna) is included for reference. An example of ramdisk-only changes can be seen in my GN Synapse Injector repo. For an example that also modifies ROM and properly injects init.d support using busybox run-parts and sepolicy-inject see CosmicDan's CosmicTweaks project. For a multi-partition example and an example of how to handle a device which only has a ramdisk when rooted see my N5X/6P BLOD Workaround Injector. Other working AK2/3 examples for more recent devices may be found on eng.stk's blu_spark device repos under Releases.

    Please see the linked post here for instructions on working with arm64-only devices (e.g. Pixel 8 series).

    Please also see the post here for important notes about the current state of AOSP vendor_boot v4 support and AVBv2 flag options.


    Magisk root is automatically detected and retained by patching the new Image.*-dtb as Magisk would!


    My development work on my many projects comes out of my free time, so if you enjoy this project or anything else I've done on xda, please consider sponsoring my ongoing work using my GitHub Sponsors profile. For a one-time donation you can hit the donate link from my profile. Thank you for your support!


    Source:
    https://github.com/osm0sis/AnyKernel3/
    Download: https://github.com/osm0sis/AnyKernel3/archive/master.zip


    Instructions

    1)
    Place final kernel build product, e.g. Image.gz-dtb or zImage to name a couple, in the zip root (any separate dt, dtb, recovery_dtbo, dtbo and/or vendor_dlkm should also go here for devices that require custom ones, each will fallback to the original if not included)
    2) Place any required ramdisk files in /ramdisk (/vendor_ramdisk for simple multi-partition vendor_boot v3 support) and module files in /modules (with the full path like /modules/system/lib/modules)
    3) Place any required patch files (generally partial files which go with AK3 file editing commands) in /patch (/vendor_patch for simple multi-partition vendor_boot v3 support)
    4) Modify the anykernel.sh to add your kernel's name, boot partition location, permissions for any added ramdisk files, and use methods for any required ramdisk modifications (optionally, also place banner and/or version files in the root to have these displayed during flash)
    5) `zip -r9 UPDATE-AnyKernel3.zip * -x .git -x .github README.md *placeholder`

    The LICENSE file must remain in the final zip to comply with licenses for binary redistribution and the license of the AK3 scripts.


    If supporting a recovery that forces zip signature verification (like Cyanogen Recovery) then you will need to also sign your zip using the method I describe here:
    [DEV][TEMPLATE] Complete Shell Script Flashable Zip Replacement + Signing [SCRIPT]

    Not required, but any tweaks you can't hardcode into the source (best practice) should be added with an additional init.tweaks.rc or bootscript.sh to minimize the necessary ramdisk changes. On newer devices Magisk allows these within /overlay.d - see examples.

    It is also extremely important to note that for the broadest AK3 compatibility it is always better to modify a ramdisk file rather than replace it.

    If running into trouble when flashing an AK3 zip, the suffix -debugging may be added to the zip's filename to enable creation of a debug .tgz of /tmp for later examination while booted or on desktop.


    Staying Up-To-Date

    Now that you've got a ready zip for your device, you might be wondering how to keep it up-to-date with the latest AnyKernel commits. AnyKernel2 and AnyKernel3 have been painstakingly developed to allow you to just drop in the latest update-binary and tools directory and have everything "just work" for beginners not overly git or script savvy, but the best practice way is as follows:

    1) Fork my AnyKernel3 repo on GitHub
    2) `git clone https://github.com/<yourname>/AnyKernel3`
    3) `git remote add upstream https://github.com/osm0sis/AnyKernel3`
    4) `git checkout -b <devicename>`
    5) Set it up like your <devicename> zip (i.e. remove any folders you don't use like ramdisk or patch, delete README.md, and add your anykernel.sh and optionally your Image.*-dtb if you want it up there) then commit all those changes
    6) `git push --set-upstream origin <devicename>`
    7) `git checkout master` then repeat steps 4-6 for any other devices you support

    Then you should be able to `git pull upstream master` from your master branch and either merge or cherry-pick the new AK3 commits into your device branches as needed.


    Enjoy!
    Questions, comments and feedback welcome.



    Credits & Thanks: All authors of the included binaries and the tools I used to port them over for their amazing work. koush for the original AnyKernel concept.

    Disclaimer: Naturally, you take all the responsibility for what happens to your device when you start messing around with things.
    132
    Script Commands Reference

    Everything to edit is self-contained in anykernel.sh. A quick-reference for the commands and properties included are as follows.


    Properties / Variables

    These are some values that will be read during the install process, allowing you to customize your installation, e.g. block= is a shell variable to specify the kernel/boot block partition that the dump_boot command method will copy and unpack.

    Code:
    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;

    do.devicecheck=1 specified requires at least device.name1 to be present. This should match ro.product.device, ro.build.product, ro.product.vendor.device or ro.vendor.product.device from the build.prop files for your device. There is support for as many device.name# properties as needed. You may remove any empty ones that aren't being used.

    do.modules=1 will push the .ko contents of the modules directory to the same location relative to root (/) and apply correct permissions. On A/B devices this can only be done to the active slot.

    do.systemless=1 (with do.modules=1) will instead push the full contents of the modules directory to create a simple "ak3-helper" Magisk module, allowing developers to effectively replace system files, including .ko files. If the current kernel is changed then the kernel helper module automatically removes itself to prevent conflicts.

    do.cleanup=0 will keep the zip from removing its working directory in /tmp/anykernel (by default) - this can be useful if trying to debug in adb shell whether the patches worked correctly.

    do.cleanuponabort=0 will keep the zip from removing its working directory in /tmp/anykernel (by default) in case of installation abort.

    supported.versions= will match against ro.build.version.release from the current ROM's build.prop. It can be set to a list or range. As a list of one or more entries, e.g. 7.1.2 or 8.1.0, 9 it will look for exact matches, as a range, e.g. 7.1.2 - 9 it will check to make sure the current version falls within those limits. Whitespace optional, and supplied version values should be in the same number format they are in the build.prop value for that Android version.

    supported.patchlevels= and supported.vendorpatchlevels= will match against ro.build.version.security_patch and ro.vendor.build.security_patch, respectively, from the current system/vendor build.prop. It can be set as a closed or open-ended range of dates in the format YYYY-MM, whitespace optional, e.g. 2019-04 - 2019-06, 2019-04 - or - 2019-06 where the last two examples show setting a minimum and maximum.

    block=auto instead of a direct block filepath enables detection of the device boot partition for use with broad, device non-specific zips. Also accepts any partition filename (from by-name), e.g. boot, recovery, or vendor_boot.

    is_slot_device=1 enables detection of the suffix for the active boot partition on slot-based devices and will add this to the end of the supplied block= path. Also accepts auto for use with broad, device non-specific zips.

    ramdisk_compression=auto allows automatically repacking the ramdisk with the format detected during unpack. Changing auto to gz, lzo, lzma, xz, bz2, lz4, or lz4-l (for lz4 legacy) instead forces the repack as that format, and using cpio or none will (attempt to) force the repack as uncompressed.

    patch_vbmeta_flag=auto allows automatically using the default AVBv2 vbmeta flag on repack, and use the Magisk configuration (Canary 23016+). Set to 0 forces keeping whatever is in the original AVBv2 flags, and set to 1 forces patching the flag (only necessary on few devices).

    customdd="<arguments>" may be added to allow specifying additional dd parameters for devices that need to hack their kernel directly into a large partition like mmcblk0, or force use of dd for flashing.

    slot_select=active|inactive may be added to allow specifying the target slot. If omitted the default remains active.

    no_block_display=1 may be added to disable output of the detected final used partition+slot path for zips which choose to include their own custom output instead.

    no_magisk_check=1 may be added to disable detection of Magisk and related kernel/dtb repatching for special zips which don't require that.


    Command Methods

    Code:
    ui_print "<text>" [...]
    abort ["<text>" [...]]
    contains <string> <substring>
    file_getprop <file> <property>
    
    set_perm <owner> <group> <mode> <file> [<file2> ...]
    set_perm_recursive <owner> <group> <dir_mode> <file_mode> <dir> [<dir2> ...]
    
    dump_boot
    split_boot
    unpack_ramdisk
    
    backup_file <file>
    restore_file <file>
    replace_string <file> <if search string> <original string> <replacement string> <scope>
    replace_section <file> <begin search string> <end search string> <replacement string>
    remove_section <file> <begin search string> <end search string>
    insert_line <file> <if search string> before|after <line match string> <inserted line>
    replace_line <file> <line replace string> <replacement line> <scope>
    remove_line <file> <line match string> <scope>
    prepend_file <file> <if search string> <patch file>
    insert_file <file> <if search string> before|after <line match string> <patch file>
    append_file <file> <if search string> <patch file>
    replace_file <file> <permissions> <patch file>
    patch_fstab <fstab file> <mount match name> <fs match type> block|mount|fstype|options|flags <original string> <replacement string>
    patch_cmdline <cmdline entry name> <replacement string>
    patch_prop <prop file> <prop name> <new prop value>
    patch_ueventd <ueventd file> <device node> <permissions> <chown> <chgrp>
    
    repack_ramdisk
    flash_boot
    flash_generic <partition name>
    write_boot
    
    reset_ak [keep]
    setup_ak

    "if search string" is the string it looks for to decide whether it needs to add the tweak or not, so generally something to indicate the tweak already exists. "cmdline entry name" behaves somewhat like this as a match check for the name of the cmdline entry to be changed/added by the patch_cmdline function, followed by the full entry to replace it. "prop name" also serves as a match check in patch_prop for a property in the given prop file, but is only the prop name as the prop value is specified separately.

    Similarly, "line match string" and "line replace string" are the search strings that locate where the modification needs to be made for those commands, "begin search string" and "end search string" are both required to select the first and last lines of the script block to be replaced for replace_section, and "mount match name" and "fs match type" are both required to narrow the patch_fstab command down to the correct entry.

    "scope" may be specified as "global" to force all instances of the string/line targeted by replace_string, replace_line or remove_line to be replaced/removed accordingly. Omitted or set to anything else and it will perform the default first-match action.

    "before|after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string".

    "block|mount|fstype|options|flags" requires you specify which part (listed in order) of the fstab entry you want to check and alter.

    dump_boot and write_boot are the default method of unpacking/repacking, but for more granular control, or omitting ramdisk changes entirely ("OG AK" mode), these can be separated into split_boot; unpack_ramdisk and repack_ramdisk; flash_boot respectively. flash_generic can be used to flash an image to the corresponding partition. It is automatically included for dtbo and vendor_dlkm in write_boot but can be called separately if using "OG AK" mode or creating a simple partition flashing only zip.

    Multi-partition zips can be created by removing the ramdisk and patch folders from the zip and including instead "-files" folders named for the partition (without slot suffix), e.g. boot-files + recovery-files, or kernel-files + ramdisk-files (on some Treble devices). These then contain Image.gz, and ramdisk, patch, etc. subfolders for each partition. To setup for the next partition, simply set block= (without slot suffix) and ramdisk_compression= for the new target partition and use the reset_ak command.

    Similarly, multi-slot zips can be created with the normal zip layout for the active (current) slot, then resetting for the inactive slot by setting block= to the partition (without slot suffix) again, slot_select=inactive and ramdisk_compression= to the desired options for the target slot and using the reset_ak keep command, which will retain the patch and any added ramdisk files for the next slot.

    backup_file may be used for testing to ensure ramdisk changes are made correctly, transparency for the end-user, or in a ramdisk-only "mod" zip. In the latter case restore_file could also be used to create a "restore" zip to undo the changes, but should be used with caution since the underlying patched files could be changed with ROM/kernel updates.

    You may also use ui_print "<text>" to write messages back to the recovery during the modification process, abort "<text>" to abort with optional message, and file_getprop "<file>" "<property>" and contains "<string>" "<substring>" to simplify string testing logic you might want in your script.


    Binary Inclusion

    The AK3 repo includes current ARM builds of magiskboot, magiskpolicy, lptools_static, httools_static, fec, snapshotupdater_static and busybox by default to keep the basic package small. Builds for other architectures and optional binaries (see below) are available from the latest Magisk zip, or my latest AIK-mobile and Flashlt packages, respectively, here:

    https://xdaforums.com/t/tool-androi...kernel-ramdisk-win-android-linux-mac.2073775/ (Android Image Kitchen thread)
    https://xdaforums.com/t/tools-zips-scripts-osm0sis-odds-and-ends-multiple-devices-platforms.2239421/ (Odds and Ends thread)

    Optional supported binaries which may be placed in /tools to enable built-in expanded functionality are as follows:

    mkbootfs - for broken recoveries, or, booted flash support for a script/app via bind mount to /tmp (deprecated/use with caution)
    flash_erase, nanddump, nandwrite - MTD block device support for devices where the dd command is not sufficient
    dumpimage, mkimage - DENX U-Boot uImage format support
    mboot - Intel OSIP Android image format support
    unpackelf, mkbootimg - Sony ELF kernel.elf format support, repacking as AOSP standard boot.img for unlocked bootloaders
    elftool (with unpackelf) - Sony ELF kernel.elf format support, repacking 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

    Optionally moving ARM builds to tools/arm and putting x86 builds in tools/x86 will enable architecture detection for use with broad, device non-specific zips.
    48
    AnyKernel3 (AK3) Release

    Welcome to AK3: AnyKernel2 + Magisk = AnyKernel3!:
    - abstract out execution directory as $home to fascilitate testing individual scripts (defaults to /tmp/anykernel)
    - general script clean ups for uniformity, readability, speed and simplicity
    - simplify consecutive `ui_print` commands where possible

    Backend only fixes:
    - use busybox umount and mount whenever possible to avoid linker warnings in stderr during system-as-root setup
    - use `busybox --install -s` for bin/* setup
    - consolidate setup to abort earlier if there are issues
    - add backwards compatible symlinks for those who might not have updated their anykernel.sh with ak3-core.sh (to be renamed in subsequent commit)

    Tools only fixes:
    - add magiskboot to replace separate support for AOSP and PXA-AOSP formats, with MTK headers, BLOB, DHTB, SEAndroid and Nook signing
    - add magiskpolicy to allow for easy sepolicy patching
    - remove xz and lz4 since magiskboot supports these (and all other formats except lzop)
    - magiskboot also resolves long-standing request for built-in Bump support (#18)

    AK3 Core only fixes:
    - use full `ui_print` function implementation like the backend
    - add `abort` function to simplify exit on errors
    - fix $patch directory being excluded from `reset_ak`
    - update $ramdisk_compression handling for magiskboot
    - update Sony ELF and related support for initial repack as AOSP by using mkbootimg as plug-and-play optional add-in binary
    - update Sony ELF MTK header support using mkmtkhdr only when ELF is initially unpacked by unpackelf
    - add support for MTK RECOVERY ramdisk header type with Sony ELF
    - simplify U-Boot dumpimage/mkimage and Sony ELF unpackelf/mkbootimg split_img file handling
    - update patch_cmdline to handle both magiskboot as header prop file, and unpackelf or mboot as cmdline.txt
    - use `cp -fp` for `backup_file` and `restore_file` to hopefully better preserve attributes if used outside of the ramdisk
    - refactor setup into `setup_ak` to simplify `reset_ak` trigger to find slot and block again
    - add fallback to busybox for compression formats (i.e. lzop) which magiskboot cannot handle

    IMPORTANT NOTES:
    1) forcing repack with uncompressed cpio ramdisk is not currently supported by magiskboot
    2) forcing repack with lzop ramdisk when previously another format is not currently supported by magiskboot

    https://github.com/osm0sis/AnyKernel3/commit/698682123053cab9e3277c9c9df783a97b3e8958

    tools: rename ak2-core.sh to ak3-core.sh:
    https://github.com/osm0sis/AnyKernel3/commit/cba94d3103ec92380717052a69bb6e37b15ad853

    anykernel: Update for AK3:
    https://github.com/osm0sis/AnyKernel3/commit/8724d881595abd529376cb6fe2205b69a05021dd

    README: Update for AK3:
    https://github.com/osm0sis/AnyKernel3/commit/a10312941ade81955d2217caa0e90dae553bb697

    AK3: fix elftool repack cmdline handling:
    https://github.com/osm0sis/AnyKernel3/commit/c8d087bbad6442546a3f85610e3eaa2d867de021

    AK3: allow workaround for dtbo devices with cat /dev/zero issues:
    https://github.com/osm0sis/AnyKernel3/commit/24032c07328cd2ed9b7c2e57d63d351d52425cf0

    README: updates and touchups for AK3:
    https://github.com/osm0sis/AnyKernel3/commit/5fdf659d01f0fed87b44c3dbc6103d4146b694d5

    AK3: resolve non-zero return code introduced by `cat <img> /dev/zero > <block>`:
    https://github.com/osm0sis/AnyKernel3/commit/97de781a55f09cca631982511789e1ff95badc8f

    Alright! The big day is here. Huge thanks to @topjohnwu for working with me to add the necessary features to magiskboot so I could keep virtually all feature parity with AnyKernel2. Plus the rewrite to magiskboot allowed me to do a thorough code review and includes more format support by default and ensures much better ongoing format support as magiskboot continues to be developed. I wrote this intentionally so that basically all current AK2 zips should be able to be immediately upgradeable using the initial patch, or even just dropping the updated tools/core and backend in.

    Of course pay close attention to merge conflicts for the main AK3 rewrite commit and the anykernel.sh updates, especially since many have added an older version of magiskboot/magiskpolicy unofficially to their zips for root repatching, but note you will need the current included builds since they are a couple commits ahead of even the current Magisk Canary. Going forward let me keep the included ARM magiskboot/magiskpolicy up to date, since I'll be ensuring they work correctly before updating them.

    Thanks also to @eng.stk and @Freak07 for their help testing during the AK3 BETA .patch phase. I also throughly tested most things throughout the rewrite on my OnePlus 6T so things should definitely be all good for OnePlus devices. :D:highfive:

    Edit: Added a couple more commits today to resolve issues on devices where dtbo partition flashing is required. Thanks @MSF Jarvis for reporting the issue, and help testing to find a solution. :)
    18
    Happy New Year!

    Despite me being away on vacation here's a big update to module handling thanks to @nathanchance. If you are currently pushing modules with AK2 you will need to move the files under "modules/" to reflect their destination subfolder to avoid breakage, e.g. "modules/system/lib/modules/", "modules/system/vendor/lib/modules/" and/or "modules/vendor/lib/modules/"; this will be pretty future proof so was worth the while.

    update-binary: Change how we handle modules:
    https://github.com/osm0sis/AnyKernel2/commit/6b11373d4ae91b10ce4745e380ee3d4b440fbde6

    README: Update documentation for modules:
    https://github.com/osm0sis/AnyKernel2/commit/218b5774d26f1ff1c0acd3bec273153f5b529cb2

    example: Update modules folder for new location handling:
    https://github.com/osm0sis/AnyKernel2/commit/a0b6db2784a3cd121a4af768a68ec88fc97c550a
    15
    Thanks guys!

    I figured it would be nice to get it out there and also have it as a "Help Desk" thread for kernel devs who have questions about implementation, etc. too. Some devices might require switching it from dd to MTD-Utils, so I can help with that. So on and so forth. :)

    Once we get a few devs who know how to use it, it should be pretty easy to help others. I'm looking at you Smitty. ;) No pressure. :p