blob: 4410b828c697c87e6f6028e7d33e4620cf06973e [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
Inseob Kimdc2af862021-02-17 15:51:56 +090093 trigger early-boot
94 trigger boot
95
96on post-fs
97 # Once everything is setup, no need to modify /.
98 # The bind+remount combination allows this to work in containers.
99 mount rootfs rootfs / remount bind ro nodev
100
Inseob Kimde6b6892021-05-26 12:06:59 +0900101 start keystore2
102
Inseob Kim67ab4362021-05-11 16:51:03 +0900103on late-fs
Inseob Kimde6b6892021-05-26 12:06:59 +0900104 start vendor.keymint-default
105
Inseob Kim17d0db12021-06-09 14:30:47 +0900106 # TODO(b/185767624): change the hard-coded size?
107 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900108
Inseob Kimafd9dc02021-04-23 14:47:44 +0900109on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900110 mark_post_data
111
112 # We chown/chmod /data again so because mount is run as root + defaults
113 chown system system /data
114 chmod 0771 /data
115
116 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900117 restorecon /data
118
Inseob Kim17d0db12021-06-09 14:30:47 +0900119 mkdir /data/vendor 0771 root root
120 mkdir /data/vendor_ce 0771 root root
121 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900122 mkdir /data/vendor/hardware 0771 root root
123
124 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900125 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900126 mkdir /data/anr 0775 system system
127 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900128 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900129
130 start tombstoned
131
Inseob Kimde6b6892021-05-26 12:06:59 +0900132 # set up keystore directory structure first so that we can end early boot
133 # and start apexd
Inseob Kim17d0db12021-06-09 14:30:47 +0900134 mkdir /data/misc 01771 system misc
Inseob Kimde6b6892021-05-26 12:06:59 +0900135 mkdir /data/misc/keystore 0700 keystore keystore
136 # work around b/183668221
137 restorecon /data/misc /data/misc/keystore
138
139 # Boot level 30
140 # odsign signing keys have MAX_BOOT_LEVEL=30
141 # This is currently the earliest boot level, but we start at 30
142 # to leave room for earlier levels.
143 setprop keystore.boot_level 30
144
Inseob Kim87ba1f12021-04-27 14:56:05 +0900145 # For security reasons, /data/local/tmp should always be empty.
146 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900147 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900148 mkdir /data/local/tmp 0771 shell shell
149
Inseob Kimdc2af862021-02-17 15:51:56 +0900150service ueventd /system/bin/ueventd
151 class core
152 critical
153 seclabel u:r:ueventd:s0
154 shutdown critical
155
156service console /system/bin/sh
157 class core
158 console
159 disabled
160 user shell
161 group shell log readproc
162 seclabel u:r:shell:s0
163 setenv HOSTNAME console
164
Inseob Kimdc2af862021-02-17 15:51:56 +0900165on fs
166 write /dev/event-log-tags "# content owned by logd
167"
168 chown logd logd /dev/event-log-tags
169 chmod 0644 /dev/event-log-tags
170
171on property:sys.boot_completed=1
172 start logd-auditctl