1# Copyright (C) 2012 The Android Open Source Project2# Copyright (C) 3# Copyright (C) 4#5# IMPORTANT: Do not create world writable files or directories.6# This is a common source of Android security bugs.7#89import /init.${ro.hardware}.rc //import <filename> : 包含其他的*.rc,类似include
10import /init.usb.rc
11import /init.trace.rc
1213on early-init //最先做 其中的action, 开始early-init 段
14# Set init and its forked children's oom_adj.15write /proc/1/oom_adj -16 //直接写入procfs
1617 start ueventd //启动一个服务,注意ueventd 必须是一个service,在359行有定义
1819# create mountpoints20mkdir /mnt 0775 root system //创建目录,具体用法与shell中的mkdir命令一样
2122on init //开始init段,其中的action在 early-init,property-init后执行
2324sysclktz 0 //设置系统时钟,如果是0表示用GMT的时钟ticks
2526loglevel 3 //log的输出级别[0,7],控制的kernel的log输出
2728# setup the global environment 29 export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin //export,shell命令,设置全局环境变量
30 export LD_LIBRARY_PATH /vendor/lib:/system/lib31 export ANDROID_BOOTLOGO 132 export ANDROID_ROOT /system33 export ANDROID_ASSETS /system/app
34 export ANDROID_DATA /data
35 export ASEC_MOUNTPOINT /mnt/asec
36 export LOOP_MOUNTPOINT /mnt/obb
37 export BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework_ext.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar
3839# Backward compatibility40symlink /system/etc /etc //创建一个指向/system/etc的软连接/etc, 也就是/etc目录实际上指向/system/etc
41symlink /sys/kernel/debug /d
4243# Right now vendor lives on the same filesystem as system,44# but someday that may change.45symlink /system/vendor /vendor
4647# Create cgroup mount point for cpu accounting48mkdir /acct
49 mount cgroup none /acct cpuacct //mount <type> <device> <dir> [mountoption] 把device(none)挂载到type为cgroup 的文件系统/acct下
//其中<device>可以是以mtd@name形式指定的一个mtd块设备. mountoption可以是mode=0755,gid=100050mkdir /acct/uid
5152mkdir /system53mkdir /data 0771systemsystem54mkdir /cache 0770system cache
55mkdir /config 0500 root root
5657# Directory for putting things only root should see.58mkdir /mnt/secure 0700 root root
5960# Directory for staging bindmounts61mkdir /mnt/secure/staging 0700 root root
6263# Directory-target for where the secure container64# imagefile directory will be bind-mounted65mkdir /mnt/secure/asec 0700 root root
6667# Secure container public mount points.68mkdir /mnt/asec 0700 root system69 mount tmpfs tmpfs /mnt/asec mode=0755,gid=10007071# Filesystem image public mount points.72mkdir /mnt/obb 0700 root system73 mount tmpfs tmpfs /mnt/obb mode=0755,gid=10007475write /proc/sys/kernel/panic_on_oops 176write /proc/sys/kernel/hung_task_timeout_secs 077write /proc/cpu/alignment 478write /proc/sys/kernel/sched_latency_ns 1000000079write /proc/sys/kernel/sched_wakeup_granularity_ns 200000080write /proc/sys/kernel/sched_compat_yield 181write /proc/sys/kernel/sched_child_runs_first 082write /proc/sys/kernel/randomize_va_space 283write /proc/sys/kernel/kptr_restrict 284write /proc/sys/kernel/dmesg_restrict 185write /proc/sys/vm/mmap_min_addr 3276886write /proc/sys/kernel/sched_rt_runtime_us 95000087write /proc/sys/kernel/sched_rt_period_us 10000008889# Create cgroup mount points for process groups90mkdir /dev/cpuctl
91 mount cgroup none /dev/cpuctl cpu
92chownsystemsystem /dev/cpuctl //改变目录(/dev/cpuctl)的使用群体为system93chownsystemsystem /dev/cpuctl/tasks
94chmod0660 /dev/cpuctl/tasks //改变文件(/dev/cpuctl/tasks)的使用权限为066095write /dev/cpuctl/cpu.shares 102496write /dev/cpuctl/cpu.rt_runtime_us 95000097write /dev/cpuctl/cpu.rt_period_us 10000009899mkdir /dev/cpuctl/apps
100chownsystemsystem /dev/cpuctl/apps/tasks
101chmod0666 /dev/cpuctl/apps/tasks
102write /dev/cpuctl/apps/cpu.shares 1024103write /dev/cpuctl/apps/cpu.rt_runtime_us 800000104write /dev/cpuctl/apps/cpu.rt_period_us 1000000105106mkdir /dev/cpuctl/apps/bg_non_interactive
107chownsystemsystem /dev/cpuctl/apps/bg_non_interactive/tasks
108chmod0666 /dev/cpuctl/apps/bg_non_interactive/tasks
109# 5.0 %110write /dev/cpuctl/apps/bg_non_interactive/cpu.shares 52111write /dev/cpuctl/apps/bg_non_interactive/cpu.rt_runtime_us 700000112write /dev/cpuctl/apps/bg_non_interactive/cpu.rt_period_us 1000000113114# Allow everybody to read the xt_qtaguid resource tracking misc dev.115# This is needed by any process that uses socket tagging.116chmod0644 /dev/xt_qtaguid
117118on fs //??????
119# mount mtd partitions120# Mount /system rw first to give the filesystem a chance to save a checkpoint121 mount yaffs2 mtd@system /system122 mount yaffs2 mtd@system /system ro remount
123 mount yaffs2 mtd@userdata /data nosuid nodev
124 mount yaffs2 mtd@cache /cache nosuid nodev
125126on post-fs
127# once everything is setup, no need to modify /128 mount rootfs rootfs / ro remount
129130# We chown/chmod /cache again so because mount is run as root + defaults131chownsystem cache /cache
132chmod0770 /cache
133134# This may have been created by the recovery system with odd permissions135mkdir /cache/recovery
136chownsystem cache /cache/recovery
137chmod0770 /cache/recovery
138139#change permissions on vmallocinfo so we can grab it from bugreports140chown root log /proc/vmallocinfo
141chmod0440 /proc/vmallocinfo
142143#change permissions on kmsg & sysrq-trigger so bugreports can grab kthread stacks144chown root system /proc/kmsg
145chmod0440 /proc/kmsg
146chown root system /proc/sysrq-trigger
147chmod0220 /proc/sysrq-trigger
148149# create the lost+found directories, so as to enforce our permissions150# Moved to init.target.rc in the Sony product git151# mkdir /cache/lost+found 0770 root root152153on post-fs-data
154# We chown/chmod /data again so because mount is run as root + defaults155chownsystemsystem /data
156chmod0771 /data
157158# Create dump dir and collect dumps.159# Do this before we mount cache so eventually we can use cache for160# storing dumps on platforms which do not have a dedicated dump partition.161mkdir /data/dontpanic 0750 root log162163# Collect apanic data, free resources and re-arm trigger164 copy /proc/apanic_console /data/dontpanic/apanic_console
165chown root log /data/dontpanic/apanic_console
166chmod0640 /data/dontpanic/apanic_console
167168 copy /proc/apanic_threads /data/dontpanic/apanic_threads
169chown root log /data/dontpanic/apanic_threads
170chmod0640 /data/dontpanic/apanic_threads
171172write /proc/apanic_console 1173174# create basic filesystem structure175mkdir /data/misc 01771system misc
176mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
177mkdir /data/misc/bluetooth 0770systemsystem178mkdir /data/misc/keystore 0700 keystore keystore
179mkdir /data/misc/keychain 0771systemsystem180mkdir /data/misc/vpn 0770system vpn
181mkdir /data/misc/systemkeys 0700systemsystem182# give system access to wpa_supplicant.conf for backup and restore183mkdir /data/misc/wifi 0770 wifi wifi
184chmod0660 /data/misc/wifi/wpa_supplicant.conf
185mkdir /data/local0751 root root
186chmod2770 /data/radio
187188# For security reasons, /data/local/tmp should always be empty.189# Do not place files or directories in /data/local/tmp190mkdir /data/local/tmp 0771 shell shell
191mkdir /data/data 0771systemsystem192mkdir /data/app-private 0771systemsystem193mkdir /data/app-asec 0700 root root
194mkdir /data/app 0771systemsystem195mkdir /data/property 0700 root root
196mkdir /data/ssh 0750 root shell
197mkdir /data/ssh/empty 0700 root root
198199# create dalvik-cache, so as to enforce our permissions200mkdir /data/dalvik-cache 0771systemsystem201202# create resource-cache and double-check the perms203mkdir /data/resource-cache 0771systemsystem204chownsystemsystem /data/resource-cache
205chmod0771 /data/resource-cache
206207# create the lost+found directories, so as to enforce our permissions208# Moved to init.target.rc in the Sony product git209# mkdir /data/lost+found 0770 root root210211# create directory for DRM plug-ins - give drm the read/write access to212# the following directory.213mkdir /data/drm 0770 drm drm
214215# If there is no fs-post-data action in the init.<device>.rc file, you216# must uncomment this line, otherwise encrypted filesystems217# won't work.218# Set indication (checked by vold) that we have finished this action219#setprop vold.post_fs_data_done 1220221on boot //开始boot段,其中的action在 early-init,property-init,init后执行
222# basic network init223 ifup lo //启动网路接口 lo, 但lo是啥接口?
224 hostname localhost //设置手机主机名为localhost
225 domainname localdomain //设置域名localdomain
226227# set RLIMIT_NICE to allow priorities from 19 to -20228 setrlimit 134040229230# Memory management. Basic kernel parameters, and allow the high231# level system server to be able to adjust the kernel OOM driver232# parameters to match how it is managing things.233write /proc/sys/vm/overcommit_memory 1234write /proc/sys/vm/min_free_order_shift 4235chown root system /sys/module/lowmemorykiller/parameters/adj
236chmod0664 /sys/module/lowmemorykiller/parameters/adj
237chown root system /sys/module/lowmemorykiller/parameters/minfree
238chmod0664 /sys/module/lowmemorykiller/parameters/minfree
239240# Tweak background writeout241write /proc/sys/vm/dirty_expire_centisecs 200242write /proc/sys/vm/dirty_background_ratio 5243244# Permissions for System Server and daemons.245chown radio system /sys/android_power/state246chown radio system /sys/android_power/request_state
247chown radio system /sys/android_power/acquire_full_wake_lock
248chown radio system /sys/android_power/acquire_partial_wake_lock
249chown radio system /sys/android_power/release_wake_lock
250chownsystemsystem /sys/power/state251chownsystemsystem /sys/power/autosleep
252chownsystemsystem /sys/power/wakeup_count
253chown radio system /sys/power/wake_lock
254chown radio system /sys/power/wake_unlock
255chmod0660 /sys/power/state256chmod0660 /sys/power/wake_lock
257chmod0660 /sys/power/wake_unlock
258259chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/timer_rate
260chmod0660 /sys/devices/system/cpu/cpufreq/interactive/timer_rate
261chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
262chmod0660 /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
263chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
264chmod0660 /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
265chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
266chmod0660 /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
267chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
268chmod0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
269chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/boost
270chmod0660 /sys/devices/system/cpu/cpufreq/interactive/boost
271chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/boostpulse
272chownsystemsystem /sys/devices/system/cpu/cpufreq/interactive/input_boost
273chmod0660 /sys/devices/system/cpu/cpufreq/interactive/input_boost
274275# Assume SMP uses shared cpufreq policy for all CPUs276chownsystemsystem /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
277chmod0660 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
278279chownsystemsystem /sys/class/timed_output/vibrator/enable
280chownsystemsystem /sys/class/leds/keyboard-backlight/brightness
281chownsystemsystem /sys/class/leds/lcd-backlight/brightness
282chownsystemsystem /sys/class/leds/button-backlight/brightness
283chownsystemsystem /sys/class/leds/jogball-backlight/brightness
284chownsystemsystem /sys/class/leds/red/brightness
285chownsystemsystem /sys/class/leds/green/brightness
286chownsystemsystem /sys/class/leds/blue/brightness
287chownsystemsystem /sys/class/leds/red/device/grpfreq
288chownsystemsystem /sys/class/leds/red/device/grppwm
289chownsystemsystem /sys/class/leds/red/device/blink
290chownsystemsystem /sys/class/leds/red/brightness
291chownsystemsystem /sys/class/leds/green/brightness
292chownsystemsystem /sys/class/leds/blue/brightness
293chownsystemsystem /sys/class/leds/red/device/grpfreq
294chownsystemsystem /sys/class/leds/red/device/grppwm
295chownsystemsystem /sys/class/leds/red/device/blink
296chownsystemsystem /sys/class/timed_output/vibrator/enable
297chownsystemsystem /sys/module/sco/parameters/disable_esco
298chownsystemsystem /sys/kernel/ipv4/tcp_wmem_min
299chownsystemsystem /sys/kernel/ipv4/tcp_wmem_def
300chownsystemsystem /sys/kernel/ipv4/tcp_wmem_max
301chownsystemsystem /sys/kernel/ipv4/tcp_rmem_min
302chownsystemsystem /sys/kernel/ipv4/tcp_rmem_def
303chownsystemsystem /sys/kernel/ipv4/tcp_rmem_max
304chown root radio /proc/cmdline
305306# Define TCP buffer sizes for various networks307# ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,308 setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208309 setprop net.tcp.buffersize.wifi 524288,1048576,2097152,262144,524288,1048576310 setprop net.tcp.buffersize.lte 524288,1048576,2097152,262144,524288,1048576311 setprop net.tcp.buffersize.umts 4094,87380,110208,4096,16384,110208312 setprop net.tcp.buffersize.hspa 4094,87380,1220608,4096,16384,1220608313 setprop net.tcp.buffersize.hsupa 4094,87380,1220608,4096,16384,1220608314 setprop net.tcp.buffersize.hsdpa 4094,87380,1220608,4096,16384,110208315 setprop net.tcp.buffersize.hspap 4094,87380,2097152,4096,16384,1220608316 setprop net.tcp.buffersize.edge 4093,26280,35040,4096,16384,35040317 setprop net.tcp.buffersize.gprs 4092,8760,11680,4096,8760,11680318 setprop net.tcp.buffersize.evdo_b 4094,87380,262144,4096,16384,262144319320# Assign TCP buffer thresholds to be ceiling value of technology maximums321# Increased technology maximums should be reflected here.322write /proc/sys/net/core/rmem_max 2097152323write /proc/sys/net/core/wmem_max 1220608324325# Set this property so surfaceflinger is not started by system_init326 setprop system_init.startsurfaceflinger 0327328 class_start core //如果所有的class类别为core 的服务没有运行,则马上启动它们
329 class_start main
330331on nonencrypted
332 class_start late_start
333334on charger
335 class_start charger
336337on property:vold.decrypt=trigger_reset_main
338 class_reset main
339340on property:vold.decrypt=trigger_load_persist_props
341 load_persist_props
342343on property:vold.decrypt=trigger_post_fs_data
344 trigger post-fs-data //触发一个事件post-fs-data, 该事件是用on post-fs-data定义的,位于后面
345346on property:vold.decrypt=trigger_restart_min_framework
347 class_start main
348349on property:vold.decrypt=trigger_restart_framework
350 class_start main
351 class_start late_start
352353on property:vold.decrypt=trigger_shutdown_framework
354 class_reset late_start
355 class_reset main
356357## Daemon processes to be run by init.358##359service ueventd /sbin/ueventd //表示service段,语法: service <服务名字> <服务对应的执行文件>; 声明服务名字为ueventd的服务,其具体执行路径
//为/sbin/ueventd
360 class core //表示属于class 类别为core 的服务,如果没有设置,则表示该服务的默认类别为default
361 critical //
362363service console /system/bin/sh
364 class core
365 console
366 disabled
367 user shell
368 group log369370on property:ro.debuggable=1 //如果用setprop命令设置属性 ro.debuggable变成1,则触发下面的start console
371 start console
372373# adbd is controlled via property triggers in init.<platform>.usb.rc374service adbd /sbin/adbd
375 class core
376 disabled //该服务不能通过启动一类服务来启动,比如 class_start core来启动,只能以单独的名字来启动 start adbd.
377378# adbd on at boot in emulator379on property:ro.kernel.qemu=1380 start adbd
381382service servicemanager /system/bin/servicemanager
383 class core
384 user system //在该服务启动前,把用户名切换到 system,默认是root
385 group system //在该服务启动前,把组名切换到 system.
386 critical //说明该服务是个对于设备很关键的服务,如果4分钟内退出大于4次,则系统将重启并进入recovery恢复模式
387 onrestart exec /system/bin/sync //当该服务重启时,执行后面的命令 exec
//exec创建和执行一个程序(/system/bin/sync),在程序完全执行完之前,init会被阻塞。所以极有可能引起init卡死
388 onrestart write /proc/sysrq-trigger c
389390service vold /system/bin/vold
391 class core
392socket vold stream 0660 root mount //语法:socket <name> <type> <perm> <user> <group>, 创建一个名字为vold<name>,类别为stream<type>
//访问权限为0660<perm> 用户为root,用户组为mount
393 ioprio be 2394395service netd /system/bin/netd
396 class main
397socket netd stream 0660 root system398socket dnsproxyd stream 0660 root inet
399socket mdns stream 0660 root system400401service debuggerd /system/bin/debuggerd
402 class main
403404service ril-daemon /system/bin/rild
405 class main
406socket rild stream 660 root radio
407socket rild-debug stream 660 radio system408 user root
409 group radio cache inet misc audio sdcard_r sdcard_rw qcom_oncrpc diag qcom_diag log410411service surfaceflinger /system/bin/surfaceflinger
412 class main
413 user system414 group graphics
415 onrestart exec /system/bin/sync
416 onrestart write /proc/sysrq-trigger c
417418service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
419 class main
420socket zygote stream 660 root system421 onrestart exec /system/bin/sync
422 onrestart write /proc/sysrq-trigger c
423424service drm /system/bin/drmserver
425 class main
426 user drm
427 group drm system inet drmrpc sdcard_r
428429service media /system/bin/mediaserver
430 class main
431 user media
432 group system audio camera inet net_bt net_bt_admin net_bw_acct drmrpc input qcom_diag
433 ioprio rt 4434435service bootanim /system/bin/bootanimation
436 class main
437 user graphics
438 group graphics
439 disabled
440 oneshot //该服务只启动一次,退出后不再运行
441442service dbus /system/bin/dbus-daemon --system --nofork
443 class main
444socket dbus stream 660 bluetooth bluetooth
445 user bluetooth
446 group bluetooth net_bt_admin
447448service bluetoothd /system/bin/logwrapper /system/bin/bluetoothd -n
449 class main
450socket bluetooth stream 660 bluetooth bluetooth
451socket dbus_bluetooth stream 660 bluetooth bluetooth
452# init.rc does not yet support applying capabilities, so run as root and453# let bluetoothd drop uid to bluetooth with the right linux capabilities454 group bluetooth net_bt_admin misc
455 disabled
456457service installd /system/bin/installd
458 class main
459socket installd stream 600systemsystem460461service flash_recovery /system/etc/install-recovery.sh
462 class main
463 oneshot
464465service racoon /system/bin/racoon
466 class main
467socket racoon stream 600systemsystem468# IKE uses UDP port 500. Racoon will setuid to vpn after binding the port.469 group vpn net_admin inet
470 disabled
471 oneshot
472473service mtpd /system/bin/mtpd
474 class main
475socket mtpd stream 600systemsystem476 user vpn
477 group vpn net_admin inet net_raw
478 disabled
479 oneshot
480481service keystore /system/bin/keystore /data/misc/keystore
482 class main
483 user keystore
484 group keystore drmrpc
485socket keystore stream 666486487service dumpstate /system/bin/dumpstate -s488 class main
489socket dumpstate stream 0660 shell log490 disabled
491 oneshot
492493service sshd /system/bin/start-ssh
494 class main
495 disabled
496497service mdnsd /system/bin/mdnsd
498 class main
499 user mdnsr
500 group inet net_raw
501socket mdnsd stream 0660 mdnsr inet
502 disabled
503 oneshot