blob: 721ba93925e66462e7fdf02661143e602da6e67e [file] [log] [blame]
Inseob Kimdc2af862021-02-17 15:51:56 +09001# Copyright (C) 2021 The Android Open Source Project
2#
3# init.rc for microdroid. This contains a minimal script plus basic service definitions (e.g. apexd)
4# needed for microdroid to run.
5# TODO(b/179340780): support APEX init scripts
6#
7# IMPORTANT: Do not create world writable files or directories.
8# This is a common source of Android security bugs.
9#
10
11import /init.environ.rc
12
13# Cgroups are mounted right before early-init using list from /etc/cgroups.json
14on early-init
Inseob Kimdc2af862021-02-17 15:51:56 +090015
Jooyung Hanc36b18a2021-04-20 03:33:36 +090016 # TODO(b/185991357) eliminate bootstrap mount namespace
17 # Set up linker config subdirectories based on mount namespaces
18 mkdir /linkerconfig/bootstrap 0755
19 mkdir /linkerconfig/default 0755
20
21 # Generate ld.config.txt for early executed processes
22 exec -- /system/bin/bootstrap/linkerconfig --target /linkerconfig/bootstrap
23 chmod 644 /linkerconfig/bootstrap/ld.config.txt
24 copy /linkerconfig/bootstrap/ld.config.txt /linkerconfig/default/ld.config.txt
25 chmod 644 /linkerconfig/default/ld.config.txt
26
27 # Mount bootstrap linker configuration as current
28 mount none /linkerconfig/bootstrap /linkerconfig bind rec
29
30 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090031
Inseob Kimdc2af862021-02-17 15:51:56 +090032 # Run apexd-bootstrap so that APEXes that provide critical libraries
33 # become available. Note that this is executed as exec_start to ensure that
34 # the libraries are available to the processes started after this statement.
35 exec_start apexd-bootstrap
36
Inseob Kim870e76b2021-02-25 17:38:32 +090037 # Generate linker config based on apex mounted in bootstrap namespace
38 update_linker_config
39
Inseob Kimdc2af862021-02-17 15:51:56 +090040on init
41 # Mount binderfs
42 mkdir /dev/binderfs
43 mount binder binder /dev/binderfs stats=global
44 chmod 0755 /dev/binderfs
45
46 symlink /dev/binderfs/binder /dev/binder
47 symlink /dev/binderfs/hwbinder /dev/hwbinder
48 symlink /dev/binderfs/vndbinder /dev/vndbinder
49
50 chmod 0666 /dev/binderfs/hwbinder
51 chmod 0666 /dev/binderfs/binder
52 chmod 0666 /dev/binderfs/vndbinder
53
54 # Start logd before any other services run to ensure we capture all of their logs.
55 start logd
56
57 start servicemanager
58
59on load_persist_props_action
60 start logd
61 start logd-reinit
62
63# Mount filesystems and start core system services.
64on late-init
65 trigger early-fs
66
67 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
68 # '--early' can be specified to skip entries with 'latemount'.
69 # /system and /vendor must be mounted by the end of the fs stage,
70 # while /data is optional.
71 trigger fs
72 trigger post-fs
73
74 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
75 # to only mount entries with 'latemount'. This is needed if '--early' is
76 # specified in the previous mount_all command on the fs stage.
77 # With /system mounted and properties form /system + /factory available,
78 # some services can be started.
79 trigger late-fs
80
Inseob Kimafd9dc02021-04-23 14:47:44 +090081 trigger post-fs-data
82
Inseob Kimdc2af862021-02-17 15:51:56 +090083 # Load persist properties and override properties (if enabled) from /data.
84 trigger load_persist_props_action
85
86 # Should be before netd, but after apex, properties and logging is available.
87 trigger load_bpf_programs
88
89 # Now we can start zygote for devices with file based encryption
90 trigger zygote-start
91
92 # Remove a file to wake up anything waiting for firmware.
93 trigger firmware_mounts_complete
94
95 trigger early-boot
96 trigger boot
97
98on post-fs
99 # Once everything is setup, no need to modify /.
100 # The bind+remount combination allows this to work in containers.
101 mount rootfs rootfs / remount bind ro nodev
102
Jooyung Hanc36b18a2021-04-20 03:33:36 +0900103 enter_default_mount_ns
104
105 # Start apexd in the VM mode to avoid unnecessary overhead of session management.
106 exec - root system -- /system/bin/apexd --vm
107
108 perform_apex_config
Inseob Kimdc2af862021-02-17 15:51:56 +0900109
Jooyung Han017916b2021-04-20 03:57:19 +0900110 exec_start derive_sdk
111
Inseob Kimdc2af862021-02-17 15:51:56 +0900112 start adbd
113
Inseob Kimafd9dc02021-04-23 14:47:44 +0900114on post-fs-data
115 mount_all /vendor/etc/fstab --late
116 restorecon /data
117
Inseob Kimdc2af862021-02-17 15:51:56 +0900118service ueventd /system/bin/ueventd
119 class core
120 critical
121 seclabel u:r:ueventd:s0
122 shutdown critical
123
124service console /system/bin/sh
125 class core
126 console
127 disabled
128 user shell
129 group shell log readproc
130 seclabel u:r:shell:s0
131 setenv HOSTNAME console
132
Inseob Kimdc2af862021-02-17 15:51:56 +0900133on fs
134 write /dev/event-log-tags "# content owned by logd
135"
136 chown logd logd /dev/event-log-tags
137 chmod 0644 /dev/event-log-tags
138
139on property:sys.boot_completed=1
140 start logd-auditctl
141