xref: /aosp_15_r20/system/core/init/README.md (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
1*00c7fec1SAndroid Build Coastguard WorkerAndroid Init Language
2*00c7fec1SAndroid Build Coastguard Worker---------------------
3*00c7fec1SAndroid Build Coastguard Worker
4*00c7fec1SAndroid Build Coastguard WorkerThe Android Init Language consists of five broad classes of statements:
5*00c7fec1SAndroid Build Coastguard WorkerActions, Commands, Services, Options, and Imports.
6*00c7fec1SAndroid Build Coastguard Worker
7*00c7fec1SAndroid Build Coastguard WorkerAll of these are line-oriented, consisting of tokens separated by
8*00c7fec1SAndroid Build Coastguard Workerwhitespace.  The c-style backslash escapes may be used to insert
9*00c7fec1SAndroid Build Coastguard Workerwhitespace into a token.  Double quotes may also be used to prevent
10*00c7fec1SAndroid Build Coastguard Workerwhitespace from breaking text into multiple tokens.  The backslash,
11*00c7fec1SAndroid Build Coastguard Workerwhen it is the last character on a line, may be used for line-folding.
12*00c7fec1SAndroid Build Coastguard Worker
13*00c7fec1SAndroid Build Coastguard WorkerLines which start with a `#` (leading whitespace allowed) are comments.
14*00c7fec1SAndroid Build Coastguard Worker
15*00c7fec1SAndroid Build Coastguard WorkerSystem properties can be expanded using the syntax
16*00c7fec1SAndroid Build Coastguard Worker`${property.name}`. This also works in contexts where concatenation is
17*00c7fec1SAndroid Build Coastguard Workerrequired, such as `import /init.recovery.${ro.hardware}.rc`.
18*00c7fec1SAndroid Build Coastguard Worker
19*00c7fec1SAndroid Build Coastguard WorkerActions and Services implicitly declare a new section.  All commands
20*00c7fec1SAndroid Build Coastguard Workeror options belong to the section most recently declared.  Commands
21*00c7fec1SAndroid Build Coastguard Workeror options before the first section are ignored.
22*00c7fec1SAndroid Build Coastguard Worker
23*00c7fec1SAndroid Build Coastguard WorkerServices have unique names.  If a second Service is defined
24*00c7fec1SAndroid Build Coastguard Workerwith the same name as an existing one, it is ignored and an error
25*00c7fec1SAndroid Build Coastguard Workermessage is logged.
26*00c7fec1SAndroid Build Coastguard Worker
27*00c7fec1SAndroid Build Coastguard Worker
28*00c7fec1SAndroid Build Coastguard WorkerInit .rc Files
29*00c7fec1SAndroid Build Coastguard Worker--------------
30*00c7fec1SAndroid Build Coastguard WorkerThe init language is used in plain text files that take the .rc file
31*00c7fec1SAndroid Build Coastguard Workerextension.  There are typically multiple of these in multiple
32*00c7fec1SAndroid Build Coastguard Workerlocations on the system, described below.
33*00c7fec1SAndroid Build Coastguard Worker
34*00c7fec1SAndroid Build Coastguard Worker`/system/etc/init/hw/init.rc` is the primary .rc file and is loaded by the init executable at the
35*00c7fec1SAndroid Build Coastguard Workerbeginning of its execution.  It is responsible for the initial set up of the system.
36*00c7fec1SAndroid Build Coastguard Worker
37*00c7fec1SAndroid Build Coastguard WorkerInit loads all of the files contained within the
38*00c7fec1SAndroid Build Coastguard Worker`/{system,system_ext,vendor,odm,product}/etc/init/` directories immediately after loading
39*00c7fec1SAndroid Build Coastguard Workerthe primary `/system/etc/init/hw/init.rc`.  This is explained in more details in the
40*00c7fec1SAndroid Build Coastguard Worker[Imports](#imports) section of this file.
41*00c7fec1SAndroid Build Coastguard Worker
42*00c7fec1SAndroid Build Coastguard WorkerLegacy devices without the first stage mount mechanism previously were
43*00c7fec1SAndroid Build Coastguard Workerable to import init scripts during mount_all, however that is deprecated
44*00c7fec1SAndroid Build Coastguard Workerand not allowed for devices launching after Q.
45*00c7fec1SAndroid Build Coastguard Worker
46*00c7fec1SAndroid Build Coastguard WorkerThe intention of these directories is:
47*00c7fec1SAndroid Build Coastguard Worker
48*00c7fec1SAndroid Build Coastguard Worker   1. /system/etc/init/ is for core system items such as
49*00c7fec1SAndroid Build Coastguard Worker      SurfaceFlinger, MediaService, and logd.
50*00c7fec1SAndroid Build Coastguard Worker   2. /vendor/etc/init/ is for SoC vendor items such as actions or
51*00c7fec1SAndroid Build Coastguard Worker      daemons needed for core SoC functionality.
52*00c7fec1SAndroid Build Coastguard Worker   3. /odm/etc/init/ is for device manufacturer items such as
53*00c7fec1SAndroid Build Coastguard Worker      actions or daemons needed for motion sensor or other peripheral
54*00c7fec1SAndroid Build Coastguard Worker      functionality.
55*00c7fec1SAndroid Build Coastguard Worker
56*00c7fec1SAndroid Build Coastguard WorkerAll services whose binaries reside on the system, vendor, or odm
57*00c7fec1SAndroid Build Coastguard Workerpartitions should have their service entries placed into a
58*00c7fec1SAndroid Build Coastguard Workercorresponding init .rc file, located in the /etc/init/
59*00c7fec1SAndroid Build Coastguard Workerdirectory of the partition where they reside.  There is a build
60*00c7fec1SAndroid Build Coastguard Workersystem macro, LOCAL\_INIT\_RC, that handles this for developers.  Each
61*00c7fec1SAndroid Build Coastguard Workerinit .rc file should additionally contain any actions associated with
62*00c7fec1SAndroid Build Coastguard Workerits service.
63*00c7fec1SAndroid Build Coastguard Worker
64*00c7fec1SAndroid Build Coastguard WorkerAn example is the userdebug logcatd.rc and Android.mk files located in the
65*00c7fec1SAndroid Build Coastguard Workersystem/core/logcat directory.  The LOCAL\_INIT\_RC macro in the
66*00c7fec1SAndroid Build Coastguard WorkerAndroid.mk file places logcatd.rc in /system/etc/init/ during the
67*00c7fec1SAndroid Build Coastguard Workerbuild process.  Init loads logcatd.rc during the mount\_all command and
68*00c7fec1SAndroid Build Coastguard Workerallows the service to be run and the action to be queued when
69*00c7fec1SAndroid Build Coastguard Workerappropriate.
70*00c7fec1SAndroid Build Coastguard Worker
71*00c7fec1SAndroid Build Coastguard WorkerThis break up of init .rc files according to their daemon is preferred
72*00c7fec1SAndroid Build Coastguard Workerto the previously used monolithic init .rc files.  This approach
73*00c7fec1SAndroid Build Coastguard Workerensures that the only service entries that init reads and the only
74*00c7fec1SAndroid Build Coastguard Workeractions that init performs correspond to services whose binaries are in
75*00c7fec1SAndroid Build Coastguard Workerfact present on the file system, which was not the case with the
76*00c7fec1SAndroid Build Coastguard Workermonolithic init .rc files.  This additionally will aid in merge
77*00c7fec1SAndroid Build Coastguard Workerconflict resolution when multiple services are added to the system, as
78*00c7fec1SAndroid Build Coastguard Workereach one will go into a separate file.
79*00c7fec1SAndroid Build Coastguard Worker
80*00c7fec1SAndroid Build Coastguard WorkerVersioned RC files within APEXs
81*00c7fec1SAndroid Build Coastguard Worker-------------------------------
82*00c7fec1SAndroid Build Coastguard Worker
83*00c7fec1SAndroid Build Coastguard WorkerWith the arrival of mainline on Android Q, the individual mainline
84*00c7fec1SAndroid Build Coastguard Workermodules carry their own init.rc files within their boundaries. Init
85*00c7fec1SAndroid Build Coastguard Workerprocesses these files according to the naming pattern `/apex/*/etc/*rc`.
86*00c7fec1SAndroid Build Coastguard Worker
87*00c7fec1SAndroid Build Coastguard WorkerBecause APEX modules must run on more than one release of Android,
88*00c7fec1SAndroid Build Coastguard Workerthey may require different parameters as part of the services they
89*00c7fec1SAndroid Build Coastguard Workerdefine. This is achieved, starting in Android T, by incorporating
90*00c7fec1SAndroid Build Coastguard Workerthe SDK version information in the name of the init file.  The suffix
91*00c7fec1SAndroid Build Coastguard Workeris changed from `.rc` to `.#rc` where # is the first SDK where that
92*00c7fec1SAndroid Build Coastguard WorkerRC file is accepted. An init file specific to SDK=31 might be named
93*00c7fec1SAndroid Build Coastguard Worker`init.31rc`. With this scheme, an APEX may include multiple init files. An
94*00c7fec1SAndroid Build Coastguard Workerexample is appropriate.
95*00c7fec1SAndroid Build Coastguard Worker
96*00c7fec1SAndroid Build Coastguard WorkerFor an APEX module with the following files in /apex/sample-module/apex/etc/:
97*00c7fec1SAndroid Build Coastguard Worker
98*00c7fec1SAndroid Build Coastguard Worker   1. init.rc
99*00c7fec1SAndroid Build Coastguard Worker   2. init.32rc
100*00c7fec1SAndroid Build Coastguard Worker   4. init.35rc
101*00c7fec1SAndroid Build Coastguard Worker
102*00c7fec1SAndroid Build Coastguard WorkerThe selection rule chooses the highest `.#rc` value that does not
103*00c7fec1SAndroid Build Coastguard Workerexceed the SDK of the currently running system. The unadorned `.rc`
104*00c7fec1SAndroid Build Coastguard Workeris interpreted as sdk=0.
105*00c7fec1SAndroid Build Coastguard Worker
106*00c7fec1SAndroid Build Coastguard WorkerWhen this APEX is installed on a device with SDK <=31, the system will
107*00c7fec1SAndroid Build Coastguard Workerprocess init.rc.  When installed on a device running SDK 32, 33, or 34,
108*00c7fec1SAndroid Build Coastguard Workerit will use init.32rc.  When installed on a device running SDKs >= 35,
109*00c7fec1SAndroid Build Coastguard Workerit will choose init.35rc
110*00c7fec1SAndroid Build Coastguard Worker
111*00c7fec1SAndroid Build Coastguard WorkerThis versioning scheme is used only for the init files within APEX
112*00c7fec1SAndroid Build Coastguard Workermodules; it does not apply to the init files stored in /system/etc/init,
113*00c7fec1SAndroid Build Coastguard Worker/vendor/etc/init, or other directories.
114*00c7fec1SAndroid Build Coastguard Worker
115*00c7fec1SAndroid Build Coastguard WorkerThis naming scheme is available after Android S.
116*00c7fec1SAndroid Build Coastguard Worker
117*00c7fec1SAndroid Build Coastguard WorkerActions
118*00c7fec1SAndroid Build Coastguard Worker-------
119*00c7fec1SAndroid Build Coastguard WorkerActions are named sequences of commands.  Actions have a trigger which
120*00c7fec1SAndroid Build Coastguard Workeris used to determine when the action is executed.  When an event
121*00c7fec1SAndroid Build Coastguard Workeroccurs which matches an action's trigger, that action is added to
122*00c7fec1SAndroid Build Coastguard Workerthe tail of a to-be-executed queue (unless it is already on the
123*00c7fec1SAndroid Build Coastguard Workerqueue).
124*00c7fec1SAndroid Build Coastguard Worker
125*00c7fec1SAndroid Build Coastguard WorkerEach action in the queue is dequeued in sequence and each command in
126*00c7fec1SAndroid Build Coastguard Workerthat action is executed in sequence.  Init handles other activities
127*00c7fec1SAndroid Build Coastguard Worker(device creation/destruction, property setting, process restarting)
128*00c7fec1SAndroid Build Coastguard Worker"between" the execution of the commands in activities.
129*00c7fec1SAndroid Build Coastguard Worker
130*00c7fec1SAndroid Build Coastguard WorkerActions take the form of:
131*00c7fec1SAndroid Build Coastguard Worker
132*00c7fec1SAndroid Build Coastguard Worker    on <trigger> [&& <trigger>]*
133*00c7fec1SAndroid Build Coastguard Worker       <command>
134*00c7fec1SAndroid Build Coastguard Worker       <command>
135*00c7fec1SAndroid Build Coastguard Worker       <command>
136*00c7fec1SAndroid Build Coastguard Worker
137*00c7fec1SAndroid Build Coastguard WorkerActions are added to the queue and executed based on the order that
138*00c7fec1SAndroid Build Coastguard Workerthe file that contains them was parsed (see the Imports section), then
139*00c7fec1SAndroid Build Coastguard Workersequentially within an individual file.
140*00c7fec1SAndroid Build Coastguard Worker
141*00c7fec1SAndroid Build Coastguard WorkerFor example if a file contains:
142*00c7fec1SAndroid Build Coastguard Worker
143*00c7fec1SAndroid Build Coastguard Worker    on boot
144*00c7fec1SAndroid Build Coastguard Worker       setprop a 1
145*00c7fec1SAndroid Build Coastguard Worker       setprop b 2
146*00c7fec1SAndroid Build Coastguard Worker
147*00c7fec1SAndroid Build Coastguard Worker    on boot && property:true=true
148*00c7fec1SAndroid Build Coastguard Worker       setprop c 1
149*00c7fec1SAndroid Build Coastguard Worker       setprop d 2
150*00c7fec1SAndroid Build Coastguard Worker
151*00c7fec1SAndroid Build Coastguard Worker    on boot
152*00c7fec1SAndroid Build Coastguard Worker       setprop e 1
153*00c7fec1SAndroid Build Coastguard Worker       setprop f 2
154*00c7fec1SAndroid Build Coastguard Worker
155*00c7fec1SAndroid Build Coastguard WorkerThen when the `boot` trigger occurs and assuming the property `true`
156*00c7fec1SAndroid Build Coastguard Workerequals `true`, then the order of the commands executed will be:
157*00c7fec1SAndroid Build Coastguard Worker
158*00c7fec1SAndroid Build Coastguard Worker    setprop a 1
159*00c7fec1SAndroid Build Coastguard Worker    setprop b 2
160*00c7fec1SAndroid Build Coastguard Worker    setprop c 1
161*00c7fec1SAndroid Build Coastguard Worker    setprop d 2
162*00c7fec1SAndroid Build Coastguard Worker    setprop e 1
163*00c7fec1SAndroid Build Coastguard Worker    setprop f 2
164*00c7fec1SAndroid Build Coastguard Worker
165*00c7fec1SAndroid Build Coastguard WorkerIf the property `true` wasn't `true` when the `boot` was triggered, then the
166*00c7fec1SAndroid Build Coastguard Workerorder of the commands executed will be:
167*00c7fec1SAndroid Build Coastguard Worker
168*00c7fec1SAndroid Build Coastguard Worker    setprop a 1
169*00c7fec1SAndroid Build Coastguard Worker    setprop b 2
170*00c7fec1SAndroid Build Coastguard Worker    setprop e 1
171*00c7fec1SAndroid Build Coastguard Worker    setprop f 2
172*00c7fec1SAndroid Build Coastguard Worker
173*00c7fec1SAndroid Build Coastguard WorkerIf the property `true` becomes `true` *AFTER* `boot` was triggered, nothing will
174*00c7fec1SAndroid Build Coastguard Workerbe executed. The condition `boot && property:true=true` will be evaluated to
175*00c7fec1SAndroid Build Coastguard Workerfalse because the `boot` trigger is a past event.
176*00c7fec1SAndroid Build Coastguard Worker
177*00c7fec1SAndroid Build Coastguard WorkerNote that when `ro.property_service.async_persist_writes` is `true`, there is no
178*00c7fec1SAndroid Build Coastguard Workerdefined ordering between persistent setprops and non-persistent setprops. For
179*00c7fec1SAndroid Build Coastguard Workerexample:
180*00c7fec1SAndroid Build Coastguard Worker
181*00c7fec1SAndroid Build Coastguard Worker    on boot
182*00c7fec1SAndroid Build Coastguard Worker        setprop a 1
183*00c7fec1SAndroid Build Coastguard Worker        setprop persist.b 2
184*00c7fec1SAndroid Build Coastguard Worker
185*00c7fec1SAndroid Build Coastguard WorkerWhen `ro.property_service.async_persist_writes` is `true`, triggers for these
186*00c7fec1SAndroid Build Coastguard Workertwo properties may execute in any order.
187*00c7fec1SAndroid Build Coastguard Worker
188*00c7fec1SAndroid Build Coastguard WorkerServices
189*00c7fec1SAndroid Build Coastguard Worker--------
190*00c7fec1SAndroid Build Coastguard WorkerServices are programs which init launches and (optionally) restarts
191*00c7fec1SAndroid Build Coastguard Workerwhen they exit.  Services take the form of:
192*00c7fec1SAndroid Build Coastguard Worker
193*00c7fec1SAndroid Build Coastguard Worker    service <name> <pathname> [ <argument> ]*
194*00c7fec1SAndroid Build Coastguard Worker       <option>
195*00c7fec1SAndroid Build Coastguard Worker       <option>
196*00c7fec1SAndroid Build Coastguard Worker       ...
197*00c7fec1SAndroid Build Coastguard Worker
198*00c7fec1SAndroid Build Coastguard Worker
199*00c7fec1SAndroid Build Coastguard WorkerOptions
200*00c7fec1SAndroid Build Coastguard Worker-------
201*00c7fec1SAndroid Build Coastguard WorkerOptions are modifiers to services.  They affect how and when init
202*00c7fec1SAndroid Build Coastguard Workerruns the service.
203*00c7fec1SAndroid Build Coastguard Worker
204*00c7fec1SAndroid Build Coastguard Worker`capabilities [ <capability>\* ]`
205*00c7fec1SAndroid Build Coastguard Worker> Set capabilities when exec'ing this service. 'capability' should be a Linux
206*00c7fec1SAndroid Build Coastguard Worker  capability without the "CAP\_" prefix, like "NET\_ADMIN" or "SETPCAP". See
207*00c7fec1SAndroid Build Coastguard Worker  http://man7.org/linux/man-pages/man7/capabilities.7.html for a list of Linux
208*00c7fec1SAndroid Build Coastguard Worker  capabilities.
209*00c7fec1SAndroid Build Coastguard Worker  If no capabilities are provided, then behaviour depends on the user the service runs under:
210*00c7fec1SAndroid Build Coastguard Worker    * if it's root, then the service will run with all the capabitilies (note: whether the
211*00c7fec1SAndroid Build Coastguard Worker        service can actually use them is controlled by selinux);
212*00c7fec1SAndroid Build Coastguard Worker    * otherwise all capabilities will be dropped.
213*00c7fec1SAndroid Build Coastguard Worker
214*00c7fec1SAndroid Build Coastguard Worker`class <name> [ <name>\* ]`
215*00c7fec1SAndroid Build Coastguard Worker> Specify class names for the service.  All services in a
216*00c7fec1SAndroid Build Coastguard Worker  named class may be started or stopped together.  A service
217*00c7fec1SAndroid Build Coastguard Worker  is in the class "default" if one is not specified via the
218*00c7fec1SAndroid Build Coastguard Worker  class option. Additional classnames beyond the (required) first
219*00c7fec1SAndroid Build Coastguard Worker  one are used to group services.
220*00c7fec1SAndroid Build Coastguard Worker  The `animation` class should include all services necessary for both
221*00c7fec1SAndroid Build Coastguard Worker  boot animation and shutdown animation. As these services can be
222*00c7fec1SAndroid Build Coastguard Worker  launched very early during bootup and can run until the last stage
223*00c7fec1SAndroid Build Coastguard Worker  of shutdown, access to /data partition is not guaranteed. These
224*00c7fec1SAndroid Build Coastguard Worker  services can check files under /data but it should not keep files opened
225*00c7fec1SAndroid Build Coastguard Worker  and should work when /data is not available.
226*00c7fec1SAndroid Build Coastguard Worker
227*00c7fec1SAndroid Build Coastguard Worker`console [<console>]`
228*00c7fec1SAndroid Build Coastguard Worker> This service needs a console. The optional second parameter chooses a
229*00c7fec1SAndroid Build Coastguard Worker  specific console instead of the default. The default "/dev/console" can
230*00c7fec1SAndroid Build Coastguard Worker  be changed by setting the "androidboot.console" kernel parameter. In
231*00c7fec1SAndroid Build Coastguard Worker  all cases the leading "/dev/" should be omitted, so "/dev/tty0" would be
232*00c7fec1SAndroid Build Coastguard Worker  specified as just "console tty0".
233*00c7fec1SAndroid Build Coastguard Worker  This option connects stdin, stdout, and stderr to the console. It is mutually exclusive with the
234*00c7fec1SAndroid Build Coastguard Worker  stdio_to_kmsg option, which only connects stdout and stderr to kmsg.
235*00c7fec1SAndroid Build Coastguard Worker
236*00c7fec1SAndroid Build Coastguard Worker`critical [window=<fatal crash window mins>] [target=<fatal reboot target>]`
237*00c7fec1SAndroid Build Coastguard Worker> This is a device-critical service. If it exits more than four times in
238*00c7fec1SAndroid Build Coastguard Worker  _fatal crash window mins_ minutes or before boot completes, the device
239*00c7fec1SAndroid Build Coastguard Worker  will reboot into _fatal reboot target_.
240*00c7fec1SAndroid Build Coastguard Worker  The default value of _fatal crash window mins_ is 4, and default value
241*00c7fec1SAndroid Build Coastguard Worker  of _fatal reboot target_ is 'bootloader'.
242*00c7fec1SAndroid Build Coastguard Worker  For tests, the fatal reboot can be skipped by setting property
243*00c7fec1SAndroid Build Coastguard Worker  `init.svc_debug.no_fatal.<service-name>` to `true` for specified critical service.
244*00c7fec1SAndroid Build Coastguard Worker
245*00c7fec1SAndroid Build Coastguard Worker`disabled`
246*00c7fec1SAndroid Build Coastguard Worker> This service will not automatically start with its class.
247*00c7fec1SAndroid Build Coastguard Worker  It must be explicitly started by name or by interface name.
248*00c7fec1SAndroid Build Coastguard Worker
249*00c7fec1SAndroid Build Coastguard Worker`enter_namespace <type> <path>`
250*00c7fec1SAndroid Build Coastguard Worker> Enters the namespace of type _type_ located at _path_. Only network namespaces are supported with
251*00c7fec1SAndroid Build Coastguard Worker  _type_ set to "net". Note that only one namespace of a given _type_ may be entered.
252*00c7fec1SAndroid Build Coastguard Worker
253*00c7fec1SAndroid Build Coastguard Worker`file <path> <type>`
254*00c7fec1SAndroid Build Coastguard Worker> Open a file path and pass its fd to the launched process. _type_ must be
255*00c7fec1SAndroid Build Coastguard Worker  "r", "w" or "rw".  For native executables see libcutils
256*00c7fec1SAndroid Build Coastguard Worker  android\_get\_control\_file().
257*00c7fec1SAndroid Build Coastguard Worker
258*00c7fec1SAndroid Build Coastguard Worker`gentle_kill`
259*00c7fec1SAndroid Build Coastguard Worker> This service will be sent SIGTERM instead of SIGKILL when stopped. After a 200 ms timeout, it will
260*00c7fec1SAndroid Build Coastguard Worker  be sent SIGKILL.
261*00c7fec1SAndroid Build Coastguard Worker
262*00c7fec1SAndroid Build Coastguard Worker`group <groupname> [ <groupname>\* ]`
263*00c7fec1SAndroid Build Coastguard Worker> Change to 'groupname' before exec'ing this service.  Additional
264*00c7fec1SAndroid Build Coastguard Worker  groupnames beyond the (required) first one are used to set the
265*00c7fec1SAndroid Build Coastguard Worker  supplemental groups of the process (via setgroups()).
266*00c7fec1SAndroid Build Coastguard Worker  Currently defaults to root.  (??? probably should default to nobody)
267*00c7fec1SAndroid Build Coastguard Worker
268*00c7fec1SAndroid Build Coastguard Worker`interface <interface name> <instance name>`
269*00c7fec1SAndroid Build Coastguard Worker> Associates this service with a list of the AIDL or HIDL services that it provides. The interface
270*00c7fec1SAndroid Build Coastguard Worker  name must be a fully-qualified name and not a value name. For instance, this is used to allow
271*00c7fec1SAndroid Build Coastguard Worker  servicemanager or hwservicemanager to lazily start services. When multiple interfaces are served,
272*00c7fec1SAndroid Build Coastguard Worker  this tag should be used multiple times. An example of an entry for a HIDL
273*00c7fec1SAndroid Build Coastguard Worker  interface is `interface [email protected]::IBaz default`. For an AIDL interface, use
274*00c7fec1SAndroid Build Coastguard Worker  `interface aidl <instance name>`. The instance name for an AIDL interface is
275*00c7fec1SAndroid Build Coastguard Worker  whatever is registered with servicemanager, and these can be listed with `adb
276*00c7fec1SAndroid Build Coastguard Worker  shell dumpsys -l`.
277*00c7fec1SAndroid Build Coastguard Worker
278*00c7fec1SAndroid Build Coastguard Worker`ioprio <class> <priority>`
279*00c7fec1SAndroid Build Coastguard Worker> Sets the IO priority and IO priority class for this service via the SYS_ioprio_set syscall.
280*00c7fec1SAndroid Build Coastguard Worker  _class_ must be one of "rt", "be", or "idle". _priority_ must be an integer in the range 0 - 7.
281*00c7fec1SAndroid Build Coastguard Worker
282*00c7fec1SAndroid Build Coastguard Worker`keycodes <keycode> [ <keycode>\* ]`
283*00c7fec1SAndroid Build Coastguard Worker> Sets the keycodes that will trigger this service. If all of the keys corresponding to the passed
284*00c7fec1SAndroid Build Coastguard Worker  keycodes are pressed at once, the service will start. This is typically used to start the
285*00c7fec1SAndroid Build Coastguard Worker  bugreport service.
286*00c7fec1SAndroid Build Coastguard Worker
287*00c7fec1SAndroid Build Coastguard Worker> This option may take a property instead of a list of keycodes. In this case, only one option is
288*00c7fec1SAndroid Build Coastguard Worker  provided: the property name in the typical property expansion format. The property must contain
289*00c7fec1SAndroid Build Coastguard Worker  a comma separated list of keycode values or the text 'none' to indicate that
290*00c7fec1SAndroid Build Coastguard Worker  this service does not respond to keycodes.
291*00c7fec1SAndroid Build Coastguard Worker
292*00c7fec1SAndroid Build Coastguard Worker> For example, `keycodes ${some.property.name:-none}` where some.property.name expands
293*00c7fec1SAndroid Build Coastguard Worker  to "123,124,125". Since keycodes are handled very early in init,
294*00c7fec1SAndroid Build Coastguard Worker  only PRODUCT_DEFAULT_PROPERTY_OVERRIDES properties can be used.
295*00c7fec1SAndroid Build Coastguard Worker
296*00c7fec1SAndroid Build Coastguard Worker`memcg.limit_in_bytes <value>` and `memcg.limit_percent <value>`
297*00c7fec1SAndroid Build Coastguard Worker> Sets the child's memory.limit_in_bytes to the minimum of `limit_in_bytes`
298*00c7fec1SAndroid Build Coastguard Worker  bytes and `limit_percent` which is interpreted as a percentage of the size
299*00c7fec1SAndroid Build Coastguard Worker  of the device's physical memory (only if memcg is mounted).
300*00c7fec1SAndroid Build Coastguard Worker  Values must be equal or greater than 0.
301*00c7fec1SAndroid Build Coastguard Worker
302*00c7fec1SAndroid Build Coastguard Worker`memcg.limit_property <value>`
303*00c7fec1SAndroid Build Coastguard Worker> Sets the child's memory.limit_in_bytes to the value of the specified property
304*00c7fec1SAndroid Build Coastguard Worker  (only if memcg is mounted). This property will override the values specified
305*00c7fec1SAndroid Build Coastguard Worker  via `memcg.limit_in_bytes` and `memcg.limit_percent`.
306*00c7fec1SAndroid Build Coastguard Worker
307*00c7fec1SAndroid Build Coastguard Worker`memcg.soft_limit_in_bytes <value>`
308*00c7fec1SAndroid Build Coastguard Worker> Sets the child's memory.soft_limit_in_bytes to the specified value (only if memcg is mounted),
309*00c7fec1SAndroid Build Coastguard Worker  which must be equal or greater than 0.
310*00c7fec1SAndroid Build Coastguard Worker
311*00c7fec1SAndroid Build Coastguard Worker`memcg.swappiness <value>`
312*00c7fec1SAndroid Build Coastguard Worker> Sets the child's memory.swappiness to the specified value (only if memcg is mounted),
313*00c7fec1SAndroid Build Coastguard Worker  which must be equal or greater than 0.
314*00c7fec1SAndroid Build Coastguard Worker
315*00c7fec1SAndroid Build Coastguard Worker`namespace <pid|mnt>`
316*00c7fec1SAndroid Build Coastguard Worker> Enter a new PID or mount namespace when forking the service.
317*00c7fec1SAndroid Build Coastguard Worker
318*00c7fec1SAndroid Build Coastguard Worker`oneshot`
319*00c7fec1SAndroid Build Coastguard Worker> Do not restart the service when it exits.
320*00c7fec1SAndroid Build Coastguard Worker
321*00c7fec1SAndroid Build Coastguard Worker`onrestart`
322*00c7fec1SAndroid Build Coastguard Worker> Execute a Command (see below) when service restarts.
323*00c7fec1SAndroid Build Coastguard Worker
324*00c7fec1SAndroid Build Coastguard Worker`oom_score_adjust <value>`
325*00c7fec1SAndroid Build Coastguard Worker> Sets the child's /proc/self/oom\_score\_adj to the specified value,
326*00c7fec1SAndroid Build Coastguard Worker  which must range from -1000 to 1000.
327*00c7fec1SAndroid Build Coastguard Worker
328*00c7fec1SAndroid Build Coastguard Worker`override`
329*00c7fec1SAndroid Build Coastguard Worker> Indicates that this service definition is meant to override a previous definition for a service
330*00c7fec1SAndroid Build Coastguard Worker  with the same name. This is typically meant for services on /odm to override those defined on
331*00c7fec1SAndroid Build Coastguard Worker  /vendor. The last service definition that init parses with this keyword is the service definition
332*00c7fec1SAndroid Build Coastguard Worker  will use for this service. Pay close attention to the order in which init.rc files are parsed,
333*00c7fec1SAndroid Build Coastguard Worker  since it has some peculiarities for backwards compatibility reasons. The 'imports' section of
334*00c7fec1SAndroid Build Coastguard Worker  this file has more details on the order.
335*00c7fec1SAndroid Build Coastguard Worker
336*00c7fec1SAndroid Build Coastguard Worker`priority <priority>`
337*00c7fec1SAndroid Build Coastguard Worker> Scheduling priority of the service process. This value has to be in range
338*00c7fec1SAndroid Build Coastguard Worker  -20 to 19. Default priority is 0. Priority is set via setpriority().
339*00c7fec1SAndroid Build Coastguard Worker
340*00c7fec1SAndroid Build Coastguard Worker`reboot_on_failure <target>`
341*00c7fec1SAndroid Build Coastguard Worker> If this process cannot be started or if the process terminates with an exit code other than
342*00c7fec1SAndroid Build Coastguard Worker  CLD_EXITED or an status other than '0', reboot the system with the target specified in
343*00c7fec1SAndroid Build Coastguard Worker  _target_. _target_ takes the same format as the parameter to sys.powerctl. This is particularly
344*00c7fec1SAndroid Build Coastguard Worker  intended to be used with the `exec_start` builtin for any must-have checks during boot.
345*00c7fec1SAndroid Build Coastguard Worker
346*00c7fec1SAndroid Build Coastguard Worker`restart_period <seconds>`
347*00c7fec1SAndroid Build Coastguard Worker> If a non-oneshot service exits, it will be restarted at its previous start time plus this period.
348*00c7fec1SAndroid Build Coastguard Worker  The default value is 5s. This can be used to implement periodic services together with the
349*00c7fec1SAndroid Build Coastguard Worker  `timeout_period` command below. For example, it may be set to 3600 to indicate that the service
350*00c7fec1SAndroid Build Coastguard Worker  should run every hour or 86400 to indicate that the service should run every day. This can be set
351*00c7fec1SAndroid Build Coastguard Worker  to a value shorter than 5s for example 0, but the minimum 5s delay is enforced if the restart was
352*00c7fec1SAndroid Build Coastguard Worker  due to a crash. This is to rate limit persistentally crashing services. In other words,
353*00c7fec1SAndroid Build Coastguard Worker  `<seconds>` smaller than 5 is respected only when the service exits deliverately and successfully
354*00c7fec1SAndroid Build Coastguard Worker  (i.e. by calling exit(0)).
355*00c7fec1SAndroid Build Coastguard Worker
356*00c7fec1SAndroid Build Coastguard Worker`rlimit <resource> <cur> <max>`
357*00c7fec1SAndroid Build Coastguard Worker> This applies the given rlimit to the service. rlimits are inherited by child
358*00c7fec1SAndroid Build Coastguard Worker  processes, so this effectively applies the given rlimit to the process tree
359*00c7fec1SAndroid Build Coastguard Worker  started by this service.
360*00c7fec1SAndroid Build Coastguard Worker  It is parsed similarly to the setrlimit command specified below.
361*00c7fec1SAndroid Build Coastguard Worker
362*00c7fec1SAndroid Build Coastguard Worker`seclabel <seclabel>`
363*00c7fec1SAndroid Build Coastguard Worker> Change to 'seclabel' before exec'ing this service.
364*00c7fec1SAndroid Build Coastguard Worker  Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
365*00c7fec1SAndroid Build Coastguard Worker  Services on the system partition can instead use policy-defined transitions
366*00c7fec1SAndroid Build Coastguard Worker  based on their file security context.
367*00c7fec1SAndroid Build Coastguard Worker  If not specified and no transition is defined in policy, defaults to the init context.
368*00c7fec1SAndroid Build Coastguard Worker
369*00c7fec1SAndroid Build Coastguard Worker`setenv <name> <value>`
370*00c7fec1SAndroid Build Coastguard Worker> Set the environment variable _name_ to _value_ in the launched process.
371*00c7fec1SAndroid Build Coastguard Worker
372*00c7fec1SAndroid Build Coastguard Worker`shutdown <shutdown_behavior>`
373*00c7fec1SAndroid Build Coastguard Worker> Set shutdown behavior of the service process. When this is not specified,
374*00c7fec1SAndroid Build Coastguard Worker  the service is killed during shutdown process by using SIGTERM and SIGKILL.
375*00c7fec1SAndroid Build Coastguard Worker  The service with shutdown_behavior of "critical" is not killed during shutdown
376*00c7fec1SAndroid Build Coastguard Worker  until shutdown times out. When shutdown times out, even services tagged with
377*00c7fec1SAndroid Build Coastguard Worker  "shutdown critical" will be killed. When the service tagged with "shutdown critical"
378*00c7fec1SAndroid Build Coastguard Worker  is not running when shut down starts, it will be started.
379*00c7fec1SAndroid Build Coastguard Worker
380*00c7fec1SAndroid Build Coastguard Worker`sigstop`
381*00c7fec1SAndroid Build Coastguard Worker> Send SIGSTOP to the service immediately before exec is called. This is intended for debugging.
382*00c7fec1SAndroid Build Coastguard Worker  See the below section on debugging for how this can be used.
383*00c7fec1SAndroid Build Coastguard Worker
384*00c7fec1SAndroid Build Coastguard Worker`socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]`
385*00c7fec1SAndroid Build Coastguard Worker> Create a UNIX domain socket named /dev/socket/_name_ and pass its fd to the
386*00c7fec1SAndroid Build Coastguard Worker  launched process.  The socket is created synchronously when the service starts.
387*00c7fec1SAndroid Build Coastguard Worker  _type_ must be "dgram", "stream" or "seqpacket".  _type_ may end with "+passcred"
388*00c7fec1SAndroid Build Coastguard Worker  to enable SO_PASSCRED on the socket or "+listen" to synchronously make it a listening socket.
389*00c7fec1SAndroid Build Coastguard Worker  User and group default to 0.  'seclabel' is the SELinux security context for the
390*00c7fec1SAndroid Build Coastguard Worker  socket.  It defaults to the service security context, as specified by
391*00c7fec1SAndroid Build Coastguard Worker  seclabel or computed based on the service executable file security context.
392*00c7fec1SAndroid Build Coastguard Worker  For native executables see libcutils android\_get\_control\_socket().
393*00c7fec1SAndroid Build Coastguard Worker
394*00c7fec1SAndroid Build Coastguard Worker`stdio_to_kmsg`
395*00c7fec1SAndroid Build Coastguard Worker> Redirect stdout and stderr to /dev/kmsg_debug. This is useful for services that do not use native
396*00c7fec1SAndroid Build Coastguard Worker  Android logging during early boot and whose logs messages we want to capture. This is only enabled
397*00c7fec1SAndroid Build Coastguard Worker  when /dev/kmsg_debug is enabled, which is only enabled on userdebug and eng builds.
398*00c7fec1SAndroid Build Coastguard Worker  This is mutually exclusive with the console option, which additionally connects stdin to the
399*00c7fec1SAndroid Build Coastguard Worker  given console.
400*00c7fec1SAndroid Build Coastguard Worker
401*00c7fec1SAndroid Build Coastguard Worker`task_profiles <profile> [ <profile>\* ]`
402*00c7fec1SAndroid Build Coastguard Worker> Set task profiles. Before Android U, the profiles are applied to the main thread of the service.
403*00c7fec1SAndroid Build Coastguard Worker  For Android U and later, the profiles are applied to the entire service process. This is designed
404*00c7fec1SAndroid Build Coastguard Worker  to replace the use of writepid option for moving a process into a cgroup.
405*00c7fec1SAndroid Build Coastguard Worker
406*00c7fec1SAndroid Build Coastguard Worker`timeout_period <seconds>`
407*00c7fec1SAndroid Build Coastguard Worker> Provide a timeout after which point the service will be killed. The oneshot keyword is respected
408*00c7fec1SAndroid Build Coastguard Worker  here, so oneshot services do not automatically restart, however all other services will.
409*00c7fec1SAndroid Build Coastguard Worker  This is particularly useful for creating a periodic service combined with the restart_period
410*00c7fec1SAndroid Build Coastguard Worker  option described above.
411*00c7fec1SAndroid Build Coastguard Worker
412*00c7fec1SAndroid Build Coastguard Worker`updatable`
413*00c7fec1SAndroid Build Coastguard Worker> Mark that the service can be overridden (via the 'override' option) later in
414*00c7fec1SAndroid Build Coastguard Worker  the boot sequence by APEXes. When a service with updatable option is started
415*00c7fec1SAndroid Build Coastguard Worker  before APEXes are all activated, the execution is delayed until the activation
416*00c7fec1SAndroid Build Coastguard Worker  is finished. A service that is not marked as updatable cannot be overridden by
417*00c7fec1SAndroid Build Coastguard Worker  APEXes.
418*00c7fec1SAndroid Build Coastguard Worker
419*00c7fec1SAndroid Build Coastguard Worker`user <username>`
420*00c7fec1SAndroid Build Coastguard Worker> Change to 'username' before exec'ing this service.
421*00c7fec1SAndroid Build Coastguard Worker  Currently defaults to root.  (??? probably should default to nobody)
422*00c7fec1SAndroid Build Coastguard Worker  As of Android M, processes should use this option even if they
423*00c7fec1SAndroid Build Coastguard Worker  require Linux capabilities.  Previously, to acquire Linux
424*00c7fec1SAndroid Build Coastguard Worker  capabilities, a process would need to run as root, request the
425*00c7fec1SAndroid Build Coastguard Worker  capabilities, then drop to its desired uid.  There is a new
426*00c7fec1SAndroid Build Coastguard Worker  mechanism through fs\_config that allows device manufacturers to add
427*00c7fec1SAndroid Build Coastguard Worker  Linux capabilities to specific binaries on a file system that should
428*00c7fec1SAndroid Build Coastguard Worker  be used instead. This mechanism is described on
429*00c7fec1SAndroid Build Coastguard Worker  <http://source.android.com/devices/tech/config/filesystem.html>.  When
430*00c7fec1SAndroid Build Coastguard Worker  using this new mechanism, processes can use the user option to
431*00c7fec1SAndroid Build Coastguard Worker  select their desired uid without ever running as root.
432*00c7fec1SAndroid Build Coastguard Worker  As of Android O, processes can also request capabilities directly in their .rc
433*00c7fec1SAndroid Build Coastguard Worker  files. See the "capabilities" option above.
434*00c7fec1SAndroid Build Coastguard Worker
435*00c7fec1SAndroid Build Coastguard Worker`writepid <file> [ <file>\* ]`
436*00c7fec1SAndroid Build Coastguard Worker> Write the child's pid to the given files when it forks. Meant for
437*00c7fec1SAndroid Build Coastguard Worker  cgroup/cpuset usage. If no files under /dev/cpuset/ are specified, but the
438*00c7fec1SAndroid Build Coastguard Worker  system property 'ro.cpuset.default' is set to a non-empty cpuset name (e.g.
439*00c7fec1SAndroid Build Coastguard Worker  '/foreground'), then the pid is written to file /dev/cpuset/_cpuset\_name_/tasks.
440*00c7fec1SAndroid Build Coastguard Worker  The use of this option for moving a process into a cgroup is obsolete. Please
441*00c7fec1SAndroid Build Coastguard Worker  use task_profiles option instead.
442*00c7fec1SAndroid Build Coastguard Worker
443*00c7fec1SAndroid Build Coastguard Worker
444*00c7fec1SAndroid Build Coastguard WorkerTriggers
445*00c7fec1SAndroid Build Coastguard Worker--------
446*00c7fec1SAndroid Build Coastguard WorkerTriggers are strings which can be used to match certain kinds of
447*00c7fec1SAndroid Build Coastguard Workerevents and used to cause an action to occur.
448*00c7fec1SAndroid Build Coastguard Worker
449*00c7fec1SAndroid Build Coastguard WorkerTriggers are subdivided into event triggers and property triggers.
450*00c7fec1SAndroid Build Coastguard Worker
451*00c7fec1SAndroid Build Coastguard WorkerEvent triggers are strings triggered by the 'trigger' command or by
452*00c7fec1SAndroid Build Coastguard Workerthe QueueEventTrigger() function within the init executable.  These
453*00c7fec1SAndroid Build Coastguard Workertake the form of a simple string such as 'boot' or 'late-init'.
454*00c7fec1SAndroid Build Coastguard Worker
455*00c7fec1SAndroid Build Coastguard WorkerProperty triggers are strings triggered when a named property changes
456*00c7fec1SAndroid Build Coastguard Workervalue to a given new value or when a named property changes value to
457*00c7fec1SAndroid Build Coastguard Workerany new value.  These take the form of 'property:<name>=<value>' and
458*00c7fec1SAndroid Build Coastguard Worker'property:<name>=\*' respectively.  Property triggers are additionally
459*00c7fec1SAndroid Build Coastguard Workerevaluated and triggered accordingly during the initial boot phase of
460*00c7fec1SAndroid Build Coastguard Workerinit.
461*00c7fec1SAndroid Build Coastguard Worker
462*00c7fec1SAndroid Build Coastguard WorkerAn Action can have multiple property triggers but may only have one
463*00c7fec1SAndroid Build Coastguard Workerevent trigger.
464*00c7fec1SAndroid Build Coastguard Worker
465*00c7fec1SAndroid Build Coastguard WorkerFor example:
466*00c7fec1SAndroid Build Coastguard Worker`on boot && property:a=b` defines an action that is only executed when
467*00c7fec1SAndroid Build Coastguard Workerthe 'boot' event trigger happens and the property a equals b at the moment. This
468*00c7fec1SAndroid Build Coastguard Workerwill NOT be executed when the property a transitions to value b after the `boot`
469*00c7fec1SAndroid Build Coastguard Workerevent was triggered.
470*00c7fec1SAndroid Build Coastguard Worker
471*00c7fec1SAndroid Build Coastguard Worker`on property:a=b && property:c=d` defines an action that is executed
472*00c7fec1SAndroid Build Coastguard Workerat three times:
473*00c7fec1SAndroid Build Coastguard Worker
474*00c7fec1SAndroid Build Coastguard Worker   1. During initial boot if property a=b and property c=d.
475*00c7fec1SAndroid Build Coastguard Worker   2. Any time that property a transitions to value b, while property c already equals d.
476*00c7fec1SAndroid Build Coastguard Worker   3. Any time that property c transitions to value d, while property a already equals b.
477*00c7fec1SAndroid Build Coastguard Worker
478*00c7fec1SAndroid Build Coastguard Worker
479*00c7fec1SAndroid Build Coastguard WorkerTrigger Sequence
480*00c7fec1SAndroid Build Coastguard Worker----------------
481*00c7fec1SAndroid Build Coastguard Worker
482*00c7fec1SAndroid Build Coastguard WorkerInit uses the following sequence of triggers during early boot. These are the
483*00c7fec1SAndroid Build Coastguard Workerbuilt-in triggers defined in init.cpp.
484*00c7fec1SAndroid Build Coastguard Worker
485*00c7fec1SAndroid Build Coastguard Worker   1. `early-init` - The first in the sequence, triggered after cgroups has been configured
486*00c7fec1SAndroid Build Coastguard Worker      but before ueventd's coldboot is complete.
487*00c7fec1SAndroid Build Coastguard Worker   2. `init` - Triggered after coldboot is complete.
488*00c7fec1SAndroid Build Coastguard Worker   3. `charger` - Triggered if `ro.bootmode == "charger"`.
489*00c7fec1SAndroid Build Coastguard Worker   4. `late-init` - Triggered if `ro.bootmode != "charger"`, or via healthd triggering a boot
490*00c7fec1SAndroid Build Coastguard Worker      from charging mode.
491*00c7fec1SAndroid Build Coastguard Worker
492*00c7fec1SAndroid Build Coastguard WorkerRemaining triggers are configured in `init.rc` and are not built-in. The default sequence for
493*00c7fec1SAndroid Build Coastguard Workerthese is specified under the "on late-init" event in `init.rc`. Actions internal to `init.rc`
494*00c7fec1SAndroid Build Coastguard Workerhave been omitted.
495*00c7fec1SAndroid Build Coastguard Worker
496*00c7fec1SAndroid Build Coastguard Worker   1. `early-fs` - Start vold.
497*00c7fec1SAndroid Build Coastguard Worker   2. `fs` - Vold is up. Mount partitions not marked as first-stage or latemounted.
498*00c7fec1SAndroid Build Coastguard Worker   3. `post-fs` - Configure anything dependent on early mounts.
499*00c7fec1SAndroid Build Coastguard Worker   4. `late-fs` - Mount partitions marked as latemounted.
500*00c7fec1SAndroid Build Coastguard Worker   5. `post-fs-data` - Mount and configure `/data`; set up encryption. `/metadata` is
501*00c7fec1SAndroid Build Coastguard Worker      reformatted here if it couldn't mount in first-stage init.
502*00c7fec1SAndroid Build Coastguard Worker   6. `post-fs-data-checkpointed` - Triggered when vold has completed committing a checkpoint
503*00c7fec1SAndroid Build Coastguard Worker      after an OTA update. Not triggered if checkpointing is not needed or supported.
504*00c7fec1SAndroid Build Coastguard Worker   7. `bpf-progs-loaded` - Starts things that want to start ASAP but need eBPF (incl. netd)
505*00c7fec1SAndroid Build Coastguard Worker   8. `zygote-start` - Start the zygote.
506*00c7fec1SAndroid Build Coastguard Worker   9. `early-boot` - After zygote has started.
507*00c7fec1SAndroid Build Coastguard Worker  10. `boot` - After `early-boot` actions have completed.
508*00c7fec1SAndroid Build Coastguard Worker
509*00c7fec1SAndroid Build Coastguard WorkerCommands
510*00c7fec1SAndroid Build Coastguard Worker--------
511*00c7fec1SAndroid Build Coastguard Worker
512*00c7fec1SAndroid Build Coastguard Worker`bootchart [start|stop]`
513*00c7fec1SAndroid Build Coastguard Worker> Start/stop bootcharting. These are present in the default init.rc files,
514*00c7fec1SAndroid Build Coastguard Worker  but bootcharting is only active if the file /data/bootchart/enabled exists;
515*00c7fec1SAndroid Build Coastguard Worker  otherwise bootchart start/stop are no-ops.
516*00c7fec1SAndroid Build Coastguard Worker
517*00c7fec1SAndroid Build Coastguard Worker`chmod <octal-mode> <path>`
518*00c7fec1SAndroid Build Coastguard Worker> Change file access permissions.
519*00c7fec1SAndroid Build Coastguard Worker
520*00c7fec1SAndroid Build Coastguard Worker`chown <owner> <group> <path>`
521*00c7fec1SAndroid Build Coastguard Worker> Change file owner and group.
522*00c7fec1SAndroid Build Coastguard Worker
523*00c7fec1SAndroid Build Coastguard Worker`class_start <serviceclass>`
524*00c7fec1SAndroid Build Coastguard Worker> Start all services of the specified class if they are
525*00c7fec1SAndroid Build Coastguard Worker  not already running.  See the start entry for more information on
526*00c7fec1SAndroid Build Coastguard Worker  starting services.
527*00c7fec1SAndroid Build Coastguard Worker
528*00c7fec1SAndroid Build Coastguard Worker`class_stop <serviceclass>`
529*00c7fec1SAndroid Build Coastguard Worker> Stop and disable all services of the specified class if they are
530*00c7fec1SAndroid Build Coastguard Worker  currently running.
531*00c7fec1SAndroid Build Coastguard Worker
532*00c7fec1SAndroid Build Coastguard Worker`class_reset <serviceclass>`
533*00c7fec1SAndroid Build Coastguard Worker> Stop all services of the specified class if they are
534*00c7fec1SAndroid Build Coastguard Worker  currently running, without disabling them. They can be restarted
535*00c7fec1SAndroid Build Coastguard Worker  later using `class_start`.
536*00c7fec1SAndroid Build Coastguard Worker
537*00c7fec1SAndroid Build Coastguard Worker`class_restart [--only-enabled] <serviceclass>`
538*00c7fec1SAndroid Build Coastguard Worker> Restarts all services of the specified class. If `--only-enabled` is
539*00c7fec1SAndroid Build Coastguard Worker  specified, then disabled services are skipped.
540*00c7fec1SAndroid Build Coastguard Worker
541*00c7fec1SAndroid Build Coastguard Worker`copy <src> <dst>`
542*00c7fec1SAndroid Build Coastguard Worker> Copies a file. Similar to write, but useful for binary/large
543*00c7fec1SAndroid Build Coastguard Worker  amounts of data.
544*00c7fec1SAndroid Build Coastguard Worker  Regarding to the src file, copying from symbolic link file and world-writable
545*00c7fec1SAndroid Build Coastguard Worker  or group-writable files are not allowed.
546*00c7fec1SAndroid Build Coastguard Worker  Regarding to the dst file, the default mode created is 0600 if it does not
547*00c7fec1SAndroid Build Coastguard Worker  exist. And it will be truncated if dst file is a normal regular file and
548*00c7fec1SAndroid Build Coastguard Worker  already exists.
549*00c7fec1SAndroid Build Coastguard Worker
550*00c7fec1SAndroid Build Coastguard Worker`copy_per_line <src> <dst>`
551*00c7fec1SAndroid Build Coastguard Worker> Copies a file line by line. Similar to copy, but useful for dst is a sysfs node
552*00c7fec1SAndroid Build Coastguard Worker  that doesn't handle multiple lines of data.
553*00c7fec1SAndroid Build Coastguard Worker
554*00c7fec1SAndroid Build Coastguard Worker`domainname <name>`
555*00c7fec1SAndroid Build Coastguard Worker> Set the domain name.
556*00c7fec1SAndroid Build Coastguard Worker
557*00c7fec1SAndroid Build Coastguard Worker`enable <servicename>`
558*00c7fec1SAndroid Build Coastguard Worker> Turns a disabled service into an enabled one as if the service did not
559*00c7fec1SAndroid Build Coastguard Worker  specify disabled.
560*00c7fec1SAndroid Build Coastguard Worker  If the service is supposed to be running, it will be started now.
561*00c7fec1SAndroid Build Coastguard Worker  Typically used when the bootloader sets a variable that indicates a specific
562*00c7fec1SAndroid Build Coastguard Worker  service should be started when needed. E.g.
563*00c7fec1SAndroid Build Coastguard Worker
564*00c7fec1SAndroid Build Coastguard Worker    on property:ro.boot.myfancyhardware=1
565*00c7fec1SAndroid Build Coastguard Worker        enable my_fancy_service_for_my_fancy_hardware
566*00c7fec1SAndroid Build Coastguard Worker
567*00c7fec1SAndroid Build Coastguard Worker`exec [ <seclabel> [ <user> [ <group>\* ] ] ] -- <command> [ <argument>\* ]`
568*00c7fec1SAndroid Build Coastguard Worker> Fork and execute command with the given arguments. The command starts
569*00c7fec1SAndroid Build Coastguard Worker  after "--" so that an optional security context, user, and supplementary
570*00c7fec1SAndroid Build Coastguard Worker  groups can be provided. No other commands will be run until this one
571*00c7fec1SAndroid Build Coastguard Worker  finishes. _seclabel_ can be a - to denote default. Properties are expanded
572*00c7fec1SAndroid Build Coastguard Worker  within _argument_.
573*00c7fec1SAndroid Build Coastguard Worker  Init halts executing commands until the forked process exits.
574*00c7fec1SAndroid Build Coastguard Worker
575*00c7fec1SAndroid Build Coastguard Worker`exec_background [ <seclabel> [ <user> [ <group>\* ] ] ] -- <command> [ <argument>\* ]`
576*00c7fec1SAndroid Build Coastguard Worker> Fork and execute command with the given arguments. This is handled similarly
577*00c7fec1SAndroid Build Coastguard Worker  to the `exec` command. The difference is that init does not halt executing
578*00c7fec1SAndroid Build Coastguard Worker  commands until the process exits for `exec_background`.
579*00c7fec1SAndroid Build Coastguard Worker
580*00c7fec1SAndroid Build Coastguard Worker`exec_start <service>`
581*00c7fec1SAndroid Build Coastguard Worker> Start a given service and halt the processing of additional init commands
582*00c7fec1SAndroid Build Coastguard Worker  until it returns.  The command functions similarly to the `exec` command,
583*00c7fec1SAndroid Build Coastguard Worker  but uses an existing service definition in place of the exec argument vector.
584*00c7fec1SAndroid Build Coastguard Worker
585*00c7fec1SAndroid Build Coastguard Worker`export <name> <value>`
586*00c7fec1SAndroid Build Coastguard Worker> Set the environment variable _name_ equal to _value_ in the
587*00c7fec1SAndroid Build Coastguard Worker  global environment (which will be inherited by all processes
588*00c7fec1SAndroid Build Coastguard Worker  started after this command is executed)
589*00c7fec1SAndroid Build Coastguard Worker
590*00c7fec1SAndroid Build Coastguard Worker`hostname <name>`
591*00c7fec1SAndroid Build Coastguard Worker> Set the host name.
592*00c7fec1SAndroid Build Coastguard Worker
593*00c7fec1SAndroid Build Coastguard Worker`ifup <interface>`
594*00c7fec1SAndroid Build Coastguard Worker> Bring the network interface _interface_ online.
595*00c7fec1SAndroid Build Coastguard Worker
596*00c7fec1SAndroid Build Coastguard Worker`insmod [-f] <path> [<options>]`
597*00c7fec1SAndroid Build Coastguard Worker> Install the module at _path_ with the specified options.
598*00c7fec1SAndroid Build Coastguard Worker  -f: force installation of the module even if the version of the running kernel
599*00c7fec1SAndroid Build Coastguard Worker  and the version of the kernel for which the module was compiled do not match.
600*00c7fec1SAndroid Build Coastguard Worker
601*00c7fec1SAndroid Build Coastguard Worker`interface_start <name>` \
602*00c7fec1SAndroid Build Coastguard Worker`interface_restart <name>` \
603*00c7fec1SAndroid Build Coastguard Worker`interface_stop <name>`
604*00c7fec1SAndroid Build Coastguard Worker> Find the service that provides the interface _name_ if it exists and run the `start`, `restart`,
605*00c7fec1SAndroid Build Coastguard Workeror `stop` commands on it respectively.  _name_ may be either a fully qualified HIDL name, in which
606*00c7fec1SAndroid Build Coastguard Workercase it is specified as `<interface>/<instance>`, or an AIDL name, in which case it is specified as
607*00c7fec1SAndroid Build Coastguard Worker`aidl/<interface>` for example `[email protected]::ISecureElement/eSE1` or
608*00c7fec1SAndroid Build Coastguard Worker`aidl/aidl_lazy_test_1`.
609*00c7fec1SAndroid Build Coastguard Worker
610*00c7fec1SAndroid Build Coastguard Worker> Note that these commands only act on interfaces specified by the `interface` service option, not
611*00c7fec1SAndroid Build Coastguard Workeron interfaces registered at runtime.
612*00c7fec1SAndroid Build Coastguard Worker
613*00c7fec1SAndroid Build Coastguard Worker> Example usage of these commands: \
614*00c7fec1SAndroid Build Coastguard Worker`interface_start [email protected]::ISecureElement/eSE1`
615*00c7fec1SAndroid Build Coastguard Workerwill start the HIDL Service that provides the `[email protected]` and `eSI1`
616*00c7fec1SAndroid Build Coastguard Workerinstance. \
617*00c7fec1SAndroid Build Coastguard Worker`interface_start aidl/aidl_lazy_test_1` will start the AIDL service that
618*00c7fec1SAndroid Build Coastguard Workerprovides the `aidl_lazy_test_1` interface.
619*00c7fec1SAndroid Build Coastguard Worker
620*00c7fec1SAndroid Build Coastguard Worker`load_exports <path>`
621*00c7fec1SAndroid Build Coastguard Worker> Open the file at _path_ and export global environment variables declared
622*00c7fec1SAndroid Build Coastguard Worker  there. Each line must be in the format `export <name> <value>`, as described
623*00c7fec1SAndroid Build Coastguard Worker  above.
624*00c7fec1SAndroid Build Coastguard Worker
625*00c7fec1SAndroid Build Coastguard Worker`load_system_props`
626*00c7fec1SAndroid Build Coastguard Worker> (This action is deprecated and no-op.)
627*00c7fec1SAndroid Build Coastguard Worker
628*00c7fec1SAndroid Build Coastguard Worker`load_persist_props`
629*00c7fec1SAndroid Build Coastguard Worker> Loads persistent properties when /data has been decrypted.
630*00c7fec1SAndroid Build Coastguard Worker  This is included in the default init.rc.
631*00c7fec1SAndroid Build Coastguard Worker
632*00c7fec1SAndroid Build Coastguard Worker`loglevel <level>`
633*00c7fec1SAndroid Build Coastguard Worker> Sets init's log level to the integer level, from 7 (all logging) to 0
634*00c7fec1SAndroid Build Coastguard Worker  (fatal logging only). The numeric values correspond to the kernel log
635*00c7fec1SAndroid Build Coastguard Worker  levels, but this command does not affect the kernel log level. Use the
636*00c7fec1SAndroid Build Coastguard Worker  `write` command to write to `/proc/sys/kernel/printk` to change that.
637*00c7fec1SAndroid Build Coastguard Worker  Properties are expanded within _level_.
638*00c7fec1SAndroid Build Coastguard Worker
639*00c7fec1SAndroid Build Coastguard Worker`mark_post_data`
640*00c7fec1SAndroid Build Coastguard Worker> (This action is deprecated and no-op.)
641*00c7fec1SAndroid Build Coastguard Worker
642*00c7fec1SAndroid Build Coastguard Worker`mkdir <path> [<mode>] [<owner>] [<group>] [encryption=<action>] [key=<key>]`
643*00c7fec1SAndroid Build Coastguard Worker> Create a directory at _path_, optionally with the given mode, owner, and
644*00c7fec1SAndroid Build Coastguard Worker  group. If not provided, the directory is created with permissions 755 and
645*00c7fec1SAndroid Build Coastguard Worker  owned by the root user and root group. If provided, the mode, owner and group
646*00c7fec1SAndroid Build Coastguard Worker  will be updated if the directory exists already.
647*00c7fec1SAndroid Build Coastguard Worker  If the directory does not exist, it will receive the security context from
648*00c7fec1SAndroid Build Coastguard Worker  the current SELinux policy or its parent if not specified in the policy. If
649*00c7fec1SAndroid Build Coastguard Worker  the directory exists, its security context will not be changed (even if
650*00c7fec1SAndroid Build Coastguard Worker  different from the policy).
651*00c7fec1SAndroid Build Coastguard Worker>
652*00c7fec1SAndroid Build Coastguard Worker> _action_ can be one of:
653*00c7fec1SAndroid Build Coastguard Worker>  * `None`: take no encryption action; directory will be encrypted if parent is.
654*00c7fec1SAndroid Build Coastguard Worker>  * `Require`: encrypt directory, abort boot process if encryption fails
655*00c7fec1SAndroid Build Coastguard Worker>  * `Attempt`: try to set an encryption policy, but continue if it fails
656*00c7fec1SAndroid Build Coastguard Worker>  * `DeleteIfNecessary`: recursively delete directory if necessary to set
657*00c7fec1SAndroid Build Coastguard Worker>  encryption policy.
658*00c7fec1SAndroid Build Coastguard Worker>
659*00c7fec1SAndroid Build Coastguard Worker> _key_ can be one of:
660*00c7fec1SAndroid Build Coastguard Worker>  * `ref`: use the systemwide DE key
661*00c7fec1SAndroid Build Coastguard Worker>  * `per_boot_ref`: use the key freshly generated on each boot.
662*00c7fec1SAndroid Build Coastguard Worker
663*00c7fec1SAndroid Build Coastguard Worker`mount_all [ <fstab> ] [--<option>]`
664*00c7fec1SAndroid Build Coastguard Worker> Calls fs\_mgr\_mount\_all on the given fs\_mgr-format fstab with optional
665*00c7fec1SAndroid Build Coastguard Worker  options "early" and "late".
666*00c7fec1SAndroid Build Coastguard Worker  With "--early" set, the init executable will skip mounting entries with
667*00c7fec1SAndroid Build Coastguard Worker  "latemount" flag and triggering fs encryption state event. With "--late" set,
668*00c7fec1SAndroid Build Coastguard Worker  init executable will only mount entries with "latemount" flag. By default,
669*00c7fec1SAndroid Build Coastguard Worker  no option is set, and mount\_all will process all entries in the given fstab.
670*00c7fec1SAndroid Build Coastguard Worker  If the fstab parameter is not specified, fstab.${ro.boot.fstab_suffix},
671*00c7fec1SAndroid Build Coastguard Worker  fstab.${ro.hardware} or fstab.${ro.hardware.platform} will be scanned for
672*00c7fec1SAndroid Build Coastguard Worker  under /odm/etc, /vendor/etc, or / at runtime, in that order.
673*00c7fec1SAndroid Build Coastguard Worker
674*00c7fec1SAndroid Build Coastguard Worker`mount <type> <device> <dir> [ <flag>\* ] [<options>]`
675*00c7fec1SAndroid Build Coastguard Worker> Attempt to mount the named device at the directory _dir_
676*00c7fec1SAndroid Build Coastguard Worker  _flag_s include "ro", "rw", "remount", "noatime", ...
677*00c7fec1SAndroid Build Coastguard Worker  _options_ include "barrier=1", "noauto\_da\_alloc", "discard", ... as
678*00c7fec1SAndroid Build Coastguard Worker  a comma separated string, e.g. barrier=1,noauto\_da\_alloc
679*00c7fec1SAndroid Build Coastguard Worker
680*00c7fec1SAndroid Build Coastguard Worker`perform_apex_config [--bootstrap]`
681*00c7fec1SAndroid Build Coastguard Worker> Performs tasks after APEXes are mounted. For example, creates data directories
682*00c7fec1SAndroid Build Coastguard Worker  for the mounted APEXes, parses config file(s) from them, and updates linker
683*00c7fec1SAndroid Build Coastguard Worker  configurations. Intended to be used only once when apexd notifies the mount
684*00c7fec1SAndroid Build Coastguard Worker  event by setting `apexd.status` to ready.
685*00c7fec1SAndroid Build Coastguard Worker  Use --bootstrap when invoking in the bootstrap mount namespace.
686*00c7fec1SAndroid Build Coastguard Worker
687*00c7fec1SAndroid Build Coastguard Worker`restart [--only-if-running] <service>`
688*00c7fec1SAndroid Build Coastguard Worker> Stops and restarts a running service, does nothing if the service is currently
689*00c7fec1SAndroid Build Coastguard Worker  restarting, otherwise, it just starts the service. If "--only-if-running" is
690*00c7fec1SAndroid Build Coastguard Worker  specified, the service is only restarted if it is already running.
691*00c7fec1SAndroid Build Coastguard Worker
692*00c7fec1SAndroid Build Coastguard Worker`restorecon <path> [ <path>\* ]`
693*00c7fec1SAndroid Build Coastguard Worker> Restore the file named by _path_ to the security context specified
694*00c7fec1SAndroid Build Coastguard Worker  in the file\_contexts configuration.
695*00c7fec1SAndroid Build Coastguard Worker  Not required for directories created by the init.rc as these are
696*00c7fec1SAndroid Build Coastguard Worker  automatically labeled correctly by init.
697*00c7fec1SAndroid Build Coastguard Worker
698*00c7fec1SAndroid Build Coastguard Worker`restorecon_recursive <path> [ <path>\* ]`
699*00c7fec1SAndroid Build Coastguard Worker> Recursively restore the directory tree named by _path_ to the
700*00c7fec1SAndroid Build Coastguard Worker  security contexts specified in the file\_contexts configuration.
701*00c7fec1SAndroid Build Coastguard Worker
702*00c7fec1SAndroid Build Coastguard Worker`rm <path>`
703*00c7fec1SAndroid Build Coastguard Worker> Calls unlink(2) on the given path. You might want to
704*00c7fec1SAndroid Build Coastguard Worker  use "exec -- rm ..." instead (provided the system partition is
705*00c7fec1SAndroid Build Coastguard Worker  already mounted).
706*00c7fec1SAndroid Build Coastguard Worker
707*00c7fec1SAndroid Build Coastguard Worker`rmdir <path>`
708*00c7fec1SAndroid Build Coastguard Worker> Calls rmdir(2) on the given path.
709*00c7fec1SAndroid Build Coastguard Worker
710*00c7fec1SAndroid Build Coastguard Worker`readahead <file|dir> [--fully]`
711*00c7fec1SAndroid Build Coastguard Worker> Calls readahead(2) on the file or files within given directory.
712*00c7fec1SAndroid Build Coastguard Worker  Use option --fully to read the full file content.
713*00c7fec1SAndroid Build Coastguard Worker
714*00c7fec1SAndroid Build Coastguard Worker`setprop <name> <value>`
715*00c7fec1SAndroid Build Coastguard Worker> Set system property _name_ to _value_. Properties are expanded
716*00c7fec1SAndroid Build Coastguard Worker  within _value_.
717*00c7fec1SAndroid Build Coastguard Worker
718*00c7fec1SAndroid Build Coastguard Worker`setrlimit <resource> <cur> <max>`
719*00c7fec1SAndroid Build Coastguard Worker> Set the rlimit for a resource. This applies to all processes launched after
720*00c7fec1SAndroid Build Coastguard Worker  the limit is set. It is intended to be set early in init and applied globally.
721*00c7fec1SAndroid Build Coastguard Worker  _resource_ is best specified using its text representation ('cpu', 'rtio', etc
722*00c7fec1SAndroid Build Coastguard Worker  or 'RLIM_CPU', 'RLIM_RTIO', etc). It also may be specified as the int value
723*00c7fec1SAndroid Build Coastguard Worker  that the resource enum corresponds to.
724*00c7fec1SAndroid Build Coastguard Worker  _cur_ and _max_ can be 'unlimited' or '-1' to indicate an infinite rlimit.
725*00c7fec1SAndroid Build Coastguard Worker
726*00c7fec1SAndroid Build Coastguard Worker`start <service>`
727*00c7fec1SAndroid Build Coastguard Worker> Start a service running if it is not already running.
728*00c7fec1SAndroid Build Coastguard Worker  Note that this is _not_ synchronous, and even if it were, there is
729*00c7fec1SAndroid Build Coastguard Worker  no guarantee that the operating system's scheduler will execute the
730*00c7fec1SAndroid Build Coastguard Worker  service sufficiently to guarantee anything about the service's status.
731*00c7fec1SAndroid Build Coastguard Worker  See the `exec_start` command for a synchronous version of `start`.
732*00c7fec1SAndroid Build Coastguard Worker
733*00c7fec1SAndroid Build Coastguard Worker> This creates an important consequence that if the service offers
734*00c7fec1SAndroid Build Coastguard Worker  functionality to other services, such as providing a
735*00c7fec1SAndroid Build Coastguard Worker  communication channel, simply starting this service before those
736*00c7fec1SAndroid Build Coastguard Worker  services is _not_ sufficient to guarantee that the channel has
737*00c7fec1SAndroid Build Coastguard Worker  been set up before those services ask for it.  There must be a
738*00c7fec1SAndroid Build Coastguard Worker  separate mechanism to make any such guarantees.
739*00c7fec1SAndroid Build Coastguard Worker
740*00c7fec1SAndroid Build Coastguard Worker`stop <service>`
741*00c7fec1SAndroid Build Coastguard Worker> Stop a service from running if it is currently running.
742*00c7fec1SAndroid Build Coastguard Worker
743*00c7fec1SAndroid Build Coastguard Worker`swapon_all [ <fstab> ]`
744*00c7fec1SAndroid Build Coastguard Worker> Calls fs\_mgr\_swapon\_all on the given fstab file.
745*00c7fec1SAndroid Build Coastguard Worker  If the fstab parameter is not specified, fstab.${ro.boot.fstab_suffix},
746*00c7fec1SAndroid Build Coastguard Worker  fstab.${ro.hardware} or fstab.${ro.hardware.platform} will be scanned for
747*00c7fec1SAndroid Build Coastguard Worker  under /odm/etc, /vendor/etc, or / at runtime, in that order.
748*00c7fec1SAndroid Build Coastguard Worker
749*00c7fec1SAndroid Build Coastguard Worker`swapoff <path>`
750*00c7fec1SAndroid Build Coastguard Worker> Stops swapping to the file or block device specified by path.
751*00c7fec1SAndroid Build Coastguard Worker
752*00c7fec1SAndroid Build Coastguard Worker`symlink <target> <path>`
753*00c7fec1SAndroid Build Coastguard Worker> Create a symbolic link at _path_ with the value _target_
754*00c7fec1SAndroid Build Coastguard Worker
755*00c7fec1SAndroid Build Coastguard Worker`sysclktz <minutes_west_of_gmt>`
756*00c7fec1SAndroid Build Coastguard Worker> Set the system clock base (0 if system clock ticks in GMT)
757*00c7fec1SAndroid Build Coastguard Worker
758*00c7fec1SAndroid Build Coastguard Worker`trigger <event>`
759*00c7fec1SAndroid Build Coastguard Worker> Trigger an event.  Used to queue an action from another
760*00c7fec1SAndroid Build Coastguard Worker  action.
761*00c7fec1SAndroid Build Coastguard Worker
762*00c7fec1SAndroid Build Coastguard Worker`umount <path>`
763*00c7fec1SAndroid Build Coastguard Worker> Unmount the filesystem mounted at that path.
764*00c7fec1SAndroid Build Coastguard Worker
765*00c7fec1SAndroid Build Coastguard Worker`umount_all [ <fstab> ]`
766*00c7fec1SAndroid Build Coastguard Worker> Calls fs\_mgr\_umount\_all on the given fstab file.
767*00c7fec1SAndroid Build Coastguard Worker  If the fstab parameter is not specified, fstab.${ro.boot.fstab_suffix},
768*00c7fec1SAndroid Build Coastguard Worker  fstab.${ro.hardware} or fstab.${ro.hardware.platform} will be scanned for
769*00c7fec1SAndroid Build Coastguard Worker  under /odm/etc, /vendor/etc, or / at runtime, in that order.
770*00c7fec1SAndroid Build Coastguard Worker
771*00c7fec1SAndroid Build Coastguard Worker`verity_update_state`
772*00c7fec1SAndroid Build Coastguard Worker> Internal implementation detail used to update dm-verity state and
773*00c7fec1SAndroid Build Coastguard Worker  set the partition._mount-point_.verified properties used by adb remount
774*00c7fec1SAndroid Build Coastguard Worker  because fs\_mgr can't set them directly itself. This is required since
775*00c7fec1SAndroid Build Coastguard Worker  Android 12, because CtsNativeVerifiedBootTestCases will read property
776*00c7fec1SAndroid Build Coastguard Worker  "partition.${partition}.verified.hash_alg" to check that sha1 is not used.
777*00c7fec1SAndroid Build Coastguard Worker  See https://r.android.com/1546980 for more details.
778*00c7fec1SAndroid Build Coastguard Worker
779*00c7fec1SAndroid Build Coastguard Worker`wait <path> [ <timeout> ]`
780*00c7fec1SAndroid Build Coastguard Worker> Poll for the existence of the given file and return when found,
781*00c7fec1SAndroid Build Coastguard Worker  or the timeout has been reached. If timeout is not specified it
782*00c7fec1SAndroid Build Coastguard Worker  currently defaults to five seconds. The timeout value can be
783*00c7fec1SAndroid Build Coastguard Worker  fractional seconds, specified in floating point notation.
784*00c7fec1SAndroid Build Coastguard Worker
785*00c7fec1SAndroid Build Coastguard Worker`wait_for_prop <name> <value>`
786*00c7fec1SAndroid Build Coastguard Worker> Wait for system property _name_ to be _value_. Properties are expanded
787*00c7fec1SAndroid Build Coastguard Worker  within _value_. If property _name_ is already set to _value_, continue
788*00c7fec1SAndroid Build Coastguard Worker  immediately.
789*00c7fec1SAndroid Build Coastguard Worker
790*00c7fec1SAndroid Build Coastguard Worker`write <path> <content>`
791*00c7fec1SAndroid Build Coastguard Worker> Open the file at _path_ and write a string to it with write(2).
792*00c7fec1SAndroid Build Coastguard Worker  If the file does not exist, it will be created. If it does exist,
793*00c7fec1SAndroid Build Coastguard Worker  it will be truncated. Properties are expanded within _content_.
794*00c7fec1SAndroid Build Coastguard Worker
795*00c7fec1SAndroid Build Coastguard WorkerImports
796*00c7fec1SAndroid Build Coastguard Worker-------
797*00c7fec1SAndroid Build Coastguard Worker`import <path>`
798*00c7fec1SAndroid Build Coastguard Worker> Parse an init config file, extending the current configuration.
799*00c7fec1SAndroid Build Coastguard Worker  If _path_ is a directory, each file in the directory is parsed as
800*00c7fec1SAndroid Build Coastguard Worker  a config file. It is not recursive, nested directories will
801*00c7fec1SAndroid Build Coastguard Worker  not be parsed.
802*00c7fec1SAndroid Build Coastguard Worker
803*00c7fec1SAndroid Build Coastguard WorkerThe import keyword is not a command, but rather its own section,
804*00c7fec1SAndroid Build Coastguard Workermeaning that it does not happen as part of an Action, but rather,
805*00c7fec1SAndroid Build Coastguard Workerimports are handled as a file is being parsed and follow the below logic.
806*00c7fec1SAndroid Build Coastguard Worker
807*00c7fec1SAndroid Build Coastguard WorkerThere are only three times where the init executable imports .rc files:
808*00c7fec1SAndroid Build Coastguard Worker
809*00c7fec1SAndroid Build Coastguard Worker   1. When it imports `/system/etc/init/hw/init.rc` or the script indicated by the property
810*00c7fec1SAndroid Build Coastguard Worker      `ro.boot.init_rc` during initial boot.
811*00c7fec1SAndroid Build Coastguard Worker   2. When it imports `/{system,system_ext,vendor,odm,product}/etc/init/` immediately after
812*00c7fec1SAndroid Build Coastguard Worker      importing `/system/etc/init/hw/init.rc`.
813*00c7fec1SAndroid Build Coastguard Worker   3. (Deprecated) When it imports /{system,vendor,odm}/etc/init/ or .rc files
814*00c7fec1SAndroid Build Coastguard Worker      at specified paths during mount_all, not allowed for devices launching
815*00c7fec1SAndroid Build Coastguard Worker      after Q.
816*00c7fec1SAndroid Build Coastguard Worker
817*00c7fec1SAndroid Build Coastguard WorkerThe order that files are imported is a bit complex for legacy reasons.  The below is guaranteed:
818*00c7fec1SAndroid Build Coastguard Worker
819*00c7fec1SAndroid Build Coastguard Worker1. `/system/etc/init/hw/init.rc` is parsed then recursively each of its imports are
820*00c7fec1SAndroid Build Coastguard Worker   parsed.
821*00c7fec1SAndroid Build Coastguard Worker2. The contents of `/system/etc/init/` are alphabetized and parsed sequentially, with imports
822*00c7fec1SAndroid Build Coastguard Worker   happening recursively after each file is parsed.
823*00c7fec1SAndroid Build Coastguard Worker3. Step 2 is repeated for `/system_ext/etc/init`, `/vendor/etc/init`, `/odm/etc/init`,
824*00c7fec1SAndroid Build Coastguard Worker   `/product/etc/init`
825*00c7fec1SAndroid Build Coastguard Worker
826*00c7fec1SAndroid Build Coastguard WorkerThe below pseudocode may explain this more clearly:
827*00c7fec1SAndroid Build Coastguard Worker
828*00c7fec1SAndroid Build Coastguard Worker    fn Import(file)
829*00c7fec1SAndroid Build Coastguard Worker      Parse(file)
830*00c7fec1SAndroid Build Coastguard Worker      for (import : file.imports)
831*00c7fec1SAndroid Build Coastguard Worker        Import(import)
832*00c7fec1SAndroid Build Coastguard Worker
833*00c7fec1SAndroid Build Coastguard Worker    Import(/system/etc/init/hw/init.rc)
834*00c7fec1SAndroid Build Coastguard Worker    Directories = [/system/etc/init, /system_ext/etc/init, /vendor/etc/init, /odm/etc/init, /product/etc/init]
835*00c7fec1SAndroid Build Coastguard Worker    for (directory : Directories)
836*00c7fec1SAndroid Build Coastguard Worker      files = <Alphabetical order of directory's contents>
837*00c7fec1SAndroid Build Coastguard Worker      for (file : files)
838*00c7fec1SAndroid Build Coastguard Worker        Import(file)
839*00c7fec1SAndroid Build Coastguard Worker
840*00c7fec1SAndroid Build Coastguard WorkerActions are executed in the order that they are parsed.  For example the `post-fs-data` action(s)
841*00c7fec1SAndroid Build Coastguard Workerin `/system/etc/init/hw/init.rc` are always the first `post-fs-data` action(s) to be executed in
842*00c7fec1SAndroid Build Coastguard Workerorder of how they appear in that file.  Then the `post-fs-data` actions of the imports of
843*00c7fec1SAndroid Build Coastguard Worker`/system/etc/init/hw/init.rc` in the order that they're imported, etc.
844*00c7fec1SAndroid Build Coastguard Worker
845*00c7fec1SAndroid Build Coastguard WorkerProperties
846*00c7fec1SAndroid Build Coastguard Worker----------
847*00c7fec1SAndroid Build Coastguard WorkerInit provides state information with the following properties.
848*00c7fec1SAndroid Build Coastguard Worker
849*00c7fec1SAndroid Build Coastguard Worker`init.svc.<name>`
850*00c7fec1SAndroid Build Coastguard Worker> State of a named service ("stopped", "stopping", "running", "restarting")
851*00c7fec1SAndroid Build Coastguard Worker
852*00c7fec1SAndroid Build Coastguard Worker`dev.mnt.dev.<mount_point>`, `dev.mnt.blk.<mount_point>`, `dev.mnt.rootdisk.<mount_point>`
853*00c7fec1SAndroid Build Coastguard Worker> Block device base name associated with a *mount_point*.
854*00c7fec1SAndroid Build Coastguard Worker  The *mount_point* has / replaced by . and if referencing the root mount point
855*00c7fec1SAndroid Build Coastguard Worker  "/", it will use "/root".
856*00c7fec1SAndroid Build Coastguard Worker  `dev.mnt.dev.<mount_point>` indicates a block device attached to filesystems.
857*00c7fec1SAndroid Build Coastguard Worker    (e.g., dm-N or sdaN/mmcblk0pN to access `/sys/fs/ext4/${dev.mnt.dev.<mount_point>}/`)
858*00c7fec1SAndroid Build Coastguard Worker
859*00c7fec1SAndroid Build Coastguard Worker  `dev.mnt.blk.<mount_point>` indicates the disk partition to the above block device.
860*00c7fec1SAndroid Build Coastguard Worker    (e.g., sdaN / mmcblk0pN to access `/sys/class/block/${dev.mnt.blk.<mount_point>}/`)
861*00c7fec1SAndroid Build Coastguard Worker
862*00c7fec1SAndroid Build Coastguard Worker  `dev.mnt.rootdisk.<mount_point>` indicates the root disk to contain the above disk partition.
863*00c7fec1SAndroid Build Coastguard Worker    (e.g., sda / mmcblk0 to access `/sys/class/block/${dev.mnt.rootdisk.<mount_point>}/queue`)
864*00c7fec1SAndroid Build Coastguard Worker
865*00c7fec1SAndroid Build Coastguard WorkerInit responds to properties that begin with `ctl.`.  These properties take the format of
866*00c7fec1SAndroid Build Coastguard Worker`ctl.[<target>_]<command>` and the _value_ of the system property is used as a parameter.  The
867*00c7fec1SAndroid Build Coastguard Worker_target_ is optional and specifies the service option that _value_ is meant to match with.  There is
868*00c7fec1SAndroid Build Coastguard Workeronly one option for _target_, `interface` which indicates that _value_ will refer to an interface
869*00c7fec1SAndroid Build Coastguard Workerthat a service provides and not the service name itself.
870*00c7fec1SAndroid Build Coastguard Worker
871*00c7fec1SAndroid Build Coastguard WorkerFor example:
872*00c7fec1SAndroid Build Coastguard Worker
873*00c7fec1SAndroid Build Coastguard Worker`SetProperty("ctl.start", "logd")` will run the `start` command on `logd`.
874*00c7fec1SAndroid Build Coastguard Worker
875*00c7fec1SAndroid Build Coastguard Worker`SetProperty("ctl.interface_start", "aidl/aidl_lazy_test_1")` will run the `start` command on the
876*00c7fec1SAndroid Build Coastguard Workerservice that exposes the `aidl aidl_lazy_test_1` interface.
877*00c7fec1SAndroid Build Coastguard Worker
878*00c7fec1SAndroid Build Coastguard WorkerNote that these
879*00c7fec1SAndroid Build Coastguard Workerproperties are only settable; they will have no value when read.
880*00c7fec1SAndroid Build Coastguard Worker
881*00c7fec1SAndroid Build Coastguard WorkerThe _commands_ are listed below.
882*00c7fec1SAndroid Build Coastguard Worker
883*00c7fec1SAndroid Build Coastguard Worker`start` \
884*00c7fec1SAndroid Build Coastguard Worker`restart` \
885*00c7fec1SAndroid Build Coastguard Worker`stop` \
886*00c7fec1SAndroid Build Coastguard WorkerThese are equivalent to using the `start`, `restart`, and `stop` commands on the service specified
887*00c7fec1SAndroid Build Coastguard Workerby the _value_ of the property.
888*00c7fec1SAndroid Build Coastguard Worker
889*00c7fec1SAndroid Build Coastguard Worker`oneshot_on` and `oneshot_off` will turn on or off the _oneshot_
890*00c7fec1SAndroid Build Coastguard Workerflag for the service specified by the _value_ of the property.  This is
891*00c7fec1SAndroid Build Coastguard Workerparticularly intended for services that are conditionally lazy HALs.  When
892*00c7fec1SAndroid Build Coastguard Workerthey are lazy HALs, oneshot must be on, otherwise oneshot should be off.
893*00c7fec1SAndroid Build Coastguard Worker
894*00c7fec1SAndroid Build Coastguard Worker`sigstop_on` and `sigstop_off` will turn on or off the _sigstop_ feature for the service
895*00c7fec1SAndroid Build Coastguard Workerspecified by the _value_ of the property.  See the _Debugging init_ section below for more details
896*00c7fec1SAndroid Build Coastguard Workerabout this feature.
897*00c7fec1SAndroid Build Coastguard Worker
898*00c7fec1SAndroid Build Coastguard WorkerBoot timing
899*00c7fec1SAndroid Build Coastguard Worker-----------
900*00c7fec1SAndroid Build Coastguard WorkerInit records some boot timing information in system properties.
901*00c7fec1SAndroid Build Coastguard Worker
902*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.init`
903*00c7fec1SAndroid Build Coastguard Worker> Time after boot in ns (via the CLOCK\_BOOTTIME clock) at which the first
904*00c7fec1SAndroid Build Coastguard Worker  stage of init started.
905*00c7fec1SAndroid Build Coastguard Worker
906*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.init.first_stage`
907*00c7fec1SAndroid Build Coastguard Worker> How long in ns it took to run first stage.
908*00c7fec1SAndroid Build Coastguard Worker
909*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.init.selinux`
910*00c7fec1SAndroid Build Coastguard Worker> How long in ns it took to run SELinux stage.
911*00c7fec1SAndroid Build Coastguard Worker
912*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.init.modules`
913*00c7fec1SAndroid Build Coastguard Worker> How long in ms it took to load kernel modules.
914*00c7fec1SAndroid Build Coastguard Worker
915*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.init.cold_boot_wait`
916*00c7fec1SAndroid Build Coastguard Worker> How long init waited for ueventd's coldboot phase to end.
917*00c7fec1SAndroid Build Coastguard Worker
918*00c7fec1SAndroid Build Coastguard Worker`ro.boottime.<service-name>`
919*00c7fec1SAndroid Build Coastguard Worker> Time after boot in ns (via the CLOCK\_BOOTTIME clock) that the service was
920*00c7fec1SAndroid Build Coastguard Worker  first started.
921*00c7fec1SAndroid Build Coastguard Worker
922*00c7fec1SAndroid Build Coastguard Worker
923*00c7fec1SAndroid Build Coastguard WorkerBootcharting
924*00c7fec1SAndroid Build Coastguard Worker------------
925*00c7fec1SAndroid Build Coastguard WorkerThis version of init contains code to perform "bootcharting": generating log
926*00c7fec1SAndroid Build Coastguard Workerfiles that can be later processed by the tools provided by <http://www.bootchart.org/>.
927*00c7fec1SAndroid Build Coastguard Worker
928*00c7fec1SAndroid Build Coastguard WorkerOn the emulator, use the -bootchart _timeout_ option to boot with bootcharting
929*00c7fec1SAndroid Build Coastguard Workeractivated for _timeout_ seconds.
930*00c7fec1SAndroid Build Coastguard Worker
931*00c7fec1SAndroid Build Coastguard WorkerOn a device:
932*00c7fec1SAndroid Build Coastguard Worker
933*00c7fec1SAndroid Build Coastguard Worker    adb shell 'touch /data/bootchart/enabled'
934*00c7fec1SAndroid Build Coastguard Worker
935*00c7fec1SAndroid Build Coastguard WorkerDon't forget to delete this file when you're done collecting data!
936*00c7fec1SAndroid Build Coastguard Worker
937*00c7fec1SAndroid Build Coastguard WorkerThe log files are written to /data/bootchart/. A script is provided to
938*00c7fec1SAndroid Build Coastguard Workerretrieve them and create a bootchart.tgz file that can be used with the
939*00c7fec1SAndroid Build Coastguard Workerbootchart command-line utility:
940*00c7fec1SAndroid Build Coastguard Worker
941*00c7fec1SAndroid Build Coastguard Worker    sudo apt-get install pybootchartgui
942*00c7fec1SAndroid Build Coastguard Worker    # grab-bootchart.sh uses $ANDROID_SERIAL.
943*00c7fec1SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
944*00c7fec1SAndroid Build Coastguard Worker
945*00c7fec1SAndroid Build Coastguard WorkerOne thing to watch for is that the bootchart will show init as if it started
946*00c7fec1SAndroid Build Coastguard Workerrunning at 0s. You'll have to look at dmesg to work out when the kernel
947*00c7fec1SAndroid Build Coastguard Workeractually started init.
948*00c7fec1SAndroid Build Coastguard Worker
949*00c7fec1SAndroid Build Coastguard Worker
950*00c7fec1SAndroid Build Coastguard WorkerComparing two bootcharts
951*00c7fec1SAndroid Build Coastguard Worker------------------------
952*00c7fec1SAndroid Build Coastguard WorkerA handy script named compare-bootcharts.py can be used to compare the
953*00c7fec1SAndroid Build Coastguard Workerstart/end time of selected processes. The aforementioned grab-bootchart.sh
954*00c7fec1SAndroid Build Coastguard Workerwill leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart.
955*00c7fec1SAndroid Build Coastguard WorkerIf two such tarballs are preserved on the host machine under different
956*00c7fec1SAndroid Build Coastguard Workerdirectories, the script can list the timestamps differences. For example:
957*00c7fec1SAndroid Build Coastguard Worker
958*00c7fec1SAndroid Build Coastguard WorkerUsage: system/core/init/compare-bootcharts.py _base-bootchart-dir_ _exp-bootchart-dir_
959*00c7fec1SAndroid Build Coastguard Worker
960*00c7fec1SAndroid Build Coastguard Worker    process: baseline experiment (delta) - Unit is ms (a jiffy is 10 ms on the system)
961*00c7fec1SAndroid Build Coastguard Worker    ------------------------------------
962*00c7fec1SAndroid Build Coastguard Worker    /init: 50 40 (-10)
963*00c7fec1SAndroid Build Coastguard Worker    /system/bin/surfaceflinger: 4320 4470 (+150)
964*00c7fec1SAndroid Build Coastguard Worker    /system/bin/bootanimation: 6980 6990 (+10)
965*00c7fec1SAndroid Build Coastguard Worker    zygote64: 10410 10640 (+230)
966*00c7fec1SAndroid Build Coastguard Worker    zygote: 10410 10640 (+230)
967*00c7fec1SAndroid Build Coastguard Worker    system_server: 15350 15150 (-200)
968*00c7fec1SAndroid Build Coastguard Worker    bootanimation ends at: 33790 31230 (-2560)
969*00c7fec1SAndroid Build Coastguard Worker
970*00c7fec1SAndroid Build Coastguard Worker
971*00c7fec1SAndroid Build Coastguard WorkerSystrace
972*00c7fec1SAndroid Build Coastguard Worker--------
973*00c7fec1SAndroid Build Coastguard WorkerSystrace (<http://developer.android.com/tools/help/systrace.html>) can be
974*00c7fec1SAndroid Build Coastguard Workerused for obtaining performance analysis reports during boot
975*00c7fec1SAndroid Build Coastguard Workertime on userdebug or eng builds.
976*00c7fec1SAndroid Build Coastguard Worker
977*00c7fec1SAndroid Build Coastguard WorkerHere is an example of trace events of "wm" and "am" categories:
978*00c7fec1SAndroid Build Coastguard Worker
979*00c7fec1SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py \
980*00c7fec1SAndroid Build Coastguard Worker          wm am --boot
981*00c7fec1SAndroid Build Coastguard Worker
982*00c7fec1SAndroid Build Coastguard WorkerThis command will cause the device to reboot. After the device is rebooted and
983*00c7fec1SAndroid Build Coastguard Workerthe boot sequence has finished, the trace report is obtained from the device
984*00c7fec1SAndroid Build Coastguard Workerand written as trace.html on the host by hitting Ctrl+C.
985*00c7fec1SAndroid Build Coastguard Worker
986*00c7fec1SAndroid Build Coastguard WorkerLimitation: recording trace events is started after persistent properties are loaded, so
987*00c7fec1SAndroid Build Coastguard Workerthe trace events that are emitted before that are not recorded. Several
988*00c7fec1SAndroid Build Coastguard Workerservices such as vold, surfaceflinger, and servicemanager are affected by this
989*00c7fec1SAndroid Build Coastguard Workerlimitation since they are started before persistent properties are loaded.
990*00c7fec1SAndroid Build Coastguard WorkerZygote initialization and the processes that are forked from the zygote are not
991*00c7fec1SAndroid Build Coastguard Workeraffected.
992*00c7fec1SAndroid Build Coastguard Worker
993*00c7fec1SAndroid Build Coastguard Worker
994*00c7fec1SAndroid Build Coastguard WorkerDebugging init
995*00c7fec1SAndroid Build Coastguard Worker--------------
996*00c7fec1SAndroid Build Coastguard WorkerWhen a service starts from init, it may fail to `execv()` the service. This is not typical, and may
997*00c7fec1SAndroid Build Coastguard Workerpoint to an error happening in the linker as the new service is started. The linker in Android
998*00c7fec1SAndroid Build Coastguard Workerprints its logs to `logd` and `stderr`, so they are visible in `logcat`. If the error is encountered
999*00c7fec1SAndroid Build Coastguard Workerbefore it is possible to access `logcat`, the `stdio_to_kmsg` service option may be used to direct
1000*00c7fec1SAndroid Build Coastguard Workerthe logs that the linker prints to `stderr` to `kmsg`, where they can be read via a serial port.
1001*00c7fec1SAndroid Build Coastguard Worker
1002*00c7fec1SAndroid Build Coastguard WorkerLaunching init services without init is not recommended as init sets up a significant amount of
1003*00c7fec1SAndroid Build Coastguard Workerenvironment (user, groups, security label, capabilities, etc) that is hard to replicate manually.
1004*00c7fec1SAndroid Build Coastguard Worker
1005*00c7fec1SAndroid Build Coastguard WorkerIf it is required to debug a service from its very start, the `sigstop` service option is added.
1006*00c7fec1SAndroid Build Coastguard WorkerThis option will send SIGSTOP to a service immediately before calling exec. This gives a window
1007*00c7fec1SAndroid Build Coastguard Workerwhere developers can attach a debugger, strace, etc before continuing the service with SIGCONT.
1008*00c7fec1SAndroid Build Coastguard Worker
1009*00c7fec1SAndroid Build Coastguard WorkerThis flag can also be dynamically controlled via the ctl.sigstop_on and ctl.sigstop_off properties.
1010*00c7fec1SAndroid Build Coastguard Worker
1011*00c7fec1SAndroid Build Coastguard WorkerBelow is an example of dynamically debugging logd via the above:
1012*00c7fec1SAndroid Build Coastguard Worker
1013*00c7fec1SAndroid Build Coastguard Worker    stop logd
1014*00c7fec1SAndroid Build Coastguard Worker    setprop ctl.sigstop_on logd
1015*00c7fec1SAndroid Build Coastguard Worker    start logd
1016*00c7fec1SAndroid Build Coastguard Worker    ps -e | grep logd
1017*00c7fec1SAndroid Build Coastguard Worker    > logd          4343     1   18156   1684 do_signal_stop 538280 T init
1018*00c7fec1SAndroid Build Coastguard Worker    gdbclient.py -p 4343
1019*00c7fec1SAndroid Build Coastguard Worker    b main
1020*00c7fec1SAndroid Build Coastguard Worker    c
1021*00c7fec1SAndroid Build Coastguard Worker    c
1022*00c7fec1SAndroid Build Coastguard Worker    c
1023*00c7fec1SAndroid Build Coastguard Worker    > Breakpoint 1, main (argc=1, argv=0x7ff8c9a488) at system/core/logd/main.cpp:427
1024*00c7fec1SAndroid Build Coastguard Worker
1025*00c7fec1SAndroid Build Coastguard WorkerBelow is an example of doing the same but with strace
1026*00c7fec1SAndroid Build Coastguard Worker
1027*00c7fec1SAndroid Build Coastguard Worker    stop logd
1028*00c7fec1SAndroid Build Coastguard Worker    setprop ctl.sigstop_on logd
1029*00c7fec1SAndroid Build Coastguard Worker    start logd
1030*00c7fec1SAndroid Build Coastguard Worker    ps -e | grep logd
1031*00c7fec1SAndroid Build Coastguard Worker    > logd          4343     1   18156   1684 do_signal_stop 538280 T init
1032*00c7fec1SAndroid Build Coastguard Worker    strace -p 4343
1033*00c7fec1SAndroid Build Coastguard Worker
1034*00c7fec1SAndroid Build Coastguard Worker    (From a different shell)
1035*00c7fec1SAndroid Build Coastguard Worker    kill -SIGCONT 4343
1036*00c7fec1SAndroid Build Coastguard Worker
1037*00c7fec1SAndroid Build Coastguard Worker    > strace runs
1038*00c7fec1SAndroid Build Coastguard Worker
1039*00c7fec1SAndroid Build Coastguard WorkerHost Init Script Verification
1040*00c7fec1SAndroid Build Coastguard Worker-----------------------------
1041*00c7fec1SAndroid Build Coastguard Worker
1042*00c7fec1SAndroid Build Coastguard WorkerInit scripts are checked for correctness during build time. Specifically the below is checked.
1043*00c7fec1SAndroid Build Coastguard Worker
1044*00c7fec1SAndroid Build Coastguard Worker1) Well formatted action, service and import sections, e.g. no actions without a preceding 'on'
1045*00c7fec1SAndroid Build Coastguard Workerline, and no extraneous lines after an 'import' statement.
1046*00c7fec1SAndroid Build Coastguard Worker2) All commands map to a valid keyword and the argument count is within the correct range.
1047*00c7fec1SAndroid Build Coastguard Worker3) All service options are valid. This is stricter than how commands are checked as the service
1048*00c7fec1SAndroid Build Coastguard Workeroptions' arguments are fully parsed, e.g. UIDs and GIDs must resolve.
1049*00c7fec1SAndroid Build Coastguard Worker
1050*00c7fec1SAndroid Build Coastguard WorkerThere are other parts of init scripts that are only parsed at runtime and therefore not checked
1051*00c7fec1SAndroid Build Coastguard Workerduring build time, among them are the below.
1052*00c7fec1SAndroid Build Coastguard Worker
1053*00c7fec1SAndroid Build Coastguard Worker1) The validity of the arguments of commands, e.g. no checking if file paths actually exist, if
1054*00c7fec1SAndroid Build Coastguard WorkerSELinux would permit the operation, or if the UIDs and GIDs resolve.
1055*00c7fec1SAndroid Build Coastguard Worker2) No checking if a service exists or has a valid SELinux domain defined
1056*00c7fec1SAndroid Build Coastguard Worker3) No checking if a service has not been previously defined in a different init script.
1057*00c7fec1SAndroid Build Coastguard Worker
1058*00c7fec1SAndroid Build Coastguard WorkerEarly Init Boot Sequence
1059*00c7fec1SAndroid Build Coastguard Worker------------------------
1060*00c7fec1SAndroid Build Coastguard WorkerThe early init boot sequence is broken up into three stages: first stage init, SELinux setup, and
1061*00c7fec1SAndroid Build Coastguard Workersecond stage init.
1062*00c7fec1SAndroid Build Coastguard Worker
1063*00c7fec1SAndroid Build Coastguard WorkerFirst stage init is responsible for setting up the bare minimum requirements to load the rest of the
1064*00c7fec1SAndroid Build Coastguard Workersystem. Specifically this includes mounting /dev, /proc, mounting 'early mount' partitions (which
1065*00c7fec1SAndroid Build Coastguard Workerneeds to include all partitions that contain system code, for example system and vendor), and moving
1066*00c7fec1SAndroid Build Coastguard Workerthe system.img mount to / for devices with a ramdisk.
1067*00c7fec1SAndroid Build Coastguard Worker
1068*00c7fec1SAndroid Build Coastguard WorkerNote that in Android Q, system.img always contains TARGET_ROOT_OUT and always is mounted at / by the
1069*00c7fec1SAndroid Build Coastguard Workertime first stage init finishes. Android Q will also require dynamic partitions and therefore will
1070*00c7fec1SAndroid Build Coastguard Workerrequire using a ramdisk to boot Android. The recovery ramdisk can be used to boot to Android instead
1071*00c7fec1SAndroid Build Coastguard Workerof a dedicated ramdisk as well.
1072*00c7fec1SAndroid Build Coastguard Worker
1073*00c7fec1SAndroid Build Coastguard WorkerFirst stage init has three variations depending on the device configuration:
1074*00c7fec1SAndroid Build Coastguard Worker1) For system-as-root devices, first stage init is part of /system/bin/init and a symlink at /init
1075*00c7fec1SAndroid Build Coastguard Workerpoints to /system/bin/init for backwards compatibility. These devices do not need to do anything to
1076*00c7fec1SAndroid Build Coastguard Workermount system.img, since it is by definition already mounted as the rootfs by the kernel.
1077*00c7fec1SAndroid Build Coastguard Worker
1078*00c7fec1SAndroid Build Coastguard Worker2) For devices with a ramdisk, first stage init is a static executable located at /init. These
1079*00c7fec1SAndroid Build Coastguard Workerdevices mount system.img as /system then perform a switch root operation to move the mount at
1080*00c7fec1SAndroid Build Coastguard Worker/system to /. The contents of the ramdisk are freed after mounting has completed.
1081*00c7fec1SAndroid Build Coastguard Worker
1082*00c7fec1SAndroid Build Coastguard Worker3) For devices that use recovery as a ramdisk, first stage init it contained within the shared init
1083*00c7fec1SAndroid Build Coastguard Workerlocated at /init within the recovery ramdisk. These devices first switch root to
1084*00c7fec1SAndroid Build Coastguard Worker/first_stage_ramdisk to remove the recovery components from the environment, then proceed the same
1085*00c7fec1SAndroid Build Coastguard Workeras 2). Note that the decision to boot normally into Android instead of booting
1086*00c7fec1SAndroid Build Coastguard Workerinto recovery mode is made if androidboot.force_normal_boot=1 is present in the
1087*00c7fec1SAndroid Build Coastguard Workerkernel commandline, or in bootconfig with Android S and later.
1088*00c7fec1SAndroid Build Coastguard Worker
1089*00c7fec1SAndroid Build Coastguard WorkerOnce first stage init finishes it execs /system/bin/init with the "selinux_setup" argument. This
1090*00c7fec1SAndroid Build Coastguard Workerphase is where SELinux is optionally compiled and loaded onto the system. selinux.cpp contains more
1091*00c7fec1SAndroid Build Coastguard Workerinformation on the specifics of this process.
1092*00c7fec1SAndroid Build Coastguard Worker
1093*00c7fec1SAndroid Build Coastguard WorkerLastly once that phase finishes, it execs /system/bin/init again with the "second_stage"
1094*00c7fec1SAndroid Build Coastguard Workerargument. At this point the main phase of init runs and continues the boot process via the init.rc
1095*00c7fec1SAndroid Build Coastguard Workerscripts.
1096