blob: 74da023cd4348015008fba3655b0b5e181d43cf6 [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 Kimde6b6892021-05-26 12:06:59 +090015 # set RLIMIT_NICE to allow priorities from 19 to -20
16 setrlimit nice 40 40
17
Jooyung Hanc36b18a2021-04-20 03:33:36 +090018 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090019
Jiyong Parkbb4a9872021-09-06 15:59:21 +090020 mkdir /mnt/apk 0755 system system
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090021 # Microdroid_manager starts apkdmverity/zipfuse/apexd
Jooyung Hane706c9f2021-07-29 17:21:20 +090022 start microdroid_manager
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090023
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090024 # Wait for apexd to finish activating APEXes before starting more processes.
25 wait_for_prop apexd.status activated
Jooyung Han16186d92021-06-01 17:53:28 +090026 perform_apex_config
Inseob Kim870e76b2021-02-25 17:38:32 +090027
Jiyong Parkbb4a9872021-09-06 15:59:21 +090028 # Notify to microdroid_manager that perform_apex_config is done.
29 # Microdroid_manager shouldn't execute payload before this, because app
30 # payloads are not designed to run with bootstrap bionic
31 setprop apex_config.done true
Jiyong Park9abfc1f2021-05-17 21:57:24 +090032
Jiyong Parke7407e22021-10-18 15:51:59 +090033 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
34
Inseob Kimdc2af862021-02-17 15:51:56 +090035on init
36 # Mount binderfs
37 mkdir /dev/binderfs
38 mount binder binder /dev/binderfs stats=global
39 chmod 0755 /dev/binderfs
40
41 symlink /dev/binderfs/binder /dev/binder
42 symlink /dev/binderfs/hwbinder /dev/hwbinder
43 symlink /dev/binderfs/vndbinder /dev/vndbinder
44
45 chmod 0666 /dev/binderfs/hwbinder
46 chmod 0666 /dev/binderfs/binder
47 chmod 0666 /dev/binderfs/vndbinder
48
Jiyong Park858c0402021-07-15 16:19:11 +090049 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
50 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
51 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
52 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
53 mkdir /dev/cpuset/foreground
54 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
55 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
56 mkdir /dev/cpuset/background
57 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
58 copy /dev/cpuset/mems /dev/cpuset/background/mems
59 mkdir /dev/cpuset/system-background
60 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
61 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
62
63 chown system system /dev/cpuset
64 chown system system /dev/cpuset/foreground
65 chown system system /dev/cpuset/background
66 chown system system /dev/cpuset/system-background
67 chown system system /dev/cpuset/tasks
68 chown system system /dev/cpuset/foreground/tasks
69 chown system system /dev/cpuset/background/tasks
70 chown system system /dev/cpuset/system-background/tasks
71
72 chmod 0664 /dev/cpuset/tasks
73 chmod 0664 /dev/cpuset/foreground/tasks
74 chmod 0664 /dev/cpuset/background/tasks
75 chmod 0664 /dev/cpuset/system-background/tasks
76
Jiyong Park779daa92021-10-18 18:33:28 +090077on init && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +090078 # Start logd before any other services run to ensure we capture all of their logs.
79 start logd
80
Jiyong Park779daa92021-10-18 18:33:28 +090081on init
Inseob Kimdc2af862021-02-17 15:51:56 +090082 start servicemanager
83
Inseob Kim8f095c92021-05-26 12:04:54 +090084 # TODO(b/185767624): remove hidl after full keymint support
85 start hwservicemanager
86
Jiyong Parke7407e22021-10-18 15:51:59 +090087on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090088 start adbd
89
Jiyong Park779daa92021-10-18 18:33:28 +090090on load_persist_props_action && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +090091 start logd
92 start logd-reinit
93
94# Mount filesystems and start core system services.
95on late-init
96 trigger early-fs
97
98 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
99 # '--early' can be specified to skip entries with 'latemount'.
100 # /system and /vendor must be mounted by the end of the fs stage,
101 # while /data is optional.
102 trigger fs
103 trigger post-fs
104
105 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
106 # to only mount entries with 'latemount'. This is needed if '--early' is
107 # specified in the previous mount_all command on the fs stage.
108 # With /system mounted and properties form /system + /factory available,
109 # some services can be started.
110 trigger late-fs
111
Inseob Kimafd9dc02021-04-23 14:47:44 +0900112 trigger post-fs-data
113
Inseob Kimdc2af862021-02-17 15:51:56 +0900114 # Load persist properties and override properties (if enabled) from /data.
115 trigger load_persist_props_action
116
Inseob Kimdc2af862021-02-17 15:51:56 +0900117 trigger early-boot
118 trigger boot
119
120on post-fs
121 # Once everything is setup, no need to modify /.
122 # The bind+remount combination allows this to work in containers.
123 mount rootfs rootfs / remount bind ro nodev
124
Inseob Kim17d0db12021-06-09 14:30:47 +0900125 # TODO(b/185767624): change the hard-coded size?
126 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900127
Inseob Kim67ab4362021-05-11 16:51:03 +0900128 # We chown/chmod /data again so because mount is run as root + defaults
129 chown system system /data
130 chmod 0771 /data
131
132 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900133 restorecon /data
134
Inseob Kima920f9e2021-08-04 03:33:43 +0000135 # set up keystore directory structure first so that we can end early boot
136 # and start apexd
137 mkdir /data/misc 01771 system misc
138 mkdir /data/misc/keystore 0700 keystore keystore
139 # work around b/183668221
140 restorecon /data/misc /data/misc/keystore
141
142 start keystore2
143
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700144 mkdir /data/misc/authfs 0700 root root
145 start authfs_service
146
Inseob Kima920f9e2021-08-04 03:33:43 +0000147on late-fs
148 start vendor.keymint-microdroid
149
150on post-fs-data
151 mark_post_data
152
Inseob Kim17d0db12021-06-09 14:30:47 +0900153 mkdir /data/vendor 0771 root root
154 mkdir /data/vendor_ce 0771 root root
155 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900156 mkdir /data/vendor/hardware 0771 root root
157
158 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900159 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900160 mkdir /data/anr 0775 system system
161 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900162 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900163
164 start tombstoned
165
Inseob Kimde6b6892021-05-26 12:06:59 +0900166 # Boot level 30
167 # odsign signing keys have MAX_BOOT_LEVEL=30
168 # This is currently the earliest boot level, but we start at 30
169 # to leave room for earlier levels.
170 setprop keystore.boot_level 30
171
Inseob Kim87ba1f12021-04-27 14:56:05 +0900172 # For security reasons, /data/local/tmp should always be empty.
173 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900174 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900175 mkdir /data/local/tmp 0771 shell shell
176
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900177service apexd-vm /system/bin/apexd --vm
178 user root
179 group system
180 oneshot
181 disabled
182
Inseob Kimdc2af862021-02-17 15:51:56 +0900183service ueventd /system/bin/ueventd
184 class core
185 critical
186 seclabel u:r:ueventd:s0
187 shutdown critical
188
189service console /system/bin/sh
190 class core
191 console
192 disabled
193 user shell
194 group shell log readproc
195 seclabel u:r:shell:s0
196 setenv HOSTNAME console
197
Inseob Kimdc2af862021-02-17 15:51:56 +0900198on fs
199 write /dev/event-log-tags "# content owned by logd
200"
201 chown logd logd /dev/event-log-tags
202 chmod 0644 /dev/event-log-tags
203
204on property:sys.boot_completed=1
205 start logd-auditctl