blob: 42aa98392d3c467d9d45990185a30ca024019e1c [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
Inseob Kimdc2af862021-02-17 15:51:56 +090020on init
21 # Mount binderfs
22 mkdir /dev/binderfs
23 mount binder binder /dev/binderfs stats=global
24 chmod 0755 /dev/binderfs
25
26 symlink /dev/binderfs/binder /dev/binder
Inseob Kimdc2af862021-02-17 15:51:56 +090027 symlink /dev/binderfs/vndbinder /dev/vndbinder
28
Inseob Kimdc2af862021-02-17 15:51:56 +090029 chmod 0666 /dev/binderfs/binder
30 chmod 0666 /dev/binderfs/vndbinder
31
Jiyong Park858c0402021-07-15 16:19:11 +090032 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
33 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
34 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
35 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
36 mkdir /dev/cpuset/foreground
37 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
38 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
39 mkdir /dev/cpuset/background
40 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
41 copy /dev/cpuset/mems /dev/cpuset/background/mems
42 mkdir /dev/cpuset/system-background
43 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
44 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
45
46 chown system system /dev/cpuset
47 chown system system /dev/cpuset/foreground
48 chown system system /dev/cpuset/background
49 chown system system /dev/cpuset/system-background
50 chown system system /dev/cpuset/tasks
51 chown system system /dev/cpuset/foreground/tasks
52 chown system system /dev/cpuset/background/tasks
53 chown system system /dev/cpuset/system-background/tasks
54
55 chmod 0664 /dev/cpuset/tasks
56 chmod 0664 /dev/cpuset/foreground/tasks
57 chmod 0664 /dev/cpuset/background/tasks
58 chmod 0664 /dev/cpuset/system-background/tasks
59
Inseob Kimdc2af862021-02-17 15:51:56 +090060 start servicemanager
61
Andrew Scullf8195942022-01-13 17:37:52 +000062 start vendor.dice-microdroid
Jiyong Parkc5166842022-01-21 12:54:57 +090063 start diced
64
Inseob Kim4de509a2022-07-04 19:29:33 +090065on init && property:ro.boot.logd.enabled=1
66 # Start logd before any other services run to ensure we capture all of their logs.
67 # TODO(b/217796229) set filterspec if debug_level is app_only
68 start logd
69 start seriallogging
70
71on init
Jiyong Parkc5166842022-01-21 12:54:57 +090072 mkdir /mnt/apk 0755 system system
73 mkdir /mnt/extra-apk 0755 root root
74 # Microdroid_manager starts apkdmverity/zipfuse/apexd
75 start microdroid_manager
76
77 # restorecon so microdroid_manager can create subdirectories
78 restorecon /mnt/extra-apk
79
80 # Wait for apexd to finish activating APEXes before starting more processes.
81 wait_for_prop apexd.status activated
82 perform_apex_config
83
84 # Notify to microdroid_manager that perform_apex_config is done.
85 # Microdroid_manager shouldn't execute payload before this, because app
86 # payloads are not designed to run with bootstrap bionic
87 setprop apex_config.done true
88
89 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
90
Jiyong Park5bd24822022-08-23 14:50:29 +090091on property:dev.bootcomplete=1
92 # Stop ueventd to save memory
93 stop ueventd
94
Oleg Matcovschi98739482022-03-14 06:29:25 -070095on init && property:ro.boot.microdroid.debuggable=1
96 # Mount tracefs (with GID=AID_READTRACEFS)
97 mount tracefs tracefs /sys/kernel/tracing gid=3012
98
Jiyong Parke7407e22021-10-18 15:51:59 +090099on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +0900100 start adbd
101
Jiyong Park779daa92021-10-18 18:33:28 +0900102on load_persist_props_action && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +0900103 start logd
104 start logd-reinit
105
106# Mount filesystems and start core system services.
107on late-init
108 trigger early-fs
109
110 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
111 # '--early' can be specified to skip entries with 'latemount'.
112 # /system and /vendor must be mounted by the end of the fs stage,
113 # while /data is optional.
114 trigger fs
115 trigger post-fs
116
117 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
118 # to only mount entries with 'latemount'. This is needed if '--early' is
119 # specified in the previous mount_all command on the fs stage.
120 # With /system mounted and properties form /system + /factory available,
121 # some services can be started.
122 trigger late-fs
123
Inseob Kimafd9dc02021-04-23 14:47:44 +0900124 trigger post-fs-data
125
Inseob Kimdc2af862021-02-17 15:51:56 +0900126 # Load persist properties and override properties (if enabled) from /data.
127 trigger load_persist_props_action
128
Inseob Kimdc2af862021-02-17 15:51:56 +0900129 trigger early-boot
130 trigger boot
131
132on post-fs
133 # Once everything is setup, no need to modify /.
134 # The bind+remount combination allows this to work in containers.
135 mount rootfs rootfs / remount bind ro nodev
136
Inseob Kim17d0db12021-06-09 14:30:47 +0900137 # TODO(b/185767624): change the hard-coded size?
138 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900139
Inseob Kim67ab4362021-05-11 16:51:03 +0900140 # We chown/chmod /data again so because mount is run as root + defaults
141 chown system system /data
142 chmod 0771 /data
143
144 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900145 restorecon /data
146
Andrew Scull195354c2022-01-27 16:12:04 +0000147 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000148 # and start apexd
149 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000150 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000151 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000152
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700153 mkdir /data/misc/authfs 0700 root root
154 start authfs_service
155
Oleg Matcovschi98739482022-03-14 06:29:25 -0700156on late-fs && property:ro.debuggable=1
157 # Ensure that tracefs has the correct permissions.
158 # This does not work correctly if it is called in post-fs.
159 chmod 0755 /sys/kernel/tracing
160 chmod 0755 /sys/kernel/debug/tracing
161
Inseob Kima920f9e2021-08-04 03:33:43 +0000162on post-fs-data
163 mark_post_data
164
Inseob Kim17d0db12021-06-09 14:30:47 +0900165 mkdir /data/vendor 0771 root root
166 mkdir /data/vendor_ce 0771 root root
167 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900168 mkdir /data/vendor/hardware 0771 root root
169
170 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900171 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900172 mkdir /data/anr 0775 system system
173 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900174 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900175
176 start tombstoned
177
Inseob Kim87ba1f12021-04-27 14:56:05 +0900178 # For security reasons, /data/local/tmp should always be empty.
179 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900180 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900181 mkdir /data/local/tmp 0771 shell shell
182
Shikha Panwarc29d24b2022-05-25 13:48:40 +0000183service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
Shikha Panwar7afc1392022-03-24 08:54:43 +0000184 user root
185 group system
Inseob Kimcd9c1dd2022-07-13 17:13:45 +0900186 shutdown critical
Shikha Panwar7afc1392022-03-24 08:54:43 +0000187
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900188service apexd-vm /system/bin/apexd --vm
189 user root
190 group system
191 oneshot
192 disabled
193
Inseob Kimdc2af862021-02-17 15:51:56 +0900194service ueventd /system/bin/ueventd
195 class core
196 critical
197 seclabel u:r:ueventd:s0
198 shutdown critical
199
200service console /system/bin/sh
201 class core
202 console
203 disabled
204 user shell
205 group shell log readproc
206 seclabel u:r:shell:s0
207 setenv HOSTNAME console
208
Jiyong Parkae5a4ed2021-11-01 18:36:28 +0900209service seriallogging /system/bin/logcat -b all -v threadtime -f /dev/hvc2 *:V
Jiyong Parkfa91d702021-10-18 23:51:39 +0900210 disabled
211 user logd
212 group root logd
213
Inseob Kimdc2af862021-02-17 15:51:56 +0900214on fs
215 write /dev/event-log-tags "# content owned by logd
216"
217 chown logd logd /dev/event-log-tags
218 chmod 0644 /dev/event-log-tags