blob: 86f6d0ac08a1f973a2bd24846a696bd049c10caf [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
Inseob Kim197748b2021-12-01 19:49:00 +090021 mkdir /mnt/extra-apk 0755 root root
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090022 # Microdroid_manager starts apkdmverity/zipfuse/apexd
Jooyung Hane706c9f2021-07-29 17:21:20 +090023 start microdroid_manager
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090024
Inseob Kim197748b2021-12-01 19:49:00 +090025 # restorecon so microdroid_manager can create subdirectories
26 restorecon /mnt/extra-apk
27
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090028 # Wait for apexd to finish activating APEXes before starting more processes.
29 wait_for_prop apexd.status activated
Jooyung Han16186d92021-06-01 17:53:28 +090030 perform_apex_config
Inseob Kim870e76b2021-02-25 17:38:32 +090031
Jiyong Parkbb4a9872021-09-06 15:59:21 +090032 # Notify to microdroid_manager that perform_apex_config is done.
33 # Microdroid_manager shouldn't execute payload before this, because app
34 # payloads are not designed to run with bootstrap bionic
35 setprop apex_config.done true
Jiyong Park9abfc1f2021-05-17 21:57:24 +090036
Jiyong Parke7407e22021-10-18 15:51:59 +090037 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
38
Inseob Kimdc2af862021-02-17 15:51:56 +090039on init
40 # Mount binderfs
41 mkdir /dev/binderfs
42 mount binder binder /dev/binderfs stats=global
43 chmod 0755 /dev/binderfs
44
45 symlink /dev/binderfs/binder /dev/binder
46 symlink /dev/binderfs/hwbinder /dev/hwbinder
47 symlink /dev/binderfs/vndbinder /dev/vndbinder
48
49 chmod 0666 /dev/binderfs/hwbinder
50 chmod 0666 /dev/binderfs/binder
51 chmod 0666 /dev/binderfs/vndbinder
52
Jiyong Park858c0402021-07-15 16:19:11 +090053 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
54 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
55 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
56 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
57 mkdir /dev/cpuset/foreground
58 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
59 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
60 mkdir /dev/cpuset/background
61 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
62 copy /dev/cpuset/mems /dev/cpuset/background/mems
63 mkdir /dev/cpuset/system-background
64 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
65 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
66
67 chown system system /dev/cpuset
68 chown system system /dev/cpuset/foreground
69 chown system system /dev/cpuset/background
70 chown system system /dev/cpuset/system-background
71 chown system system /dev/cpuset/tasks
72 chown system system /dev/cpuset/foreground/tasks
73 chown system system /dev/cpuset/background/tasks
74 chown system system /dev/cpuset/system-background/tasks
75
76 chmod 0664 /dev/cpuset/tasks
77 chmod 0664 /dev/cpuset/foreground/tasks
78 chmod 0664 /dev/cpuset/background/tasks
79 chmod 0664 /dev/cpuset/system-background/tasks
80
Jiyong Park779daa92021-10-18 18:33:28 +090081on init && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +090082 # Start logd before any other services run to ensure we capture all of their logs.
83 start logd
84
Jiyong Park779daa92021-10-18 18:33:28 +090085on init
Inseob Kimdc2af862021-02-17 15:51:56 +090086 start servicemanager
87
Inseob Kim8f095c92021-05-26 12:04:54 +090088 # TODO(b/185767624): remove hidl after full keymint support
89 start hwservicemanager
90
Jiyong Parke7407e22021-10-18 15:51:59 +090091on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090092 start adbd
93
Jiyong Park779daa92021-10-18 18:33:28 +090094on load_persist_props_action && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +090095 start logd
96 start logd-reinit
97
98# Mount filesystems and start core system services.
99on late-init
100 trigger early-fs
101
102 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
103 # '--early' can be specified to skip entries with 'latemount'.
104 # /system and /vendor must be mounted by the end of the fs stage,
105 # while /data is optional.
106 trigger fs
107 trigger post-fs
108
109 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
110 # to only mount entries with 'latemount'. This is needed if '--early' is
111 # specified in the previous mount_all command on the fs stage.
112 # With /system mounted and properties form /system + /factory available,
113 # some services can be started.
114 trigger late-fs
115
Inseob Kimafd9dc02021-04-23 14:47:44 +0900116 trigger post-fs-data
117
Inseob Kimdc2af862021-02-17 15:51:56 +0900118 # Load persist properties and override properties (if enabled) from /data.
119 trigger load_persist_props_action
120
Inseob Kimdc2af862021-02-17 15:51:56 +0900121 trigger early-boot
122 trigger boot
123
124on post-fs
125 # Once everything is setup, no need to modify /.
126 # The bind+remount combination allows this to work in containers.
127 mount rootfs rootfs / remount bind ro nodev
128
Inseob Kim17d0db12021-06-09 14:30:47 +0900129 # TODO(b/185767624): change the hard-coded size?
130 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900131
Inseob Kim67ab4362021-05-11 16:51:03 +0900132 # We chown/chmod /data again so because mount is run as root + defaults
133 chown system system /data
134 chmod 0771 /data
135
136 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900137 restorecon /data
138
Inseob Kima920f9e2021-08-04 03:33:43 +0000139 # set up keystore directory structure first so that we can end early boot
140 # and start apexd
141 mkdir /data/misc 01771 system misc
142 mkdir /data/misc/keystore 0700 keystore keystore
143 # work around b/183668221
144 restorecon /data/misc /data/misc/keystore
145
146 start keystore2
147
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700148 mkdir /data/misc/authfs 0700 root root
149 start authfs_service
150
Inseob Kima920f9e2021-08-04 03:33:43 +0000151on late-fs
152 start vendor.keymint-microdroid
153
154on post-fs-data
155 mark_post_data
156
Inseob Kim17d0db12021-06-09 14:30:47 +0900157 mkdir /data/vendor 0771 root root
158 mkdir /data/vendor_ce 0771 root root
159 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900160 mkdir /data/vendor/hardware 0771 root root
161
162 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900163 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900164 mkdir /data/anr 0775 system system
165 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900166 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900167
168 start tombstoned
169
Inseob Kimde6b6892021-05-26 12:06:59 +0900170 # Boot level 30
171 # odsign signing keys have MAX_BOOT_LEVEL=30
172 # This is currently the earliest boot level, but we start at 30
173 # to leave room for earlier levels.
174 setprop keystore.boot_level 30
175
Inseob Kim87ba1f12021-04-27 14:56:05 +0900176 # For security reasons, /data/local/tmp should always be empty.
177 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900178 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900179 mkdir /data/local/tmp 0771 shell shell
180
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900181service apexd-vm /system/bin/apexd --vm
182 user root
183 group system
184 oneshot
185 disabled
186
Inseob Kimdc2af862021-02-17 15:51:56 +0900187service ueventd /system/bin/ueventd
188 class core
189 critical
190 seclabel u:r:ueventd:s0
191 shutdown critical
192
193service console /system/bin/sh
194 class core
195 console
196 disabled
197 user shell
198 group shell log readproc
199 seclabel u:r:shell:s0
200 setenv HOSTNAME console
201
Jiyong Parkae5a4ed2021-11-01 18:36:28 +0900202service seriallogging /system/bin/logcat -b all -v threadtime -f /dev/hvc2 *:V
Jiyong Parkfa91d702021-10-18 23:51:39 +0900203 disabled
204 user logd
205 group root logd
206
Inseob Kimdc2af862021-02-17 15:51:56 +0900207on fs
208 write /dev/event-log-tags "# content owned by logd
209"
210 chown logd logd /dev/event-log-tags
211 chmod 0644 /dev/event-log-tags
212
213on property:sys.boot_completed=1
214 start logd-auditctl