Over time, I’ve fallen into some misconceptions... What was essentially a simple task ended up wasting a lot of time.
So, I decided to write this article to help others in the future, hoping they don’t repeat the mistakes I made.
Cover Image ©Copyright: BiliBili @KoraCola "When you finally look up, the universe is slowly turning."
Warning: this article is mostly translated by ChatGPT from Chinese
Introduction
Nethunter is a popular open-source project, but many of its cool features require kernel support to truly bring it to life, due to the system-level and low-level demands. This greatly limits the ability to tinker with "unofficially supported devices." However, to uphold the spirit of open-source, the Kali project team has provided a way to compile any non-GKI kernel into the Nethunter format. Of course, if your device supports GKI, you can simply flash the official lite module.
Project Source
https://gitlab.com/kalilinux/nethunter/build-scripts/kali-nethunter-kernel
Compilation Requirements
An open-source kernel that can be compiled
(You’ll need a reliable defconfig file. If the kernel project has some stars, it might be worth considering. If your defconfig file cannot be used directly with make, subsequent steps will be futile.)
Compilation Method
A reliable compiler
I recommend Neutron Clang. Their documentation provides clear troubleshooting steps.
Clone your chosen kernel project
git clone <kernel_project_URL>
Navigate to the project root directory:
cd <project_directory>
git clone https://gitlab.com/kalilinux/nethunter/build-scripts/kali-nethunter-kernel
Modify the local.config
Use the local.config.example in the kali-nethunter-kernel folder as a reference and customize it. Only keep the parameters you need, i.e., only those you truly understand.
Run ./build.sh
Select option 2 for compilation. (If you are using a third-party compiler, you can still try the built-in Google Clang, but I personally prefer Neutron Clang.)
Make module
Create the AnyKernel module in the build.sh menu to enable flashing.
Finally, for any issues, you can always ask ChatGPT!
If You Need a Template, you can refer to my fork:
https://github.com/SherlockChiang/kali-nethunter-kernel
https://github.com/SherlockChiang/kernel_xiaomi_sm8250_nethunter
Update
Additionally, beginners may face some challenges with devices that don’t directly provide a defconfig file, such as the official LOS open-source kernel for the K30S.
The solution is actually quite simple. Let’s look at the file directory structure below.
The top image shows the contents of the vendor folder, while the bottom shows the Xiaomi path under the vendor folder, which contains device-specific configurations.
We can infer a lot from the file’s modification times. Here, we are using kona_defconfig (as I didn’t want to use konaperf for overclocking but instead needed power-saving). Afterward, we merge the general Xiaomi vendor config sm8250-common.config and the K30S-specific config apollo.config into it using the following command:
cat apollo.config >> kona_defconfig