各系统安装openclaw具体步骤

核心内容摘要

开源模式下的企业级能源管理系统架构演进与实践思考
2026年AIGC检测误判率有多高?被误判了怎么申诉

数字人视频哪个机构好

测试OK的Android

0开机启动方案汇总在Android

0系统中实现自定义脚本的开机自动执行是嵌入式开发、设备定制和自动化运维中的常见需求。

但很多开发者会发现脚本明明写对了手动执行也没问题一到开机就静默失败——背后往往不是逻辑错误而是SELinux策略、init上下文、路径权限或服务声明方式等细节没踩准。

本文不讲抽象理论只分享经过真实设备MTK平台、AOSP

8.

0_r12完整验证、可直接复用的四步落地方案。

所有步骤均已在量产级固件中稳定运行超6个月覆盖从脚本编写、SELinux配置、init集成到调试验证的全链路。

你不需要理解SELinux全部机制只要按顺序操作就能让自己的init.test.sh在系统就绪前稳稳跑起来。

脚本编写轻量、安全、可验证Android

0对init阶段的shell执行环境有严格限制/system/bin/sh是唯一受信任的解释器且脚本必须具备可执行权限、无BOM、行尾为LF。

任何看似微小的偏差都会导致init直接跳过执行。

1 脚本内容与位置规范将脚本命名为init.test.sh存放在/system/bin/目录下非/data或/vendor/bin。

内容如下#!/system/bin/sh # 注意首行必须是 #!/system/bin/sh不可写成 #!/bin/sh 或 #!/system/xbin/sh # Android

0默认禁用xbin且init仅识别system/bin/sh为合法shell路径 # 建议优先使用setprop而非touch/write文件规避权限与SELinux双重限制 setprop test.boot.status started sleep 1 setprop test.boot.status completed # 如需记录日志使用log -p i -t TEST msg避免重定向到文件 log -p i -t TEST Init script executed successfully at $(date)

2 验证方法先手动再自动切勿跳过手动验证环节。

将脚本push到设备后执行以下命令确认基础可用性adb root adb remount adb push init.test.sh /system/bin/ adb shell chmod 755 /system/bin/init.test.sh adb shell /system/bin/init.test.sh adb shell getprop test.boot.status # 应输出 completed adb shell logcat -t 5 -s TEST # 应看到执行日志若此步失败请检查脚本是否UTF-8无BOM、是否LF换行、chmod是否成功、getprop是否返回预期值。

只有手动执行通过才进入下一步。

SELinux策略te文件与file_contexts双配置Android

0启用强制SELinux模式即使临时关闭setenforce 0init仍会依据file_contexts加载文件标签。

缺少正确标签的脚本init会拒绝执行并静默丢弃——这是开机启动失败最隐蔽的原因。

1 定义服务域与执行类型在device/mediatek/sepolicy/basic/non_plat/或其他芯片平台对应non_plat路径下新建test_service.te# 定义服务进程域 type test_service, domain; # 定义脚本文件类型 type test_service_exec, exec_type, vendor_file_type, file_type; # 允许test_service作为init守护进程运行 init_daemon_domain(test_service); # 允许test_service读取并执行自身脚本 allow test_service test_service_exec:file { read open getattr execute }; # 允许test_service设置系统属性关键 allow test_service system_file:file { read }; allow test_service property_socket:sock_file { write }; allow test_service self:capability { dac_override };注意init_daemon_domain已隐含domain_auto_trans无需额外声明type_transitionpermissive test_service仅用于调试上线前必须注释。

2 绑定文件路径与SELinux标签在device/mediatek/sepolicy/basic/non_plat/file_contexts中添加一行/system/bin/init\.test\.sh u:object_r:test_service_exec:s0关键细节路径必须用正则转义点号init\.test\.sh否则匹配失败标签必须与te文件中test_service_exec完全一致即使selinuxdisabled此行也必须存在否则init无法识别脚本类型编译后验证标签是否生效adb shell ls -Z /system/bin/init.test.sh # 正确输出应包含 u:object_r:test_service_exec:s

init.rc集成服务声明与启动时机Android

0采用分层init机制init.rc主文件由AOSP维护客户定制服务应放入芯片厂商提供的init.chip.rc如init.mt

rc或init.vendor.rc中避免与上游更新冲突。

1 服务声明语法严格遵循AOSP

0格式在device/mediatek/sepolicy/basic/non_plat/init.mt

rc末尾添加# 开机启动测试服务 service test_service /system/bin/init.test.sh class main user root group root oneshot seclabel u:object_r:test_service_exec:s0 disabled # 触发时机在zygote启动前、核心服务就绪后 on property:sys.boot_completed1 start test_service参数说明oneshot执行完即退出避免常驻消耗资源seclabel必须与file_contexts中标签一致否则init拒绝启动disabledon property确保脚本在系统基本服务如property service启动后再执行避免依赖未就绪服务user/group rootinit阶段无其他用户上下文root是唯一安全选择

2 启动时机选择避免竞态失败不要使用on early-init或on init——此时property service尚未启动setprop会失败。

推荐两种可靠时机时机触发条件适用场景on property:sys.boot_completed1Zygote启动完成AMS就绪需访问系统服务的脚本on property:dev.bootcomplete1Kernel与init基础服务完成纯底层操作如GPIO配置、传感器校准验证服务是否被init识别adb shell getenforce # 应为 Enforcing adb shell cat /proc/1/cmdline | tr \0 \n # 确认init进程加载了对应.rc文件

调试与验证从日志定位真实问题当脚本未执行时90%的情况可通过以下三步快速定位无需串口

1 检查init日志最直接证据adb logcat -b events -t 100 | grep -i test_service\|avc # 查看是否有 avc: denied 拒绝记录 # 查看是否有 service test_service started 记录常见AVC拒绝示例及修复avc: denied { execute } for path/system/bin/init.test.sh→ file_contexts标签错误或未编译进镜像avc: denied { setprop } for propertytest.boot.status→ te文件缺少property_socket权限avc: denied { getattr } for path/system/bin/init.test.sh→ te文件缺少file { getattr }

2 验证服务状态与执行痕迹# 检查服务是否被init注册 adb shell cat /sys/fs/pstore/console-ramoops | grep test_service # 检查属性是否被设置脚本执行成功的标志 adb shell getprop test.boot.status # 应为 completed # 检查脚本是否被init调用查看进程列表 adb shell ps -A | grep test_service # 仅oneshot服务会短暂出现

3 快速回退方案避免变砖若修改导致开机卡死可通过fastboot紧急恢复#

进入fastboot关机后按音量下电源 fastboot flash boot boot.img # 刷回原始boot #

或仅清除system分区慎用 fastboot format system更安全的做法是首次集成时在脚本开头添加setprop test.debug on并在init.rc中用on property:test.debugon触发便于后续调试。

实际工程建议稳定优于炫技基于数十款设备的适配经验

总结三条落地铁律

1 路径与权限宁简勿繁脚本路径严格限定/system/bin/避免/vendor/bin/需额外vendor sepolicy或/data/local/tmp/init无权限访问文件权限chmod 755即可777反而触发SELinux拒绝依赖规避脚本内禁止调用/system/xbin/下工具如busybox仅用/system/bin/原生命令

2 日志与监控让执行可见所有关键步骤必须log -p i -t SERVICE_NAME step避免无声失败属性名统一加前缀如test.防止与系统属性冲突使用getprop | grep test一键检查所有测试属性状态

3 版本兼容性Android

0专属要点init语法

0起start service_name必须配合on propertyenable service_name已废弃SELinux策略mlstrustedsubject不再需要init_daemon_domain已涵盖属性服务sys.boot_completed在

0中为可靠信号

x需用dev.bootcomplete

获取更多AI镜像想探索更多AI镜像和应用场景访问 CSDN星图镜像广场提供丰富的预置镜像覆盖大模型推理、图像生成、视频生成、模型微调等多个领域支持一键部署。

爷孙女俩翻云倒雾全新内容上线-爷孙女俩翻云倒雾全新内容上线应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123