Difference with Magisk
Although KernelSU and Magisk modules have many similarities, there are inevitably some differences due to their completely different implementation mechanisms. If you want your module to work on both Magisk and KernelSU, it's essential to understand these differences.
Similarities
- Module file format: Both use the ZIP format to organize modules, and the module format is practically the same.
- Module installation directory: Both are located at
/data/adb/modules. - Systemless: Both support modifying
/systemin a systemless way through modules. - post-fs-data.sh: Execution time and semantics are exactly the same.
- service.sh: Execution time and semantics are exactly the same.
- system.prop: Completely the same.
- sepolicy.rule: Completely the same.
- BusyBox: Scripts are run in BusyBox with "Standalone Mode" enabled in both cases.
Differences
Before understanding the differences, it's important to know how to identify whether your module is running in KernelSU or Magisk. You can use the environment variable KSU to differentiate it in all places where you can run module scripts (customize.sh, post-fs-data.sh, service.sh). In KernelSU, this environment variable will be set to true.
Here are some differences:
- KernelSU modules cannot be installed in Recovery mode.
- KernelSU modules don't have built-in support for Zygisk, but you can use Zygisk modules through ZygiskNext.
- The method for replacing or deleting files in KernelSU modules is completely different from Magisk. KernelSU doesn't support the
.replacemethod. Instead, you need to create a same-named file withmknod filename c 0 0to delete the corresponding file. - The directories for BusyBox are different. The built-in BusyBox in KernelSU is located at
/data/adb/ksu/bin/busybox, while in Magisk it is at/data/adb/magisk/busybox. Note that this is an internal behavior of KernelSU and may change in the future! - KernelSU doesn't support
.replacefiles, but it supports theREMOVEandREPLACEvariables to remove or replace files and folders. - KernelSU adds the
boot-completedstage to run scripts after the boot process is finished. - KernelSU adds the
post-mountstage to run scripts after OverlayFS is mounted.