website/docs/zh_TW/guide/module-config.md
KernelSU 提供了一個內建的配置系統,允許模組儲存持久化或暫時的鍵值設定。配置以二進位格式儲存在 /data/adb/ksu/module_configs/<module_id>/,具有以下特性:
persist.config):重新開機後保留,直到明確刪除或解除安裝模組tmp.config):在每次啟動時的 post-fs-data 階段自動清除讀取配置時,對於同一個鍵,暫時值優先於持久值。
所有模組腳本(post-fs-data.sh、service.sh、boot-completed.sh 等)執行時都會設定 KSU_MODULE 環境變數為模組 ID。您可以使用 ksud module config 命令來管理模組的配置:
# 獲取配置值
value=$(ksud module config get my_setting)
# 設定持久配置值
ksud module config set my_setting "some value"
# 設定暫時配置值(重新開機後清除)
ksud module config set --temp runtime_state "active"
# 列出所有配置項(合併持久和暫時配置)
ksud module config list
# 刪除配置項
ksud module config delete my_setting
# 刪除暫時配置項
ksud module config delete --temp runtime_state
# 清除所有持久配置
ksud module config clear
# 清除所有暫時配置
ksud module config clear --temp
# 從 stdin 設定值(適用於多行或複雜資料)
ksud module config set my_key <<EOF
多行
文字值
EOF
# 或從命令管道輸入
echo "value" | ksud module config set my_key
# 明確使用 stdin 標誌
cat file.json | ksud module config set json_data --stdin
配置系統強制執行以下限制:
^[a-zA-Z][a-zA-Z0-9._-]+$(與模組 ID 相同)
.)、底線(_)或連字號(-)0x4b53554d("KSUM")和版本驗證配置系統適用於:
::: tip 最佳實踐
ksud module config list 命令偵錯配置問題
:::模組配置系統提供了用於進階用例的特殊配置鍵:
您可以透過設定 override.description 配置鍵來動態覆蓋 module.prop 中的 description 欄位:
# 覆蓋模組描述
ksud module config set override.description "在管理器中顯示的自訂描述"
當取得模組列表時,如果存在 override.description 配置,它將取代 module.prop 中的原始描述。這對於以下場景很有用:
模組可以使用 manage.<feature> 配置模式宣告它們管理的 KernelSU 功能。支援的功能對應於 KernelSU 內部的 FeatureId 列舉:
支援的功能:
su_compat - SU 相容模式kernel_umount - 核心自動卸載# 宣告此模組管理 SU 相容性並將其啟用
ksud module config set manage.su_compat true
# 宣告此模組管理核心卸載並將其停用
ksud module config set manage.kernel_umount false
# 移除功能管理(模組不再控制此功能)
ksud module config delete manage.su_compat
工作原理:
manage.<feature> 鍵的存在表示模組正在管理該功能true/1 代表啟用,false/0(或任何其他值)代表停用管理的功能透過模組列表 API 以 managedFeatures 欄位(逗號分隔的字串)公開。這允許:
::: warning 僅支援預定義功能
僅使用上面列出的預定義功能名稱(su_compat、kernel_umount)。這些對應於實際的 KernelSU 內部功能。使用其他功能名稱不會導致錯誤,但沒有任何功能作用。
:::