blob: 074e1185dea734c895b4b5278cf11190457e564e [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 Han16186d92021-06-01 17:53:28 +090018 # in microdroid, we don't use "bootstrap" mount namespace
19 # because APEXes are passed from host and are available
20 # from the start. We don't need to wait till /data is ready.
21 enter_default_mount_ns
Jooyung Hanc36b18a2021-04-20 03:33:36 +090022
23 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090024
Jooyung Han16186d92021-06-01 17:53:28 +090025 # Exec apexd in the VM mode to avoid unnecessary overhead of normal mode.
26 # (e.g. session management)
27 exec - root system -- /system/bin/apexd --vm
Inseob Kimdc2af862021-02-17 15:51:56 +090028
Jooyung Han16186d92021-06-01 17:53:28 +090029 perform_apex_config
30 exec_start derive_sdk
Inseob Kim870e76b2021-02-25 17:38:32 +090031
Jiyong Park9abfc1f2021-05-17 21:57:24 +090032 mkdir /mnt/apk 0755 system system
33 start zipfuse
34
Inseob Kimdc2af862021-02-17 15:51:56 +090035on init
36 # Mount binderfs
37 mkdir /dev/binderfs
38 mount binder binder /dev/binderfs stats=global
39 chmod 0755 /dev/binderfs
40
41 symlink /dev/binderfs/binder /dev/binder
42 symlink /dev/binderfs/hwbinder /dev/hwbinder
43 symlink /dev/binderfs/vndbinder /dev/vndbinder
44
45 chmod 0666 /dev/binderfs/hwbinder
46 chmod 0666 /dev/binderfs/binder
47 chmod 0666 /dev/binderfs/vndbinder
48
49 # Start logd before any other services run to ensure we capture all of their logs.
50 start logd
51
52 start servicemanager
53
Inseob Kim8f095c92021-05-26 12:04:54 +090054 # TODO(b/185767624): remove hidl after full keymint support
55 start hwservicemanager
56
Jooyung Han16186d92021-06-01 17:53:28 +090057 start adbd
58
59 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
60 # TODO(b/186396070) move this before apexd for DICE derivation
61 start microdroid_manager
62
Inseob Kimdc2af862021-02-17 15:51:56 +090063on load_persist_props_action
64 start logd
65 start logd-reinit
66
67# Mount filesystems and start core system services.
68on late-init
69 trigger early-fs
70
71 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
72 # '--early' can be specified to skip entries with 'latemount'.
73 # /system and /vendor must be mounted by the end of the fs stage,
74 # while /data is optional.
75 trigger fs
76 trigger post-fs
77
78 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
79 # to only mount entries with 'latemount'. This is needed if '--early' is
80 # specified in the previous mount_all command on the fs stage.
81 # With /system mounted and properties form /system + /factory available,
82 # some services can be started.
83 trigger late-fs
84
Inseob Kimafd9dc02021-04-23 14:47:44 +090085 trigger post-fs-data
86
Inseob Kimdc2af862021-02-17 15:51:56 +090087 # Load persist properties and override properties (if enabled) from /data.
88 trigger load_persist_props_action
89
90 # Should be before netd, but after apex, properties and logging is available.
91 trigger load_bpf_programs
92
93 # Now we can start zygote for devices with file based encryption
94 trigger zygote-start
95
96 # Remove a file to wake up anything waiting for firmware.
97 trigger firmware_mounts_complete
98
99 trigger early-boot
100 trigger boot
101
Inseob Kimde6b6892021-05-26 12:06:59 +0900102on early-fs
103 start vold
104
Inseob Kimdc2af862021-02-17 15:51:56 +0900105on post-fs
106 # Once everything is setup, no need to modify /.
107 # The bind+remount combination allows this to work in containers.
108 mount rootfs rootfs / remount bind ro nodev
109
Inseob Kimde6b6892021-05-26 12:06:59 +0900110 start keystore2
111
Inseob Kim67ab4362021-05-11 16:51:03 +0900112on late-fs
Inseob Kimde6b6892021-05-26 12:06:59 +0900113 start vendor.keymint-default
114
115 exec_start wait_for_keymaster
116
Inseob Kim67ab4362021-05-11 16:51:03 +0900117 mount_all /vendor/etc/fstab.microdroid --late
118
Inseob Kimafd9dc02021-04-23 14:47:44 +0900119on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900120 mark_post_data
121
122 # We chown/chmod /data again so because mount is run as root + defaults
123 chown system system /data
124 chmod 0771 /data
125
126 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900127 restorecon /data
128
Inseob Kimde6b6892021-05-26 12:06:59 +0900129 # Make sure we have the device encryption key.
130 installkey /data
131
Inseob Kimcd13c692021-04-23 15:56:33 +0900132 mkdir /data/vendor 0771 root root encryption=Require
133 mkdir /data/vendor_ce 0771 root root encryption=None
134 mkdir /data/vendor_de 0771 root root encryption=None
135 mkdir /data/vendor/hardware 0771 root root
136
137 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900138 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kimcd13c692021-04-23 15:56:33 +0900139 mkdir /data/anr 0775 system system encryption=Require
140 mkdir /data/tombstones 0771 system system encryption=Require
141 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900142
143 start tombstoned
144
Inseob Kimde6b6892021-05-26 12:06:59 +0900145 # set up keystore directory structure first so that we can end early boot
146 # and start apexd
147 mkdir /data/misc 01771 system misc encryption=Require
148 mkdir /data/misc/keystore 0700 keystore keystore
149 # work around b/183668221
150 restorecon /data/misc /data/misc/keystore
151
152 # Boot level 30
153 # odsign signing keys have MAX_BOOT_LEVEL=30
154 # This is currently the earliest boot level, but we start at 30
155 # to leave room for earlier levels.
156 setprop keystore.boot_level 30
157
158 # Now that /data is mounted and we have created /data/misc/keystore,
159 # we can tell keystore to stop allowing use of early-boot keys,
160 # and access its database for the first time to support creation and
161 # use of MAX_BOOT_LEVEL keys.
162 exec - system system -- /system/bin/vdc keymaster earlyBootEnded
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
166 mkdir /data/local 0751 root root encryption=Require
167 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
192
Inseob Kimde6b6892021-05-26 12:06:59 +0900193on property:vold.decrypt=trigger_post_fs_data
194 trigger post-fs-data