blob: 861b0321bef44f2a8deed8f38fe6b8c36ddabadd [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
32 exec_start derive_sdk
Inseob Kim870e76b2021-02-25 17:38:32 +090033
Jooyung Hand4a7a7a2021-06-17 13:05:36 +090034 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 +090035 mkdir /mnt/apk 0755 system system
36 start zipfuse
37
Inseob Kimdc2af862021-02-17 15:51:56 +090038on init
39 # Mount binderfs
40 mkdir /dev/binderfs
41 mount binder binder /dev/binderfs stats=global
42 chmod 0755 /dev/binderfs
43
44 symlink /dev/binderfs/binder /dev/binder
45 symlink /dev/binderfs/hwbinder /dev/hwbinder
46 symlink /dev/binderfs/vndbinder /dev/vndbinder
47
48 chmod 0666 /dev/binderfs/hwbinder
49 chmod 0666 /dev/binderfs/binder
50 chmod 0666 /dev/binderfs/vndbinder
51
52 # Start logd before any other services run to ensure we capture all of their logs.
53 start logd
54
55 start servicemanager
56
Inseob Kim8f095c92021-05-26 12:04:54 +090057 # TODO(b/185767624): remove hidl after full keymint support
58 start hwservicemanager
59
Jooyung Han16186d92021-06-01 17:53:28 +090060 start adbd
61
62 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
63 # TODO(b/186396070) move this before apexd for DICE derivation
64 start microdroid_manager
65
Inseob Kimdc2af862021-02-17 15:51:56 +090066on load_persist_props_action
67 start logd
68 start logd-reinit
69
70# Mount filesystems and start core system services.
71on late-init
72 trigger early-fs
73
74 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
75 # '--early' can be specified to skip entries with 'latemount'.
76 # /system and /vendor must be mounted by the end of the fs stage,
77 # while /data is optional.
78 trigger fs
79 trigger post-fs
80
81 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
82 # to only mount entries with 'latemount'. This is needed if '--early' is
83 # specified in the previous mount_all command on the fs stage.
84 # With /system mounted and properties form /system + /factory available,
85 # some services can be started.
86 trigger late-fs
87
Inseob Kimafd9dc02021-04-23 14:47:44 +090088 trigger post-fs-data
89
Inseob Kimdc2af862021-02-17 15:51:56 +090090 # Load persist properties and override properties (if enabled) from /data.
91 trigger load_persist_props_action
92
93 # Should be before netd, but after apex, properties and logging is available.
94 trigger load_bpf_programs
95
96 # Now we can start zygote for devices with file based encryption
97 trigger zygote-start
98
99 # Remove a file to wake up anything waiting for firmware.
100 trigger firmware_mounts_complete
101
102 trigger early-boot
103 trigger boot
104
105on 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
Inseob Kim17d0db12021-06-09 14:30:47 +0900115 # TODO(b/185767624): change the hard-coded size?
116 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900117
Inseob Kimafd9dc02021-04-23 14:47:44 +0900118on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900119 mark_post_data
120
121 # We chown/chmod /data again so because mount is run as root + defaults
122 chown system system /data
123 chmod 0771 /data
124
125 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900126 restorecon /data
127
Inseob Kim17d0db12021-06-09 14:30:47 +0900128 mkdir /data/vendor 0771 root root
129 mkdir /data/vendor_ce 0771 root root
130 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900131 mkdir /data/vendor/hardware 0771 root root
132
133 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900134 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900135 mkdir /data/anr 0775 system system
136 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900137 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900138
139 start tombstoned
140
Inseob Kimde6b6892021-05-26 12:06:59 +0900141 # set up keystore directory structure first so that we can end early boot
142 # and start apexd
Inseob Kim17d0db12021-06-09 14:30:47 +0900143 mkdir /data/misc 01771 system misc
Inseob Kimde6b6892021-05-26 12:06:59 +0900144 mkdir /data/misc/keystore 0700 keystore keystore
145 # work around b/183668221
146 restorecon /data/misc /data/misc/keystore
147
148 # Boot level 30
149 # odsign signing keys have MAX_BOOT_LEVEL=30
150 # This is currently the earliest boot level, but we start at 30
151 # to leave room for earlier levels.
152 setprop keystore.boot_level 30
153
Inseob Kim87ba1f12021-04-27 14:56:05 +0900154 # For security reasons, /data/local/tmp should always be empty.
155 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900156 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900157 mkdir /data/local/tmp 0771 shell shell
158
Inseob Kimdc2af862021-02-17 15:51:56 +0900159service ueventd /system/bin/ueventd
160 class core
161 critical
162 seclabel u:r:ueventd:s0
163 shutdown critical
164
165service console /system/bin/sh
166 class core
167 console
168 disabled
169 user shell
170 group shell log readproc
171 seclabel u:r:shell:s0
172 setenv HOSTNAME console
173
Inseob Kimdc2af862021-02-17 15:51:56 +0900174on fs
175 write /dev/event-log-tags "# content owned by logd
176"
177 chown logd logd /dev/event-log-tags
178 chmod 0644 /dev/event-log-tags
179
180on property:sys.boot_completed=1
181 start logd-auditctl