blob: 2385d8fdb6946c413ba4e02bfafaa2acf4905f1e [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
102on post-fs
103 # Once everything is setup, no need to modify /.
104 # The bind+remount combination allows this to work in containers.
105 mount rootfs rootfs / remount bind ro nodev
106
Inseob Kimde6b6892021-05-26 12:06:59 +0900107 start keystore2
108
Inseob Kim67ab4362021-05-11 16:51:03 +0900109on late-fs
Inseob Kimde6b6892021-05-26 12:06:59 +0900110 start vendor.keymint-default
111
112 exec_start wait_for_keymaster
113
Inseob Kim17d0db12021-06-09 14:30:47 +0900114 # TODO(b/185767624): change the hard-coded size?
115 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900116
Inseob Kimafd9dc02021-04-23 14:47:44 +0900117on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900118 mark_post_data
119
120 # We chown/chmod /data again so because mount is run as root + defaults
121 chown system system /data
122 chmod 0771 /data
123
124 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900125 restorecon /data
126
Inseob Kim17d0db12021-06-09 14:30:47 +0900127 mkdir /data/vendor 0771 root root
128 mkdir /data/vendor_ce 0771 root root
129 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900130 mkdir /data/vendor/hardware 0771 root root
131
132 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900133 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900134 mkdir /data/anr 0775 system system
135 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900136 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900137
138 start tombstoned
139
Inseob Kimde6b6892021-05-26 12:06:59 +0900140 # set up keystore directory structure first so that we can end early boot
141 # and start apexd
Inseob Kim17d0db12021-06-09 14:30:47 +0900142 mkdir /data/misc 01771 system misc
Inseob Kimde6b6892021-05-26 12:06:59 +0900143 mkdir /data/misc/keystore 0700 keystore keystore
144 # work around b/183668221
145 restorecon /data/misc /data/misc/keystore
146
147 # Boot level 30
148 # odsign signing keys have MAX_BOOT_LEVEL=30
149 # This is currently the earliest boot level, but we start at 30
150 # to leave room for earlier levels.
151 setprop keystore.boot_level 30
152
Inseob Kim87ba1f12021-04-27 14:56:05 +0900153 # For security reasons, /data/local/tmp should always be empty.
154 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900155 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900156 mkdir /data/local/tmp 0771 shell shell
157
Inseob Kimdc2af862021-02-17 15:51:56 +0900158service ueventd /system/bin/ueventd
159 class core
160 critical
161 seclabel u:r:ueventd:s0
162 shutdown critical
163
164service console /system/bin/sh
165 class core
166 console
167 disabled
168 user shell
169 group shell log readproc
170 seclabel u:r:shell:s0
171 setenv HOSTNAME console
172
Inseob Kimdc2af862021-02-17 15:51:56 +0900173on fs
174 write /dev/event-log-tags "# content owned by logd
175"
176 chown logd logd /dev/event-log-tags
177 chmod 0644 /dev/event-log-tags
178
179on property:sys.boot_completed=1
180 start logd-auditctl