How to Root Android Devices via KernelSU [GKI and LKM]

kernelsu root android

kernelsu root android

In this guide, we will show you various methods through which you can root your Android device via KernelSU. When it comes to entering the custom development, then gaining administrative privileges and getting access to the system partition are two of the most preferred tweaks for tech enthusiasts. Up until now, your only course of action was to patch the stock boot/init_boot image and then flash it via Fastboot Commands.

However, there’s now a new player in town and it takes a completely different approach to getting this job done- by taking the help of the kernel instead of boot. So in this guide, we will show you the steps to root all supported Android devices via KernelSU using three nifty methods. But first let’s try and understand what exactly is this tool, its different modes, their benefits, and which one should you ultimately opt for. So without further ado, let’s get started.

What is KernelSU?

KernelSU is a rooting method for Android devices that comes with a Generic Kernel Image. It carries out its functions in kernel mode and grants root permission to applications directly in the kernel space. Moroever, since this is kernel-based, in other words, working in kernel mode, it is able to provide a kernel interface that allows you to carry out a plentitude of tweaks, which includes the likes of adding a hardware breakpoint to any process in kernel mode.

kernelsu root android

Similar to how you could flash a GSI ROM to any Project Treble device, you will be able to root your device using a Generic Kernel Image. However, similar to the Project Treble requirement for GSI, the KernelSU also has its own requirements, the most important among which is that the device should have a GKI Kernel [we will explain to you how to check if your device has a GKI kernel or not]. Furthermore, it should be running Android 12 or higher versions.

Unfortunately, there are many Android devices out there that don’t have a GKI Kernel. For those sets of devices, users could build their own kernel from scratch or use a prebuilt one [which sometimes might prove to be a risky approach]. Keeping all these points in mind, let’s now get started with the steps to root your Android device via KernelSU. Follow along.

What are the Different Modes of KernelSU

KernelSU provides rooting in two different modes: Generic Kernel Image and Loadable Kernel Module. In GKI mode, the original kernel of the device will be replaced with the generic kernel image provided by KernelSU. On the other hand, in LKM mode,  the original kernel of the device will not be replaced, however, the loadable kernel module will be loaded into the device kernel.

Benefits of GKI Mode

  • As compared to LKM, a GKI module is compatible with many more devices.
  • There is no need to rely on the OEM and wait for them to release kernel updates [till the KMI is consistent].

Benefits of LKM Mode

  • This is the perfect option to go with if you are planning to make some tweaks to the stock kernel or wish to use a custom kernel.
  • Easier to update devices and install OTA updates when compared with GKI.
  • Moroever, LKM can also be loaded with temporary ROOT permissions. Since it does not replace the boot partition, it will not trigger the Android Verified Boot and will not lead to any problems for your device.
  • You can even temporarily disable root access by uninstalling LKM. You may then re-enable the root access just by doing a restart!

Should I Choose KernelSU GKI or LKM

If you are using an Android device [smartphone, then you should opt for LKM. On the other hand, if you are using an emulator or Windows Subsystem for Android, then consider using the GKI.

The Prerequisites to Root Android via KernelSU

Given below are the prerequisites to root your Android device via the GKI and LKM Modes of KernelSU. You’ll have to carry out these steps irrespective of the method you opt for. But before starting with any of the methods, please take a complete device backup. Thedroidwin will not be held responsible if something happens to your device or data after performing the below steps.

STEP 1: Check If Device has GKI Kernel

The single most important check that you need to perform is to verify if your device supports GKI Kernel or not. If it doesn’t, then none of the methods given below will work on your device and you’ll have to stick with the Magisk method of rooting the device. Here’s how it could be done:

  1. Go to the KernelSU Downloads section on the GitHub.
  2. Then click on Show All Releases and scroll to the end.
  3. Next up, download the KernelSU APK file and install it.
  4. Launch the app and verify the result. It will say either:
    Unsupported: KernelSU only supports GKI Kernels now
    Not Installed: Click To Install

    kernelsu root android

  5. If it says Unsupported, then KernelSU won’t work on your device:
    According to KernelSU, in case of Unsupported: You should compile the kernel yourself, KernelSU won't and never provide a boot image for you to flash.
  6. If it says Not Installed, then KernelSU is supported on your device.
    According to KernelSU, in case of Not Installed: Your device is officially supported by KernelSU

STEP 2: Download Android SDK Platform Tools

Next up, you’ll have to get hold of Google’s Android SDK Platform Tool so that you can execute the ADB Commands. So get it from our guide and then extract it anywhere on your PC.

android sdk platform tools

STEP 3: Backup Boot Partition

You should consider backing up the stock boot.img. This is because if something goes wrong during the process[ bootloop or softbrick], then you could easily bring ypir device back to life by flashing the stock boot.img file via Fastboot. So download the same firmware version that is currently installed on your device [you may verify the same from the Build Version], extract the boot.img file, and transfer it to the platform tools folder.

STEP 4: Enable USB Debugging and OEM Unlocking

You’ll now have to enable USB Debugging and OEM Unlocking. The former is required so that your PC is able to identify the connected device in ADB Mode whereas the latter is used to unlock the bootloader on your device. So let’s now enable both these toggles, for which you may either check out our detailed guide on How to Enable USB Debugging on Android Devices or refer to the below shorter instructions:

  1. Head over to Settings > About Phone > Tap on Build Number 7 times.
  2. Go to Settings > System > Developer Options > Enable OEM Unlock.
  3. Then enable USB Debugging and tap on OK in the prompt that appears.oem unlocking android

STEP 5: Unlock Bootloader

Irrespective of the method you opt for rooting, unlocking the bootloader on your device is a must. So refer to our detailed guide on How to Unlock the Bootloader on any Android Device. Do keep in mind that doing so will wipe off all the data from your device and might nullify its warranty as well.

unlock bootloader confirm

STEP 5: Find the Kernel Module Interface

Next up, you’ll have you’ll have to find the Kernel Module Interface for your device. Only the kernel versions with the same KMI are compatible. So to find it, first off, refer to the below Kernel Version Format

KernelRelease :=
Version.PatchLevel.SubLevel-AndroidRelease-KmiGeneration-suffix
w      .x         .y       -zzz           -k            -something

Here, w.x-zzz-k is the KMI version. For example, if a device has a kernel version is 5.10.101-android12-9-g30979850fc20, then its KMI is 5.10-android12-9. Do note that the SubLevel [y] in the kernel version does not impact the KMI version. Therefore, 5.10.101-android12-9-g30979850fc20 has the same KMI as 5.10.137-android12-9-g30979850fc20 even though the patch levels are different [101 and 107, respectively].

EXAMPLE 2: In the screenshot for my device that I will be using throughout this guide, the Kernel Version Format is:

5.10.198-android13-4-00036-g11d7e4f57f68-ab1139
w= 5
x= 10
y= 198
zzz= android 13
k= 4
something= 00036-g11d7e4f57f68-ab1139

Therefore, the KMI Version, which is w.x-zzz-k, translates to5.10-android13-4for my device.

NOTE: The Android OS version is not necessarily the same as the version number of the Linux kernel [the former could be greater than the latter as well]. So if your kernel version isandroid12-5.10.101, but your Android system version is Android 13 or other, then it’s completely normal and nothing to worry about.

STEP 6: Verify Security Patch

Apart from taking note of the KMI Version, you should also keep a tab on the Security Patch Level. To eb more precise, you cannot flash a kernel if it has a lower security patch level, even though the KMI versions of both the kernels are the same. For example, if the current kernel version is 5.10.101-android12-9-g30979850fc20 and has a security patch of December 2023.

But if you’re flashing a kernel having version 5.10.101-android12-9-g30979850fc20 and a security patch of July 2023, then it will lead to a bootloop. This is because even though the KMIs are the same, the security patch is undergoing a downgrade, which is a big no. So you should only download the kernel with the security patch or higher than the current one [which in this case should be >= December 2023].

How to Root Android via KernelSU LKM

There exist quite a few methods when it comes to rooting Android via LKM in KernelSU. Go through each of these methods once and then try out the one that is in sync with your requirements.

Via Stock Firmware

First off, verify if your device supports the fastboot boot command or not. If it does, then there’s no need to download the stock firmware and extract the boot.img. Instead you may directly download the GKI Kernel provided by KernelSU and flash it as explained below.

On the other hand, if your device doesn’t support temporary boot [fastboot boot], then you have no choice but to download the firmware [the same version that is currently installed on your device] and extract the boot.img file from it. After that, you may try out the KernelSU Manager “Select and patch a file” method, as explained in the next section [skip tis method].

NOTE: If your device came with an Android 13 or higher version out of the box, then LKM mode will modify the ramdisk, so it needs to patch the init_boot partition instead of the boot partition. With that said, let’s now get started with the steps:

  1. First off, download the GKI Kernel provided by KernelSU to the platform-tools folder.
  2. Make sure that the kernel is in sync with the KMI and Security Patch Level.
  3. Then open Command Prompt inside the platform-tools and type in the below command:
    adb reboot bootloader

    kernelsu root android

  4. Then temporarily boot the GKI kernel provided by KernelSU via the below command:
    fastboot boot boot.img

    kernelsu root android

  5. Now install the KernelSU manager and finally install it directly in the manager.

Via KernelSU Manager

If your device does not support fastboot boot or if the available kernels are not compatible with your devices [such as Pixels, which requires manual patching, explained at the end], then in those cases, you could opt for this method. So launch KernelSU Manager and tap on the Install icon at the top right. You’ll be provided with three options: Select and patch a file, Install directly, and Install to another partition. Here’s what each of these options signifies:

kernelsu manager

NOTE: “Non-rooted users” will only see the Select and Patch a File option as the other two require a rooted device beforehand.

Select and patch a file

  1. If your device is currently non-rooted then choose this option
  2. Now select your official firmware. KernelSU will then patch it.
  3. Once done, transfer the patched file to the platform-tools folder.
  4. Then open Command Prompt and type in the below command:
    adb reboot bootloader

    kernelsu root android

  5. Now use the below command to flash the KernelSU patched boot
    fastboot flash boot boot.img

    fastboot flash boot root

  6. Now use the below command to boot your device to the rooted OS
    fastboot reboot

Install Directly

If your device is already rooted and you’re just planning to upgrade the KernelSU, then this should be your go-to method. So choose this option and the KernelSU manager will automatically get your device information, patch the official firmware, and subsequently flash it. Your device will then boot to the upgraded KernelSU module.

Install to Another Partition

Use this method if you want to retain root after OTA. It’s just that your device should support an A/B partition [which nearly every Android device supports, still you may perform this check via the Trenle Info app]. If that’s well and good, then here’s how to use this feature:

  1. First off, download and install the OTA update on your device.
  2. Then launch KernelSU, tap on the Install icon at the top right, and choose Install to Another Partition.
  3. The manager will now automatically patch the official firmware and then install it to another partition.
  4. Once done, restart the device. The slots will be changed and device will boot to the rooted updated OS!

How to Root Android via KernelSU GKI

There exist four different methods though which you can root your Android device via LKM in KernelSU. Go through each of these methods once and then try out the one that is in sync with your requirements.

Using Boot.img provided by KernelSU

  1. Download the correct boot.img from GitHub using the KMI version of your kernel [see STEP 5 Prerequisites].
  2. There might be three boot files in different formats having the same KMI and security patch levels, the only difference being in the kernel compression format.
  3. So you’ll have to check the kernel compression format for your stock boot.img and then download the file accordingly. For example, Xiaomi usually use gz or uncompressed.
  4. Now transfer this boot.img file to the platform-tools folder.
  5. Likewise, open Command Prompt inside the platform-tools folder.
  6. Then type in the below command to boot your device to Fastboot Mode
    adb reboot bootloader

    fastboot mode pixel

  7. Now if your device supports temporary boot, then use the below command to temporarily boot your device to the rooted OS. If everything works well and good, then you may do the permanent installation.
    fastboot boot boot.img

    kernelsu root android

  8. If your device doesn’t support fastboot boot or if it does and you are now looking for permanent root, then in both these cases, use the below command to permanently flash the boot.img:
    fastboot flash boot boot.img

    fastboot flash boot root

  9. Finally, use the below command to boot your device to the rooted OS:
    fastboot reboot

By Extracting Boot.img

While lz4gz and uncompressed are some of the most common boot.img compression formats, however, not all OEMs follow this. For instance, for Pixel devices, the boot.img format is lz4_legacy compressed and the ramdisk may be gz or could also be lz4_legacy compression. So in such cases, directly flashing the boot.img provided by KernelSU might not work.

So what else could be done? Well, you’ll have to manually patch the boot.img and get the job done. This process could be carried out via magiskboot, both on your PC as well as directly on your Android device. We have listed the steps for both, you may refer to the one that is in sync with your requirements.

Via magiskboot on Phone

  1. Download the latest Magisk APK file from its official GitHub page.
  2. Now rename the Magisk APK to Magisk ZIP and then unzip the file.
  3. After that, transfer this file to the platform-tools folder on your PC.
  4. Likewise, open the Command Prompt window inside this folder.
  5. Now type in the below command to transfer the libmagiskboot.so file from Magisk to the tmp directory of magiskboot on your device.
    adb push Magisk/lib/arm64-v8a/libmagiskboot.so /data/local/tmp/magiskboot
  6. Now download the AnyKernel3 ZIP corresponding to your kernel’s KMI [see Prerequisite STEP 5].
  7. Then extract it and transfer the Image file to your device. Also, transfer the stock boot.img to your device.
  8. Now type in the below command in the CMD window:
    adb shell
  9. Then change the directory via:
    cd /data/local/tmp/
  10. Now execute the below command
    chmod +x magiskboot
  11. Again, open the shell environment via:
    adb shell
  12. Likewise, change the current directory:
    cd /data/local/tmp/
  13. Now unpack the boot.img via the below command:
    ./magiskboot unpack boot.img
  14. You will get a kernel file, this is your stock kernel.
  15. Replace kernel with Image by running the below command:
    mv -f Image kernel
  16. Finally, execute the below command to repack the boot.img file:
    ./magiskboot repack boot.img
  17. You will get a new-boot.img file, transfer it to platform-tools.
  18. Now boot your device to Fastboot Mode via the below command:
    adb reboot reboot
  19. Then use the below command to flash the new boot-img file:
    fastboot flash boot new-boot.img
  20. Note: If supported by your device, you may also temporarily boot:
    fastboot boot new-boot.img
  21. Then use the fastboot flash boot new-boot.img for permanent root.
  22. Finally, boot your device to the rooted OS via the below command
    fastboot reboot

Via magiskboot on PC

  1. Download the magiskboot for your OS from here.
  2. Now download the AnyKernel3 ZIP corresponding to your kernel’s KMI [see Prerequisite STEP 5].
  3. Then extract it and transfer the Image file to your device. Also, transfer the stock boot.img to your device.
  4. Now type in the below command in the CMD window:
    adb shell
  5. Then change the directory via:
    cd /data/local/tmp/
  6. Now execute the below command
    chmod +x magiskboot
  7. Again, open the shell environment via:
    adb shell
  8. Likewise, change the current directory:
    cd /data/local/tmp/
  9. Now unpack the boot.img via the below command:
    ./magiskboot unpack boot.img
  10. You will get a kernel file, this is your stock kernel.
  11. Replace kernel with Image by running the below command:
    mv -f Image kernel
  12. Finally, execute the below command to repack the boot.img file:
    ./magiskboot repack boot.img
  13. You will get a new-boot.img file, transfer it to platform-tools.
  14. Now boot your device to Fastboot Mode via the below command:
    adb reboot reboot
  15. Then use the below command to flash the new boot-img file:
    fastboot flash boot new-boot.img
  16. Note: If supported by your device, you may also temporarily boot:
    fastboot boot new-boot.img
  17. Then use the fastboot flash boot new-boot.img for permanent root.
  18. Finally, boot your device to the rooted OS via the below command
    fastboot reboot

Via Android Image Kitchen

  1. To begin with, extract the boot.img from the stock firmware.
    Root Android KernelSU
  2. Make sure it is the same version that is installed on your device.
  3. Then download and extract Android Image Kitchen on your PC.
    Root Android KernelSU
  4. Now transfer the stock boot.img inside the Android Image Kitchen folder.
    Root Android KernelSU
  5. Then download and extract AnyKernel3 ZIP file that corresponds to your KMI.
    Root Android KernelSU
  6. For example, if your KMI is 5.10.149-android13-4, then download the one which corresponds to this format:
    android13-5.10.149_yyyy-MM.boot-<format>.img
  7. Now open the CMD window inside the Android Image Kitchen folder and type in the below command to extract the boot.img
    unpackimg.bat boot.img

    Root Android KernelSU

  8. It will now unpack boot.img and you will get a couple of files. Replace boot.img-kernel in the split_img directory with the Image you extracted from AnyKernel3.
    Root Android KernelSU
  9. Make sure to rename the Image boot.img-kernel. Once done, type in the below command to repack the boot.img
    repackimg.bat

    Root Android KernelSU

  10. You’ll get image-new.img, and transfer it to the platform-tools folder. Then open the CMD window inside this folder.
    Root Android KernelSU
  11. Now type in the below command to boot your device to Fastboot Mode
    adb reboot bootloader
  12. Then execute the below command to temporary boot via the patched boot.img:
    fastboot boot image-new.img

    Root Android KernelSU

  13. If everything’s working well and good, then reboot your device to Fastboot Mode.
  14. If it’s not, then just do a normal restart, and your device will be booted to the OS.
  15. Now type in the below command to permanently flash this boot.img:
    fastboot flash boot image-new.img
  16. Finally, type in the below command to boot your device to the rooted OS:
    fastboot reboot

    Root Android KernelSU

Via Custom Recovery

You could also root your Android device via KernelSU by taking the help of a custom recovery like TWRP. While it’s among the easiest and shortest methods out there, but not every device has a custom recovery and that is why it isn’t used much. But if your device does have a recovery, then here’s how you can carry out this task:

  1. Download the correct version of the AnyKernel3 ZIP and then transfer it to your device.
  2. Use the correct KMI and the Security Patch Level [refer to STEP 5 and 6 of Prerequisite].
  3. Now download and install the TWRP Recovery on your device [skip if already installed].
  4. Open CMD inside platform-tools and use the below command to boot the device to TWRP
    adb reboot recovery
  5. From TWRP, go to Install, select the AnyKernel ZIP, and perform a right-swipe to flash it.
  6. Once done, you may now reboot your device to the rooted OS by going to Reboot > System.

Root Android KernelSU

Via a Kernel Flasher App

This is among the easiest methods to root your Android device via KernelSU. Moreover, this might be the only method that might work for users who are unable to directly obtain root via KernelSU. However, it has the biggest drawbacks as well- your device needs to be rooted via Magisk. So why would anyone use this method? Well, it could come in handy when you are looking to upgrade the KernelSU and it doesn’t require the use of PC either!

NOTE: Even if your device is currently not rooted, you could still use this method, granted your device supports temporary root [if that is not the case and you still want to use this method, then check out the “Can I Root via Magisk and then use KernelSU?” section below]. So download the boot.img provided by KernelSU and temporarily boot your device to it via the fastboot boot boot.img command. Once you have obtained a temporary root, proceed with the below steps to make it permanent.

  1. To begin with, download the correct version of the AnyKernel3 ZIP.
  2. Use the correct KMI and the Security Patch Level [refer to STEP 5 and 6 of Prerequisite].
  3. Download and install Franko Kernel Manager from the Play Store.
  4. Then launch it and tap Grant in the Magisk pop-up.
  5. Now tap on Manual Flasher and select Flasher.
    Root Android KernelSU
  6. Then select the kernel.zip file and hit Flash & Reboot.
  7. The flashing will now begin. Once done, your device will boot to the rooted OS.

Can I Root via Magisk and then use KernelSU?

Yes, you can root your device via Magisk, then install KernelSU, give it the required SuperUser permissions, and obtain root via any of the desired methods listed in this guide. Once that is done, you may then remove Magisk from your device. This way you’ll have a rooted device using just the KernelSU! Here’s how it could be done:

  1. To begin with, root your device via Magisk patched boot/init_boot.
  2. Then obtain root via KernelSU using any of the methods listed here.
  3. Kernel Flasher might be the most straightforward method out there.
  4. So once you have obtained root via KernelSU, launch the Magisk app.
  5. Then tap on Uninstall Magisk > Complete Uninstall > Restart Device.
  6. Your device will ‘still’ reboot to the rooted OS with KernelSU installed.

Install OTA Rooted Android

Can KernelSU GKI and LKM Coexist?

Yes, both the Generic Kernel Image and Loadable Kernel Module of KernelSU can co-exist, however, the priority of the GKI mode will be higher than that of LKM. Let’s understand it with the help of an example. Suppose, you use a GKI Kernel to replace the original kernel and then use LKM to patch the GKI kernel, then in that case, LKM will be ignored and the device will always run in GKI mode.

That’s it. These were the various methods through which you can root your Android device via KernelSU. If you have any queries concerning the aforementioned steps, do let us know in the comments. We will get back to you with a solution as soon as possible.

How to Flash Modules via KernelSU

Proceed with the below steps to flash the desired modules using KernelSU.

  1. Download the desired module ZIP file to your device.
  2. Then launch KernelSU and go to the Modules section.
  3. Tap on Install, navigate to the module zip, and select it.flash module kernelsu
  4. It will now be flashed. Once done, hit the Reboot button.
  5. Device will boot to OS and the module will be activated.

How to Unroot any Android Device via KernelSU

If you have obtained root via KernelSU, then here’s how to unroot your Android device via it:

  1. Launch KernelSU, go to Modules, and disable and uninstall all of them.
  2. Then go to Home, tap on the Settings icon at the top right > tap Uninstall.uninstall kernelsu unroot android
  3. Now select Uninstall Permanently and tap OK in the prompt that appears.
  4. Finally, restart your device. KernelSU is removed and your device stands unrooted.

Leave a Reply

Your email address will not be published. Required fields are marked *