How to integrate HyperSU
Notes
This document modified from KernelSU Official Documentation
HyperSU can be integrated into non-GKI kernels and was backported to 3.4 and earlier versions.
Due to the fragmentation of non-GKI kernels, we don't have a universal way to build them; therefore, we cannot provide a non-GKI boot.img. However, you can build the kernel with HyperSU integrated on your own.
First, you should be able to build a bootable kernel from kernel source code. If the kernel isn't open source, then it is difficult to run HyperSU for your device.
If you're able to build a bootable kernel, you can add HyperSU into your kernel by following this guide.
Building Kernel
WARNING
This part is for GKI devices
Sync the kernel source code
repo init -u https://android.googlesource.com/kernel/manifest
mv <kernel_manifest.xml> .repo/manifests
repo init -m manifest.xml
repo syncThe <kernel_manifest.xml> file is a manifest that uniquely identifies a build, allowing you to make it reproducible. To do this, you should download the manifest file from GKI release builds.
Build
Please check the Building kernels first.
For example, to build an aarch64 kernel image:
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.shDon't forget to add the LTO=thin flag; otherwise, the build may fail if your computer has less than 24 GB of memory.
Starting from Android 13, the kernel is built by bazel:
tools/bazel build --config=fast //common:kernel_aarch64_distBuild kernel with HyperSU
First, add HyperSU to your kernel source tree. Run this from the root of your kernel source.
For GKI devices:
curl -LSs "https://raw.githubusercontent.com/HyperSU-Team/HyperSU/main/kernel/setup.sh" | bashFor non-GKI devices:
curl -LSs "https://raw.githubusercontent.com/HyperSU-Team/HyperSU/builtin/kernel/setup.sh" | bashThe script checks out the matching branch and wires HyperSU into your tree; no extra arguments are needed.
Manual hooks
TIP
Keep in mind that, on some devices, your defconfig may be located at arch/arm64/configs or in other cases, it may be at arch/arm64/configs/vendor/your_defconfig. Regardless of the defconfig you're using, make sure to enable CONFIG_KSU with y to enable or n to disable it. For example, if you choose to enable it, your defconfig should contain the following string:
arch/arm64/configs/...
+# HyperSU
+CONFIG_KSU=y
+CONFIG_KSU_MANUAL_HOOK=yThen,add HyperSU's hooks into your kernel, and build your kernel again, and HyperSU should work correctly.
SUSFS
WARNING
SUSFS is no longer supported for NonGKI kernels,if you want to use SUSFS on NonGKI kernel, please manually backport the patches from gki-android12-5.10 branch.
DANGER
HyperSU's SUSFS part of the kernel code is updated from the SUSFS repository. If you encounter build errors or boot problems, please CHECK the update log of the SUSFS repository FIRST.
if you are sure that HyperSU's SUSFS part of the kernel code has not been updated, please report this issue to HyperSU.
TIP
Keep in mind that, on some devices, your defconfig may be located at arch/arm64/configs or in other cases, it may be at arch/arm64/configs/vendor/your_defconfig. Regardless of the defconfig you're using, make sure to enable CONFIG_KSU with y to enable or n to disable it. For example, if you choose to enable it, your defconfig should contain the following string:
arch/arm64/configs/...
+# HyperSU
+CONFIG_KSU=y
+CONFIG_KSU_SUSFS=yThen, in the SUSFS repository, choose the branch that matches your kernel version and apply the kernel-side patches as instructed; after making the changes, rebuild the kernel.