blob: 45d939840d3665389618a50f81a87d2dbf0ad4a5 [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
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090020 # TODO(b/190343842) verify apexes/apk before mounting them.
21
Jooyung Han16186d92021-06-01 17:53:28 +090022 # Exec apexd in the VM mode to avoid unnecessary overhead of normal mode.
23 # (e.g. session management)
24 exec - root system -- /system/bin/apexd --vm
Inseob Kimdc2af862021-02-17 15:51:56 +090025
Jooyung Han16186d92021-06-01 17:53:28 +090026 perform_apex_config
Inseob Kim870e76b2021-02-25 17:38:32 +090027
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090028 exec - root system -- /system/bin/apkdmverity /dev/block/by-name/microdroid-apk /dev/block/by-name/microdroid-apk-idsig microdroid-apk
Jiyong Park9abfc1f2021-05-17 21:57:24 +090029 mkdir /mnt/apk 0755 system system
30 start zipfuse
31
Inseob Kimdc2af862021-02-17 15:51:56 +090032on init
33 # Mount binderfs
34 mkdir /dev/binderfs
35 mount binder binder /dev/binderfs stats=global
36 chmod 0755 /dev/binderfs
37
38 symlink /dev/binderfs/binder /dev/binder
39 symlink /dev/binderfs/hwbinder /dev/hwbinder
40 symlink /dev/binderfs/vndbinder /dev/vndbinder
41
42 chmod 0666 /dev/binderfs/hwbinder
43 chmod 0666 /dev/binderfs/binder
44 chmod 0666 /dev/binderfs/vndbinder
45
Jiyong Park858c0402021-07-15 16:19:11 +090046 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
47 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
48 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
49 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
50 mkdir /dev/cpuset/foreground
51 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
52 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
53 mkdir /dev/cpuset/background
54 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
55 copy /dev/cpuset/mems /dev/cpuset/background/mems
56 mkdir /dev/cpuset/system-background
57 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
58 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
59
60 chown system system /dev/cpuset
61 chown system system /dev/cpuset/foreground
62 chown system system /dev/cpuset/background
63 chown system system /dev/cpuset/system-background
64 chown system system /dev/cpuset/tasks
65 chown system system /dev/cpuset/foreground/tasks
66 chown system system /dev/cpuset/background/tasks
67 chown system system /dev/cpuset/system-background/tasks
68
69 chmod 0664 /dev/cpuset/tasks
70 chmod 0664 /dev/cpuset/foreground/tasks
71 chmod 0664 /dev/cpuset/background/tasks
72 chmod 0664 /dev/cpuset/system-background/tasks
73
Inseob Kimdc2af862021-02-17 15:51:56 +090074 # Start logd before any other services run to ensure we capture all of their logs.
75 start logd
76
77 start servicemanager
78
Inseob Kim8f095c92021-05-26 12:04:54 +090079 # TODO(b/185767624): remove hidl after full keymint support
80 start hwservicemanager
81
Jooyung Han16186d92021-06-01 17:53:28 +090082 start adbd
83
84 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
85 # TODO(b/186396070) move this before apexd for DICE derivation
86 start microdroid_manager
87
Inseob Kimdc2af862021-02-17 15:51:56 +090088on load_persist_props_action
89 start logd
90 start logd-reinit
91
92# Mount filesystems and start core system services.
93on late-init
94 trigger early-fs
95
96 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
97 # '--early' can be specified to skip entries with 'latemount'.
98 # /system and /vendor must be mounted by the end of the fs stage,
99 # while /data is optional.
100 trigger fs
101 trigger post-fs
102
103 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
104 # to only mount entries with 'latemount'. This is needed if '--early' is
105 # specified in the previous mount_all command on the fs stage.
106 # With /system mounted and properties form /system + /factory available,
107 # some services can be started.
108 trigger late-fs
109
Inseob Kimafd9dc02021-04-23 14:47:44 +0900110 trigger post-fs-data
111
Inseob Kimdc2af862021-02-17 15:51:56 +0900112 # Load persist properties and override properties (if enabled) from /data.
113 trigger load_persist_props_action
114
Inseob Kimdc2af862021-02-17 15:51:56 +0900115 trigger early-boot
116 trigger boot
117
118on post-fs
119 # Once everything is setup, no need to modify /.
120 # The bind+remount combination allows this to work in containers.
121 mount rootfs rootfs / remount bind ro nodev
122
Inseob Kimde6b6892021-05-26 12:06:59 +0900123 start keystore2
124
Inseob Kim67ab4362021-05-11 16:51:03 +0900125on late-fs
Andrew Scull9ba26572021-05-27 19:20:46 +0000126 start vendor.keymint-microdroid
Inseob Kimde6b6892021-05-26 12:06:59 +0900127
Inseob Kim17d0db12021-06-09 14:30:47 +0900128 # TODO(b/185767624): change the hard-coded size?
129 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900130
Inseob Kimafd9dc02021-04-23 14:47:44 +0900131on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900132 mark_post_data
133
134 # We chown/chmod /data again so because mount is run as root + defaults
135 chown system system /data
136 chmod 0771 /data
137
138 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900139 restorecon /data
140
Inseob Kim17d0db12021-06-09 14:30:47 +0900141 mkdir /data/vendor 0771 root root
142 mkdir /data/vendor_ce 0771 root root
143 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900144 mkdir /data/vendor/hardware 0771 root root
145
146 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900147 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900148 mkdir /data/anr 0775 system system
149 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900150 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900151
152 start tombstoned
153
Inseob Kimde6b6892021-05-26 12:06:59 +0900154 # set up keystore directory structure first so that we can end early boot
155 # and start apexd
Inseob Kim17d0db12021-06-09 14:30:47 +0900156 mkdir /data/misc 01771 system misc
Inseob Kimde6b6892021-05-26 12:06:59 +0900157 mkdir /data/misc/keystore 0700 keystore keystore
158 # work around b/183668221
159 restorecon /data/misc /data/misc/keystore
160
161 # Boot level 30
162 # odsign signing keys have MAX_BOOT_LEVEL=30
163 # This is currently the earliest boot level, but we start at 30
164 # to leave room for earlier levels.
165 setprop keystore.boot_level 30
166
Inseob Kim87ba1f12021-04-27 14:56:05 +0900167 # For security reasons, /data/local/tmp should always be empty.
168 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900169 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900170 mkdir /data/local/tmp 0771 shell shell
171
Inseob Kimdc2af862021-02-17 15:51:56 +0900172service ueventd /system/bin/ueventd
173 class core
174 critical
175 seclabel u:r:ueventd:s0
176 shutdown critical
177
178service console /system/bin/sh
179 class core
180 console
181 disabled
182 user shell
183 group shell log readproc
184 seclabel u:r:shell:s0
185 setenv HOSTNAME console
186
Inseob Kimdc2af862021-02-17 15:51:56 +0900187on fs
188 write /dev/event-log-tags "# content owned by logd
189"
190 chown logd logd /dev/event-log-tags
191 chmod 0644 /dev/event-log-tags
192
193on property:sys.boot_completed=1
194 start logd-auditctl