blob: 68024e5b084fa8cce75dc7542976ba3891d8d5db [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
Jooyung Han16186d92021-06-01 17:53:28 +090015 # in microdroid, we don't use "bootstrap" mount namespace
16 # because APEXes are passed from host and are available
17 # from the start. We don't need to wait till /data is ready.
18 enter_default_mount_ns
Jooyung Hanc36b18a2021-04-20 03:33:36 +090019
20 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090021
Jooyung Han16186d92021-06-01 17:53:28 +090022 # Exec apexd in the VM mode to avoid unnecessary overhead of normal mode.
23 # (e.g. session management)
24 exec - root system -- /system/bin/apexd --vm
Inseob Kimdc2af862021-02-17 15:51:56 +090025
Jooyung Han16186d92021-06-01 17:53:28 +090026 perform_apex_config
27 exec_start derive_sdk
Inseob Kim870e76b2021-02-25 17:38:32 +090028
Jiyong Park9abfc1f2021-05-17 21:57:24 +090029 mkdir /mnt/apk 0755 system system
30 start zipfuse
31
Inseob Kimdc2af862021-02-17 15:51:56 +090032on init
33 # Mount binderfs
34 mkdir /dev/binderfs
35 mount binder binder /dev/binderfs stats=global
36 chmod 0755 /dev/binderfs
37
38 symlink /dev/binderfs/binder /dev/binder
39 symlink /dev/binderfs/hwbinder /dev/hwbinder
40 symlink /dev/binderfs/vndbinder /dev/vndbinder
41
42 chmod 0666 /dev/binderfs/hwbinder
43 chmod 0666 /dev/binderfs/binder
44 chmod 0666 /dev/binderfs/vndbinder
45
46 # Start logd before any other services run to ensure we capture all of their logs.
47 start logd
48
49 start servicemanager
50
Inseob Kim8f095c92021-05-26 12:04:54 +090051 # TODO(b/185767624): remove hidl after full keymint support
52 start hwservicemanager
53
Jooyung Han16186d92021-06-01 17:53:28 +090054 start adbd
55
56 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
57 # TODO(b/186396070) move this before apexd for DICE derivation
58 start microdroid_manager
59
Inseob Kimdc2af862021-02-17 15:51:56 +090060on load_persist_props_action
61 start logd
62 start logd-reinit
63
64# Mount filesystems and start core system services.
65on late-init
66 trigger early-fs
67
68 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
69 # '--early' can be specified to skip entries with 'latemount'.
70 # /system and /vendor must be mounted by the end of the fs stage,
71 # while /data is optional.
72 trigger fs
73 trigger post-fs
74
75 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
76 # to only mount entries with 'latemount'. This is needed if '--early' is
77 # specified in the previous mount_all command on the fs stage.
78 # With /system mounted and properties form /system + /factory available,
79 # some services can be started.
80 trigger late-fs
81
Inseob Kimafd9dc02021-04-23 14:47:44 +090082 trigger post-fs-data
83
Inseob Kimdc2af862021-02-17 15:51:56 +090084 # Load persist properties and override properties (if enabled) from /data.
85 trigger load_persist_props_action
86
87 # Should be before netd, but after apex, properties and logging is available.
88 trigger load_bpf_programs
89
90 # Now we can start zygote for devices with file based encryption
91 trigger zygote-start
92
93 # Remove a file to wake up anything waiting for firmware.
94 trigger firmware_mounts_complete
95
96 trigger early-boot
97 trigger boot
98
99on post-fs
100 # Once everything is setup, no need to modify /.
101 # The bind+remount combination allows this to work in containers.
102 mount rootfs rootfs / remount bind ro nodev
103
Inseob Kim67ab4362021-05-11 16:51:03 +0900104on late-fs
105 mount_all /vendor/etc/fstab.microdroid --late
106
Inseob Kimafd9dc02021-04-23 14:47:44 +0900107on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900108 mark_post_data
109
110 # We chown/chmod /data again so because mount is run as root + defaults
111 chown system system /data
112 chmod 0771 /data
113
114 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900115 restorecon /data
116
Inseob Kimcd13c692021-04-23 15:56:33 +0900117 mkdir /data/vendor 0771 root root encryption=Require
118 mkdir /data/vendor_ce 0771 root root encryption=None
119 mkdir /data/vendor_de 0771 root root encryption=None
120 mkdir /data/vendor/hardware 0771 root root
121
122 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900123 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kimcd13c692021-04-23 15:56:33 +0900124 mkdir /data/anr 0775 system system encryption=Require
125 mkdir /data/tombstones 0771 system system encryption=Require
126 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900127
128 start tombstoned
129
Inseob Kim87ba1f12021-04-27 14:56:05 +0900130 # For security reasons, /data/local/tmp should always be empty.
131 # Do not place files or directories in /data/local/tmp
132 mkdir /data/local 0751 root root encryption=Require
133 mkdir /data/local/tmp 0771 shell shell
134
Inseob Kimdc2af862021-02-17 15:51:56 +0900135service ueventd /system/bin/ueventd
136 class core
137 critical
138 seclabel u:r:ueventd:s0
139 shutdown critical
140
141service console /system/bin/sh
142 class core
143 console
144 disabled
145 user shell
146 group shell log readproc
147 seclabel u:r:shell:s0
148 setenv HOSTNAME console
149
Inseob Kimdc2af862021-02-17 15:51:56 +0900150on fs
151 write /dev/event-log-tags "# content owned by logd
152"
153 chown logd logd /dev/event-log-tags
154 chmod 0644 /dev/event-log-tags
155
156on property:sys.boot_completed=1
157 start logd-auditctl
158