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