Cách cài đặt
Kiểm tra xem thiết bị của bạn có được hỗ trợ không
Tải xuống APP KernelSU manager từ GitHub Releases và cài đặt nó vào thiết bị của bạn:
- Nếu ứng dụng hiển thị
Unsupported, nghĩa là Bạn nên tự biên dịch kernel, KernelSU sẽ không và không bao giờ cung cấp boot image để bạn flash. - Nếu ứng dụng hiển thị
Not installedthì thiết bị của bạn đã được KernelSU hỗ trợ chính thức.
INFO
Đối với các thiết bị hiển thị Unsupported, đây là Thiết-bị-hỗ-trợ-không-chính-thức, bạn có thể tự biên dịch kernel.
Sao lưu stock boot.img
Trước khi flash, trước tiên bạn phải sao lưu stock boot.img. Nếu bạn gặp phải bootloop (vòng lặp khởi động), bạn luôn có thể khôi phục hệ thống bằng cách quay lại trạng thái khởi động ban đầu bằng fastboot.
WARNING
Việc flash có thể gây mất dữ liệu, hãy đảm bảo thực hiện tốt bước này trước khi chuyển sang bước tiếp theo!! Bạn cũng có thể sao lưu tất cả dữ liệu trên điện thoại nếu cần.
Kiến thức cần thiết
ADB và fastboot
Theo mặc định, bạn sẽ sử dụng các công cụ ADB và fastboot trong hướng dẫn này, vì vậy nếu bạn không biết về chúng, chúng tôi khuyên bạn nên sử dụng công cụ tìm kiếm để tìm hiểu về chúng trước tiên.
KMI
Kernel Module Interface (KMI), các phiên bản kernel có cùng KMI đều tương thích Đây là ý nghĩa của "general" trong GKI; ngược lại, nếu KMI khác thì các kernel này không tương thích với nhau và việc flash kernel image có KMI khác với thiết bị của bạn có thể gây ra bootloop.
Cụ thể, đối với thiết bị GKI, định dạng phiên bản kernel phải như sau:
KernelRelease :=
Version.PatchLevel.SubLevel-AndroidRelease-KmiGeneration-suffix
w .x .y -zzz -k -somethingw.x-zzz-k là phiên bản KMI. Ví dụ: nếu phiên bản kernel của thiết bị là 5.10.101-android12-9-g30979850fc20, thì KMI của nó là 5.10-android12-9; về mặt lý thuyết, nó có thể khởi động bình thường với các kernel KMI khác.
TIP
Lưu ý rằng SubLevel trong phiên bản kernel không phải là một phần của KMI! Điều đó có nghĩa là 5.10.101-android12-9-g30979850fc20 có cùng KMI với 5.10.137-android12-9-g30979850fc20!
Phiên bản kernel vs Phiên bản Android
Xin lưu ý: Phiên bản kernel và phiên bản Android không nhất thiết phải giống nhau!
Nếu bạn nhận thấy phiên bản kernel của mình là android12-5.10.101 nhưng phiên bản hệ thống Android của bạn là Android 13 hoặc phiên bản khác; xin đừng ngạc nhiên, vì số phiên bản của hệ thống Android không nhất thiết phải giống với số phiên bản của kernel Linux; Số phiên bản của kernel Linux nhìn chung nhất quán với phiên bản của hệ thống Android đi kèm với thiết bị khi nó được xuất xưởng. Nếu hệ thống Android được nâng cấp sau này, phiên bản kernel thường sẽ không thay đổi. Nếu bạn cần flash, vui lòng tham khảo phiên bản kernel!!
Giới thiệu
Có một số phương pháp cài đặt KernelSU, mỗi phương pháp phù hợp với một kịch bản khác nhau, vì vậy vui lòng chọn khi cần.
- Cài đặt với Recovery tùy chỉnh (ví dụ TWRP)
- Cài đặt bằng ứng dụng flash kernel, chẳng hạn như Franco Kernel Manager
- Cài đặt thông qua fastboot bằng boot.img do KernelSU cung cấp
- Sửa boot.img theo cách thủ công và cài đặt nó
Since version 0.9.0, KernelSU supports two running modes on GKI devices:
GKI: Replace the original kernel of the device with the Generic Kernel Image (GKI) provided by KernelSU.LKM: Load the Loadable Kernel Module (LKM) into the device kernel without replacing the original kernel.
These two modes are suitable for different scenarios, and you can choose the one according to your needs.
GKI mode
In GKI mode, the original kernel of the device will be replaced with the generic kernel image provided by KernelSU. The advantages of GKI mode are:
- Strong universality, suitable for most devices. For example, Samsung has enabled KNOX devices, and LKM mode cannot work. There are also some niche modified devices that can only use GKI mode.
- Can be used without relying on official firmware, and there is no need to wait for official firmware updates, as long as the KMI is consistent, it can be used.
LKM mode
In LKM mode, the original kernel of the device won't be replaced, but the loadable kernel module will be loaded into the device kernel. The advantages of LKM mode are:
- Won't replace the original kernel of the device. If you have special requirements for the original kernel of the device, or you want to use KernelSU while using a third-party kernel, you can use LKM mode.
- It's more convenient to upgrade and OTA. When upgrading KernelSU, you can directly install it in the manager without flashing manually. After the system OTA, you can directly install it to the second slot without manual flashing.
- Suitable for some special scenarios. For example, LKM can also be loaded with temporary root permissions. Since it doesn't need to replace the boot partition, it won't trigger AVB and won't cause the device to be bricked.
- LKM can be temporarily uninstalled. If you want to temporarily disable root access, you can uninstall LKM. This process doesn't require flashing partitions, or even rebooting the device. If you want to enable root again, just reboot the device.
COEXISTENCE OF TWO MODES
After opening the manager, you can see the current mode of the device on the homepage. Note that the priority of GKI mode is higher than that of LKM. For example, if you use GKI kernel to replace the original kernel, and use LKM to patch the GKI kernel, the LKM will be ignored, and the device will always run in GKI mode.
Which one to choose?
If your device is a mobile phone, we recommend that you prioritize LKM mode. If your device is an emulator, WSA, or Waydroid, we recommend that you prioritize GKI mode.
LKM installation
Get the official firmware
To use LKM mode, you need to get the official firmware and patch it based on the official firmware. If you use a third-party kernel, you can use the boot.img of the third-party kernel as the official firmware.
There are many ways to get the official firmware. If your device supports fastboot boot, we recommend the most recommended and simplest method is to use fastboot boot to temporarily boot the GKI kernel provided by KernelSU, then install the manager, and finally install it directly in the manager. This method doesn't require manually downloading the official firmware or manually extracting the boot.
If your device doesn't support fastboot boot, you may need to manually download the official firmware package and extract the boot from it.
Unlike GKI mode, LKM mode modifies the ramdisk. Therefore, on devices with Android 13, it needs to patch the init_boot partition instead of the boot partition, while GKI mode always operates on the boot partition.
Use the manager
Open the manager, click the installation icon in the upper right corner, and several options will appear:
- Select a file. If your device doesn't have root privileges, you can choose this option and then select your official firmware. The manager will automatically patch it. After that, just flash this patched file to obtain root privileges permanently.
- Direct install. If your device is already rooted, you can choose this option. The manager will automatically get your device information, and then automatically patch the official firmware, and flash it automatically. You can consider using
fastboot bootKernelSU's GKI kernel to get temporary root and install the manager, and then use this option. This is also the main way to upgrade KernelSU. - Install to inactive slot. If your device supports A/B partition, you can choose this option. The manager will automatically patch the official firmware and install it to another partition. This method is suitable for devices after OTA, you can directly install it to the inactive slot after OTA.
If you don't want to use the manager, you can also use the command line to install LKM. The ksud tool provided by KernelSU can help you patch the official firmware quickly and then flash it.
The usage of ksud is as follows:
ksud boot-patchUsage: ksud boot-patch [OPTIONS]
Options:
-b, --boot <BOOT> Boot image be patched
-l, --lkm <LKM> LKM module path. If not specified, the built-in module will be used
-m, --module <MODULE> LKM module path to be replaced. If not specified, the built-in module will be used
-i, --init <INIT> init to be replaced
-u, --ota Will use another slot if the boot image is not specified
-f, --flash Flash it to boot partition after patch
-o, --out <OUT> Output path. If not specified, the current directory will be used
--magiskboot <MAGISKBOOT> magiskboot path. If not specified, the built-in version will be used
--kmi <KMI> KMI version. If specified, the indicated KMI will be used
-h, --help Print helpA few options that need to be explained:
- The
--magiskbootoption can specify the path of magiskboot. If not specified, ksud will look for it in the environment variables. If you don’t know how to get magiskboot, you can check here. - The
--kmioption can specify theKMIversion. If the kernel name of your device doesn't follow the KMI specification, you can specify it using this option.
The most common usage is:
ksud boot-patch -b <boot.img> --kmi android13-5.10LKM mode installation
There are several installation methods for LKM mode, each suitable for a different scenario, so please choose accordingly:
- Install with fastboot using the boot.img provided by KernelSU.
- Install with a kernel flash app, such as Kernel Flasher.
- Repair the boot.img manually and install it.
- Install with custom Recovery (e.g., TWRP).
Cài đặt với Recovery tùy chỉnh
Điều kiện chắc chắn: Thiết bị của bạn phải có Recovery tùy chỉnh, chẳng hạn như TWRP; nếu không hoặc chỉ có Recovery chính thức, hãy sử dụng phương pháp khác.
Các bước:
- Từ Release page của KernelSU, tải xuống gói zip bắt đầu bằng AnyKernel3 phù hợp với phiên bản điện thoại của bạn; ví dụ: phiên bản kernel của điện thoại là
android12-5.10. 66, thì bạn nên tải xuống tệpAnyKernel3-android12-5.10.66_yyyy-MM.zip(trong đóyyyylà năm vàMMlà tháng). - Khởi động lại điện thoại vào TWRP.
- Sử dụng adb để đặt AnyKernel3-*.zip vào điện thoại /sdcard và chọn cài đặt nó trong GUI TWRP; hoặc bạn có thể trực tiếp
adb sideload AnyKernel-*.zipđể cài đặt.
PS. Phương pháp này phù hợp với mọi cài đặt (không giới hạn cài đặt ban đầu hoặc các nâng cấp tiếp theo), miễn là bạn sử dụng TWRP.
Cài đặt bằng Kernel Flasher
Điều kiện chắc chắn: Thiết bị của bạn phải được root. Ví dụ: bạn đã cài đặt Magisk để root hoặc bạn đã cài đặt phiên bản KernelSU cũ và cần nâng cấp lên phiên bản KernelSU khác; nếu thiết bị của bạn chưa được root, vui lòng thử các phương pháp khác.
Các bước:
- Tải xuống zip AnyKernel3; hãy tham khảo phần Cài đặt bằng Custom Recovery để biết hướng dẫn tải xuống.
- Mở Ứng dụng Kernel Flash và sử dụng zip AnyKernel3 được cung cấp để flash.
Nếu trước đây bạn chưa từng sử dụng Ứng dụng Kernel flash thì sau đây là những ứng dụng phổ biến hơn.
PS. Phương pháp này thuận tiện hơn khi nâng cấp KernelSU và có thể thực hiện mà không cần máy tính (sao lưu trước!). .
Các bước:
Cài đặt bằng boot.img do KernelSU cung cấp
Phương pháp này không yêu cầu bạn phải có TWRP, cũng như không yêu cầu điện thoại của bạn phải có quyền root; nó phù hợp cho lần cài đặt KernelSU đầu tiên của bạn.
Tìm boot.img thích hợp
KernelSU cung cấp boot.img chung cho các thiết bị GKI và bạn nên chuyển boot.img vào phân vùng boot của thiết bị.
Bạn có thể tải xuống boot.img từ GitHub Release, xin lưu ý rằng bạn nên sử dụng đúng phiên bản boot.img. Ví dụ: nếu thiết bị của bạn hiển thị kernel android12-5.10.101 , bạn cần tải xuống android-5.10.101_yyyy-MM.boot-<format>.img. (Giữ KMI nhất quán!)
Trong đó <format> đề cập đến định dạng nén kernel của boot.img chính thức của bạn, vui lòng kiểm tra định dạng nén kernel của boot.img ban đầu của bạn, bạn nên sử dụng đúng định dạng, ví dụ: lz4, gz; nếu bạn sử dụng định dạng nén không chính xác, bạn có thể gặp phải bootloop.
INFO
- Bạn có thể sử dụng magiskboot để lấy định dạng nén của boot ban đầu; Tất nhiên, bạn cũng có thể hỏi những người khác, có kinh nghiệm hơn có cùng kiểu máy với thiết bị của bạn. Ngoài ra, định dạng nén của kernel thường không thay đổi nên nếu bạn khởi động thành công với một định dạng nén nào đó thì bạn có thể thử định dạng đó sau.
- Các thiết bị Xiaomi thường sử dụng
gzhoặc uncompressed (không nén). - Đối với thiết bị Pixel, hãy làm theo hướng dẫn bên dưới.
flash boot.img vào thiết bị
Sử dụng adb để kết nối thiết bị của bạn, sau đó thực thi adb restart bootloader để vào chế độ fastboot, sau đó sử dụng lệnh này để flash KernelSU:
fastboot flash boot boot.imgINFO
Nếu thiết bị của bạn hỗ trợ fastboot boot, trước tiên bạn có thể sử dụng fastboot boot boot.img để thử sử dụng boot.img để khởi động hệ thống trước. Nếu có điều gì bất ngờ xảy ra, hãy khởi động lại để boot.
khởi động lại
Sau khi flash xong bạn nên khởi động lại máy:
fastboot rebootVá boot.img theo cách thủ công
Đối với một số thiết bị, định dạng boot.img không quá phổ biến, chẳng hạn như không lz4, gz và không nén; điển hình nhất là Pixel, định dạng boot.img của nó là nén lz4_legacy, ramdisk có thể là gz cũng có thể là nén lz4_legacy; tại thời điểm này, nếu bạn trực tiếp flash boot.img do KernelSU cung cấp, điện thoại có thể không khởi động được; Tại thời điểm này, bạn có thể vá boot.img theo cách thủ công để dùng được.
Nhìn chung có hai phương pháp vá:
Trong số đó, Android-Image-Kitchen phù hợp để hoạt động trên PC và magiskboot cần sự kết nối của điện thoại di động.
Chuẩn bị
- Lấy stock boot.img của điện thoại; bạn có thể lấy nó từ nhà sản xuất thiết bị của mình, bạn có thể cần payload-dumper-go
- Tải xuống tệp zip AnyKernel3 do KernelSU cung cấp phù hợp với phiên bản KMI của thiết bị của bạn (bạn có thể tham khảo Cài đặt với Khôi phục tùy chỉnh).
- Giải nén gói AnyKernel3 và lấy tệp
Image, đây là tệp kernel của KernelSU.
Sử dụng Android-Image-Kitchen
- Tải Android-Image-Kitchen về máy tính.
- Đặt stock boot.img vào thư mục gốc của Android-Image-Kitchen.
- Thực thi
./unpackimg.sh boot.imgtại thư mục gốc của Android-Image-Kitchen, lệnh này sẽ giải nén boot.img và bạn sẽ nhận được một số tệp. - Thay thế
boot.img-kerneltrong thư mụcsplit_imgbằngImagebạn đã trích xuất từ AnyKernel3 (lưu ý đổi tên thành boot.img-kernel). - Thực thi
./repackimg.shtại thư mục gốc của 在 Android-Image-Kitchen; Và bạn sẽ nhận được một file có tênimage-new.img; Flash boot.img này bằng fastboot(Tham khảo phần trước).
Sử dụng magiskboot
- Tải xuống Magisk mới nhất từ Trang phát hành
- Đổi tên
Magisk-*(version).apkthànhMagisk-*.zipvà giải nén nó. - Đẩy
Magisk-*/lib/arm64-v8a/libmagiskboot.sovào thiết bị của bạn bằng adb:adb push Magisk-*/lib/arm64-v8a/libmagiskboot.so /data/local/tmp /magiskboot - Đẩy stock boot.img và Image trong AnyKernel3 vào thiết bị của bạn.
- Nhập thư mục adb shell và cd
/data/local/tmp/, sau đóchmod +x magiskboot - Nhập adb shell và cd
/data/local/tmp/, thực thi./magiskboot unpack boot.imgđể giải nénboot.img, bạn sẽ nhận được filekernel, đây là kernel gốc của bạn. - Thay thế
kernelbằngImage:mv -f Image kernel - Thực thi
./magiskboot repack boot.imgđể đóng gói lại boot img và bạn sẽ nhận được một tệpnew-boot.img, flash tệp này vào thiết bị bằng fastboot.
Các phương pháp khác
Trên thực tế, tất cả các phương pháp cài đặt này chỉ có một ý tưởng chính, đó là thay thế kernel gốc bằng kernel do KernelSU cung cấp; chỉ cần đạt được điều này là có thể cài đặt được; ví dụ, sau đây là các phương pháp có thể khác.
- Trước tiên hãy cài đặt Magisk, nhận quyền root thông qua Magisk, sau đó sử dụng flasher kernel để flash trong zip AnyKernel từ KernelSU.
- Sử dụng một số bộ công cụ flash trên PC để flash trong kernel do KernelSU cung cấp.
Tuy nhiên, nếu nó không hoạt động, vui lòng thử phương pháp magiskboot.
Sau khi cài đặt: Hỗ trợ Module
METAMODULE CHO SỬA ĐỔI TỆP HỆ THỐNG
Nếu bạn muốn sử dụng các module sửa đổi tệp /system, bạn cần cài đặt metamodule sau khi cài đặt KernelSU. Các module chỉ sử dụng scripts, sepolicy hoặc system.prop hoạt động mà không cần metamodule.
Để hỗ trợ sửa đổi /system, vui lòng xem Hướng dẫn Metamodule để:
- Hiểu metamodule là gì và tại sao cần chúng
- Cài đặt metamodule
meta-overlayfschính thức - Tìm hiểu về các tùy chọn metamodule khác