blob: 347f51412db9510a571b32ab455978ec13a7b1e7 [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
Jiyong Parkbb4a9872021-09-06 15:59:21 +090020 mkdir /mnt/apk 0755 system system
Jooyung Hane706c9f2021-07-29 17:21:20 +090021 start microdroid_manager
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090022
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
Jiyong Parkbb4a9872021-09-06 15:59:21 +090029 # Notify to microdroid_manager that perform_apex_config is done.
30 # Microdroid_manager shouldn't execute payload before this, because app
31 # payloads are not designed to run with bootstrap bionic
32 setprop apex_config.done true
Jiyong Park9abfc1f2021-05-17 21:57:24 +090033
Inseob Kimdc2af862021-02-17 15:51:56 +090034on init
35 # Mount binderfs
36 mkdir /dev/binderfs
37 mount binder binder /dev/binderfs stats=global
38 chmod 0755 /dev/binderfs
39
40 symlink /dev/binderfs/binder /dev/binder
41 symlink /dev/binderfs/hwbinder /dev/hwbinder
42 symlink /dev/binderfs/vndbinder /dev/vndbinder
43
44 chmod 0666 /dev/binderfs/hwbinder
45 chmod 0666 /dev/binderfs/binder
46 chmod 0666 /dev/binderfs/vndbinder
47
Jiyong Park858c0402021-07-15 16:19:11 +090048 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
49 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
50 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
51 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
52 mkdir /dev/cpuset/foreground
53 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
54 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
55 mkdir /dev/cpuset/background
56 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
57 copy /dev/cpuset/mems /dev/cpuset/background/mems
58 mkdir /dev/cpuset/system-background
59 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
60 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
61
62 chown system system /dev/cpuset
63 chown system system /dev/cpuset/foreground
64 chown system system /dev/cpuset/background
65 chown system system /dev/cpuset/system-background
66 chown system system /dev/cpuset/tasks
67 chown system system /dev/cpuset/foreground/tasks
68 chown system system /dev/cpuset/background/tasks
69 chown system system /dev/cpuset/system-background/tasks
70
71 chmod 0664 /dev/cpuset/tasks
72 chmod 0664 /dev/cpuset/foreground/tasks
73 chmod 0664 /dev/cpuset/background/tasks
74 chmod 0664 /dev/cpuset/system-background/tasks
75
Inseob Kimdc2af862021-02-17 15:51:56 +090076 # Start logd before any other services run to ensure we capture all of their logs.
77 start logd
78
79 start servicemanager
80
Inseob Kim8f095c92021-05-26 12:04:54 +090081 # TODO(b/185767624): remove hidl after full keymint support
82 start hwservicemanager
83
Jooyung Han16186d92021-06-01 17:53:28 +090084 start adbd
85
Inseob Kimdc2af862021-02-17 15:51:56 +090086on load_persist_props_action
87 start logd
88 start logd-reinit
89
90# Mount filesystems and start core system services.
91on late-init
92 trigger early-fs
93
94 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
95 # '--early' can be specified to skip entries with 'latemount'.
96 # /system and /vendor must be mounted by the end of the fs stage,
97 # while /data is optional.
98 trigger fs
99 trigger post-fs
100
101 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
102 # to only mount entries with 'latemount'. This is needed if '--early' is
103 # specified in the previous mount_all command on the fs stage.
104 # With /system mounted and properties form /system + /factory available,
105 # some services can be started.
106 trigger late-fs
107
Inseob Kimafd9dc02021-04-23 14:47:44 +0900108 trigger post-fs-data
109
Inseob Kimdc2af862021-02-17 15:51:56 +0900110 # Load persist properties and override properties (if enabled) from /data.
111 trigger load_persist_props_action
112
Inseob Kimdc2af862021-02-17 15:51:56 +0900113 trigger early-boot
114 trigger boot
115
116on post-fs
117 # Once everything is setup, no need to modify /.
118 # The bind+remount combination allows this to work in containers.
119 mount rootfs rootfs / remount bind ro nodev
120
Inseob Kim17d0db12021-06-09 14:30:47 +0900121 # TODO(b/185767624): change the hard-coded size?
122 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900123
Inseob Kim67ab4362021-05-11 16:51:03 +0900124 # We chown/chmod /data again so because mount is run as root + defaults
125 chown system system /data
126 chmod 0771 /data
127
128 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900129 restorecon /data
130
Inseob Kima920f9e2021-08-04 03:33:43 +0000131 # set up keystore directory structure first so that we can end early boot
132 # and start apexd
133 mkdir /data/misc 01771 system misc
134 mkdir /data/misc/keystore 0700 keystore keystore
135 # work around b/183668221
136 restorecon /data/misc /data/misc/keystore
137
138 start keystore2
139
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700140 mkdir /data/misc/authfs 0700 root root
141 start authfs_service
142
Inseob Kima920f9e2021-08-04 03:33:43 +0000143on late-fs
144 start vendor.keymint-microdroid
145
146on post-fs-data
147 mark_post_data
148
Inseob Kim17d0db12021-06-09 14:30:47 +0900149 mkdir /data/vendor 0771 root root
150 mkdir /data/vendor_ce 0771 root root
151 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900152 mkdir /data/vendor/hardware 0771 root root
153
154 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900155 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900156 mkdir /data/anr 0775 system system
157 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900158 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900159
160 start tombstoned
161
Inseob Kimde6b6892021-05-26 12:06:59 +0900162 # Boot level 30
163 # odsign signing keys have MAX_BOOT_LEVEL=30
164 # This is currently the earliest boot level, but we start at 30
165 # to leave room for earlier levels.
166 setprop keystore.boot_level 30
167
Inseob Kim87ba1f12021-04-27 14:56:05 +0900168 # For security reasons, /data/local/tmp should always be empty.
169 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900170 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900171 mkdir /data/local/tmp 0771 shell shell
172
Inseob Kimdc2af862021-02-17 15:51:56 +0900173service ueventd /system/bin/ueventd
174 class core
175 critical
176 seclabel u:r:ueventd:s0
177 shutdown critical
178
179service console /system/bin/sh
180 class core
181 console
182 disabled
183 user shell
184 group shell log readproc
185 seclabel u:r:shell:s0
186 setenv HOSTNAME console
187
Inseob Kimdc2af862021-02-17 15:51:56 +0900188on fs
189 write /dev/event-log-tags "# content owned by logd
190"
191 chown logd logd /dev/event-log-tags
192 chmod 0644 /dev/event-log-tags
193
194on property:sys.boot_completed=1
195 start logd-auditctl