blob: 2ccdc3b4a7ea16e280c9a5a0d7307e94f96d4336 [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
27 symlink /dev/binderfs/hwbinder /dev/hwbinder
28 symlink /dev/binderfs/vndbinder /dev/vndbinder
29
30 chmod 0666 /dev/binderfs/hwbinder
31 chmod 0666 /dev/binderfs/binder
32 chmod 0666 /dev/binderfs/vndbinder
33
Jiyong Park858c0402021-07-15 16:19:11 +090034 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
35 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
36 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
37 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
38 mkdir /dev/cpuset/foreground
39 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
40 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
41 mkdir /dev/cpuset/background
42 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
43 copy /dev/cpuset/mems /dev/cpuset/background/mems
44 mkdir /dev/cpuset/system-background
45 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
46 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
47
48 chown system system /dev/cpuset
49 chown system system /dev/cpuset/foreground
50 chown system system /dev/cpuset/background
51 chown system system /dev/cpuset/system-background
52 chown system system /dev/cpuset/tasks
53 chown system system /dev/cpuset/foreground/tasks
54 chown system system /dev/cpuset/background/tasks
55 chown system system /dev/cpuset/system-background/tasks
56
57 chmod 0664 /dev/cpuset/tasks
58 chmod 0664 /dev/cpuset/foreground/tasks
59 chmod 0664 /dev/cpuset/background/tasks
60 chmod 0664 /dev/cpuset/system-background/tasks
61
Inseob Kimdc2af862021-02-17 15:51:56 +090062 start servicemanager
63
Andrew Scullf8195942022-01-13 17:37:52 +000064 start vendor.dice-microdroid
Jiyong Parkc5166842022-01-21 12:54:57 +090065 start diced
66
67 mkdir /mnt/apk 0755 system system
68 mkdir /mnt/extra-apk 0755 root root
69 # Microdroid_manager starts apkdmverity/zipfuse/apexd
70 start microdroid_manager
71
72 # restorecon so microdroid_manager can create subdirectories
73 restorecon /mnt/extra-apk
74
75 # Wait for apexd to finish activating APEXes before starting more processes.
76 wait_for_prop apexd.status activated
77 perform_apex_config
78
79 # Notify to microdroid_manager that perform_apex_config is done.
80 # Microdroid_manager shouldn't execute payload before this, because app
81 # payloads are not designed to run with bootstrap bionic
82 setprop apex_config.done true
83
84 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
85
Oleg Matcovschi98739482022-03-14 06:29:25 -070086on init && property:ro.boot.microdroid.debuggable=1
87 # Mount tracefs (with GID=AID_READTRACEFS)
88 mount tracefs tracefs /sys/kernel/tracing gid=3012
89
Jiyong Parkc5166842022-01-21 12:54:57 +090090on init && property:ro.boot.logd.enabled=1
91 # Start logd before any other services run to ensure we capture all of their logs.
92 start logd
Jiyong Parkd0da3e22022-01-13 01:35:49 +090093
Jiyong Parke7407e22021-10-18 15:51:59 +090094on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090095 start adbd
96
Jiyong Park779daa92021-10-18 18:33:28 +090097on load_persist_props_action && property:ro.boot.logd.enabled=1
Inseob Kimdc2af862021-02-17 15:51:56 +090098 start logd
99 start logd-reinit
100
101# Mount filesystems and start core system services.
102on late-init
103 trigger early-fs
104
105 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
106 # '--early' can be specified to skip entries with 'latemount'.
107 # /system and /vendor must be mounted by the end of the fs stage,
108 # while /data is optional.
109 trigger fs
110 trigger post-fs
111
112 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
113 # to only mount entries with 'latemount'. This is needed if '--early' is
114 # specified in the previous mount_all command on the fs stage.
115 # With /system mounted and properties form /system + /factory available,
116 # some services can be started.
117 trigger late-fs
118
Inseob Kimafd9dc02021-04-23 14:47:44 +0900119 trigger post-fs-data
120
Inseob Kimdc2af862021-02-17 15:51:56 +0900121 # Load persist properties and override properties (if enabled) from /data.
122 trigger load_persist_props_action
123
Inseob Kimdc2af862021-02-17 15:51:56 +0900124 trigger early-boot
125 trigger boot
126
127on post-fs
128 # Once everything is setup, no need to modify /.
129 # The bind+remount combination allows this to work in containers.
130 mount rootfs rootfs / remount bind ro nodev
131
Inseob Kim17d0db12021-06-09 14:30:47 +0900132 # TODO(b/185767624): change the hard-coded size?
133 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900134
Inseob Kim67ab4362021-05-11 16:51:03 +0900135 # We chown/chmod /data again so because mount is run as root + defaults
136 chown system system /data
137 chmod 0771 /data
138
139 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900140 restorecon /data
141
Andrew Scull195354c2022-01-27 16:12:04 +0000142 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000143 # and start apexd
144 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000145 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000146 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000147
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700148 mkdir /data/misc/authfs 0700 root root
149 start authfs_service
150
Oleg Matcovschi98739482022-03-14 06:29:25 -0700151on late-fs && property:ro.debuggable=1
152 # Ensure that tracefs has the correct permissions.
153 # This does not work correctly if it is called in post-fs.
154 chmod 0755 /sys/kernel/tracing
155 chmod 0755 /sys/kernel/debug/tracing
156
Inseob Kima920f9e2021-08-04 03:33:43 +0000157on post-fs-data
158 mark_post_data
159
Inseob Kim17d0db12021-06-09 14:30:47 +0900160 mkdir /data/vendor 0771 root root
161 mkdir /data/vendor_ce 0771 root root
162 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900163 mkdir /data/vendor/hardware 0771 root root
164
165 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900166 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900167 mkdir /data/anr 0775 system system
168 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900169 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900170
171 start tombstoned
172
Inseob Kim87ba1f12021-04-27 14:56:05 +0900173 # For security reasons, /data/local/tmp should always be empty.
174 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900175 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900176 mkdir /data/local/tmp 0771 shell shell
177
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900178service apexd-vm /system/bin/apexd --vm
179 user root
180 group system
181 oneshot
182 disabled
183
Inseob Kimdc2af862021-02-17 15:51:56 +0900184service ueventd /system/bin/ueventd
185 class core
186 critical
187 seclabel u:r:ueventd:s0
188 shutdown critical
189
190service console /system/bin/sh
191 class core
192 console
193 disabled
194 user shell
195 group shell log readproc
196 seclabel u:r:shell:s0
197 setenv HOSTNAME console
198
Jiyong Parkae5a4ed2021-11-01 18:36:28 +0900199service seriallogging /system/bin/logcat -b all -v threadtime -f /dev/hvc2 *:V
Jiyong Parkfa91d702021-10-18 23:51:39 +0900200 disabled
201 user logd
202 group root logd
203
Inseob Kimdc2af862021-02-17 15:51:56 +0900204on fs
205 write /dev/event-log-tags "# content owned by logd
206"
207 chown logd logd /dev/event-log-tags
208 chmod 0644 /dev/event-log-tags