android 初始化 脚本,Android init language与init.rc初始化脚本
微信公众号:杨源鑫
如果你觉得文章对你有帮助,欢迎在评论区交流讨论
参考: android源码目录里的system/core/init/readme.txt.
Android系统里以*.rc为扩展名为系统初始化脚本,脚本里就是使用安卓初始化语言.
语句都是一行为一条语句,没有符号分隔. 语句里的每个词用空格隔开.
如: service ueventd /sbin/ueventd
备注语句以符号”#”作为注释.
语言基本上分为4个块: Actions Commands Services 和 Options.
每个Actions和Services关键词开始的语句作为一个新的区块.
Commands和Options就是属于就近的Actions或Services块.
如:
Actions的形式:
Services的形式:
[ ]*
rc文件里实例:
system/bin/logd
socket logd stream 0666 logd logd
socket logdr seqpacket 0666 logd logd
socket logdw dgram 0222 logd logd
system
system-background/tasks
s0
# Actions
# on
# Set init and its forked children's oom_adj.
write /proc/1/oom_score_adj -1000
# Set the security context of /adb_keys if present.
每个rc文件里又可以包含其它rc文件:
import /init.environ.rc
import /init.usb.rc
import /init.${ro.hardware}.rc
import /init.usb.configfs.rc
import /init.${ro.zygote}.rc
import /init.trace.rc
Actions里常用的trigger有:
on early-init
on init
on late-init
on post-fs
on boot
on property:sys.init_log_level=* //在设置属性值时触发
on charger
on property:sys.powerctl=*
常用的Commands有://参考system/core/init/keywords.h
Start bootcharting if configured (see below).
is included in the default init.rc.
mode>
Change file access permissions.
Change file owner and group.
Start all services of the specified class if they are
not already running.
Stop and disable all services of the specified class if they are
Stop all services of the specified class if they are
without disabling them. They can be restarted
using class_start.
to write, but useful for binary/large
of data.
name>
Set the domain name.
enable into an enabled one as if the service did not
If the service is supposed to be running, it will be started now.
when the bootloader sets a variable that indicates a specific
when needed. E.g.
on property:ro.boot.myfancyhardware=1
enable my_fancy_service_for_my_fancy_hardware
[ [ ]* ] ] -- [ ]*
and execute command with the given arguments. The command starts
after "--" so that an optional security context, user, and supplementary
groups can be provided. No other commands will be run until this one
can be a - to denote default.
export
Set the environment variable equal to in the
global environment (which will be inherited by all processes
after this command is executed)
name>
Set the host name.
interface>
interface online.
import Parse an init config file, extending the current configuration.
path>
Install the module at
from /system, /vendor, et cetera.
is included in the default init.rc.
when /data has been decrypted.
is included in the default init.rc.
level>
Sets the kernel log level to level. Properties are expanded within .
path> [mode] [owner] [group]
Create a directory at , optionally with the given mode, owner, and
If not provided, the directory is created with permissions 755 and
by the root user and root group. If provided, the mode, owner and group
updated if the directory exists already.
on the given fs_mgr-format fstab.
mount [ ]* []
to mount the named device at the directory may be of the form mtd@name to specify a mtd block
by name.
s include "ro", "rw", "remount", "noatime", ...
include "barrier=1", "noauto_da_alloc", "discard", ... as
string, eg: barrier=1,noauto_da_alloc
to respond to changes to the
"sys.powerctl" system property, used to implement rebooting.
Like stop, but doesn't disable the service.
[ ]*
to the security context specified
[ ]*
to the
to . Properties are expanded
.
with the value .verified properties used by adb remountt set them directly itself.
wait [ ]
for the existence of the given file and return when found,
or the timeout has been reached. If timeout is not specified it
defaults to five seconds.
path>
Open the file at and write a string to it with write(2).
If the file does not exist, it will be created. If it does exist,
are expanded within .
Services里常用的options有:
is a device-critical service. If it exits more than four times in
into recovery mode.
not automatically start with its class.
by name.
Set the environment variable to in the launched process.
[ [ [ ] ] ]
and pass
to the launched process. must be "dgram", "stream" or "seqpacket".
and group default to 0.
'seclabel' is the SELinux security context for the socket.
to the service security context, as specified by seclabel or
on the service executable file security context.
to username before exec'ing this service.
to root. (??? probably should default to nobody)
if your process requires linux capabilities then you cannot use
in-process while
and then drop to your desired uid.
group [ ]*
to groupname before exec'ing this service. Additional
to set the
of the process (via setgroups()).
to root. (??? probably should default to nobody)
to 'seclabel' before exec'ing this service.
for use by services run from the rootfs, e.g. ueventd, adbd.
on the system partition can instead use policy-defined transitions
on their file security context.
If not specified and no transition is defined in policy, defaults to the init context.
Do not restart the service when it exits.
class class name for the service. All services in a
class may be started or stopped together. A service
is in the class "default" if one is not specified via the
class option.
when service restarts.
's pid to the given files when it forks. Meant for
实现直接使用root用户进入终端, 修改android/out/target/product/tulip-p1/root/init.rc :
console /system/bin/sh
class core
console
# user shell
# group shell log
# seclabel u:r:shell:s0
//备注使用shell用户进入终端. 会默认使用root用户操作
实现系统进入后执行自定义的脚本 :修改android/out/target/product/tulip-p1/root/init.rc , 增加内容:
service start_mytest /system/bin/mytest.sh
on property:sys.boot_completed=1
在android/out/target/product/tulip-p1/system/bin目录下,增加mytest.sh, 内容:
#!/system/bin/sh
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
