blob: 36cddbb58efa83fb20dba22d5f47eecae5a00202 [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 Hand4a7a7a2021-06-17 13:05:36 +090025 # TODO(b/190343842) verify apexes/apk before mounting them.
26
Jooyung Han16186d92021-06-01 17:53:28 +090027 # Exec apexd in the VM mode to avoid unnecessary overhead of normal mode.
28 # (e.g. session management)
29 exec - root system -- /system/bin/apexd --vm
Inseob Kimdc2af862021-02-17 15:51:56 +090030
Jooyung Han16186d92021-06-01 17:53:28 +090031 perform_apex_config
Inseob Kim870e76b2021-02-25 17:38:32 +090032
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090033 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 +090034 mkdir /mnt/apk 0755 system system
35 start zipfuse
36
Inseob Kimdc2af862021-02-17 15:51:56 +090037on init
38 # Mount binderfs
39 mkdir /dev/binderfs
40 mount binder binder /dev/binderfs stats=global
41 chmod 0755 /dev/binderfs
42
43 symlink /dev/binderfs/binder /dev/binder
44 symlink /dev/binderfs/hwbinder /dev/hwbinder
45 symlink /dev/binderfs/vndbinder /dev/vndbinder
46
47 chmod 0666 /dev/binderfs/hwbinder
48 chmod 0666 /dev/binderfs/binder
49 chmod 0666 /dev/binderfs/vndbinder
50
51 # Start logd before any other services run to ensure we capture all of their logs.
52 start logd
53
54 start servicemanager
55
Inseob Kim8f095c92021-05-26 12:04:54 +090056 # TODO(b/185767624): remove hidl after full keymint support
57 start hwservicemanager
58
Jooyung Han16186d92021-06-01 17:53:28 +090059 start adbd
60
61 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
62 # TODO(b/186396070) move this before apexd for DICE derivation
63 start microdroid_manager
64
Inseob Kimdc2af862021-02-17 15:51:56 +090065on load_persist_props_action
66 start logd
67 start logd-reinit
68
69# Mount filesystems and start core system services.
70on late-init
71 trigger early-fs
72
73 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
74 # '--early' can be specified to skip entries with 'latemount'.
75 # /system and /vendor must be mounted by the end of the fs stage,
76 # while /data is optional.
77 trigger fs
78 trigger post-fs
79
80 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
81 # to only mount entries with 'latemount'. This is needed if '--early' is
82 # specified in the previous mount_all command on the fs stage.
83 # With /system mounted and properties form /system + /factory available,
84 # some services can be started.
85 trigger late-fs
86
Inseob Kimafd9dc02021-04-23 14:47:44 +090087 trigger post-fs-data
88
Inseob Kimdc2af862021-02-17 15:51:56 +090089 # Load persist properties and override properties (if enabled) from /data.
90 trigger load_persist_props_action
91
Inseob Kimdc2af862021-02-17 15:51:56 +090092 trigger early-boot
93 trigger boot
94
95on post-fs
96 # Once everything is setup, no need to modify /.
97 # The bind+remount combination allows this to work in containers.
98 mount rootfs rootfs / remount bind ro nodev
99
Inseob Kimde6b6892021-05-26 12:06:59 +0900100 start keystore2
101
Inseob Kim67ab4362021-05-11 16:51:03 +0900102on late-fs
Andrew Scull9ba26572021-05-27 19:20:46 +0000103 start vendor.keymint-microdroid
Inseob Kimde6b6892021-05-26 12:06:59 +0900104
Inseob Kim17d0db12021-06-09 14:30:47 +0900105 # TODO(b/185767624): change the hard-coded size?
106 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900107
Inseob Kimafd9dc02021-04-23 14:47:44 +0900108on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900109 mark_post_data
110
111 # We chown/chmod /data again so because mount is run as root + defaults
112 chown system system /data
113 chmod 0771 /data
114
115 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900116 restorecon /data
117
Inseob Kim17d0db12021-06-09 14:30:47 +0900118 mkdir /data/vendor 0771 root root
119 mkdir /data/vendor_ce 0771 root root
120 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900121 mkdir /data/vendor/hardware 0771 root root
122
123 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900124 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900125 mkdir /data/anr 0775 system system
126 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900127 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900128
129 start tombstoned
130
Inseob Kimde6b6892021-05-26 12:06:59 +0900131 # set up keystore directory structure first so that we can end early boot
132 # and start apexd
Inseob Kim17d0db12021-06-09 14:30:47 +0900133 mkdir /data/misc 01771 system misc
Inseob Kimde6b6892021-05-26 12:06:59 +0900134 mkdir /data/misc/keystore 0700 keystore keystore
135 # work around b/183668221
136 restorecon /data/misc /data/misc/keystore
137
138 # Boot level 30
139 # odsign signing keys have MAX_BOOT_LEVEL=30
140 # This is currently the earliest boot level, but we start at 30
141 # to leave room for earlier levels.
142 setprop keystore.boot_level 30
143
Inseob Kim87ba1f12021-04-27 14:56:05 +0900144 # For security reasons, /data/local/tmp should always be empty.
145 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900146 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900147 mkdir /data/local/tmp 0771 shell shell
148
Inseob Kimdc2af862021-02-17 15:51:56 +0900149service ueventd /system/bin/ueventd
150 class core
151 critical
152 seclabel u:r:ueventd:s0
153 shutdown critical
154
155service console /system/bin/sh
156 class core
157 console
158 disabled
159 user shell
160 group shell log readproc
161 seclabel u:r:shell:s0
162 setenv HOSTNAME console
163
Inseob Kimdc2af862021-02-17 15:51:56 +0900164on fs
165 write /dev/event-log-tags "# content owned by logd
166"
167 chown logd logd /dev/event-log-tags
168 chmod 0644 /dev/event-log-tags
169
170on property:sys.boot_completed=1
171 start logd-auditctl