blob: 50f7389f3480211b6a8dbce82d17093ffe860d2c [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
Jooyung Han16186d92021-06-01 17:53:28 +090051 start adbd
52
53 # TODO(b/186396070) microdroid_manager starts zipfuse if necessary
54 # TODO(b/186396070) move this before apexd for DICE derivation
55 start microdroid_manager
56
Inseob Kimdc2af862021-02-17 15:51:56 +090057on load_persist_props_action
58 start logd
59 start logd-reinit
60
61# Mount filesystems and start core system services.
62on late-init
63 trigger early-fs
64
65 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
66 # '--early' can be specified to skip entries with 'latemount'.
67 # /system and /vendor must be mounted by the end of the fs stage,
68 # while /data is optional.
69 trigger fs
70 trigger post-fs
71
72 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
73 # to only mount entries with 'latemount'. This is needed if '--early' is
74 # specified in the previous mount_all command on the fs stage.
75 # With /system mounted and properties form /system + /factory available,
76 # some services can be started.
77 trigger late-fs
78
Inseob Kimafd9dc02021-04-23 14:47:44 +090079 trigger post-fs-data
80
Inseob Kimdc2af862021-02-17 15:51:56 +090081 # Load persist properties and override properties (if enabled) from /data.
82 trigger load_persist_props_action
83
84 # Should be before netd, but after apex, properties and logging is available.
85 trigger load_bpf_programs
86
87 # Now we can start zygote for devices with file based encryption
88 trigger zygote-start
89
90 # Remove a file to wake up anything waiting for firmware.
91 trigger firmware_mounts_complete
92
93 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 Kim67ab4362021-05-11 16:51:03 +0900101on late-fs
102 mount_all /vendor/etc/fstab.microdroid --late
103
Inseob Kimafd9dc02021-04-23 14:47:44 +0900104on post-fs-data
Inseob Kim67ab4362021-05-11 16:51:03 +0900105 mark_post_data
106
107 # We chown/chmod /data again so because mount is run as root + defaults
108 chown system system /data
109 chmod 0771 /data
110
111 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900112 restorecon /data
113
Inseob Kimcd13c692021-04-23 15:56:33 +0900114 mkdir /data/vendor 0771 root root encryption=Require
115 mkdir /data/vendor_ce 0771 root root encryption=None
116 mkdir /data/vendor_de 0771 root root encryption=None
117 mkdir /data/vendor/hardware 0771 root root
118
119 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900120 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kimcd13c692021-04-23 15:56:33 +0900121 mkdir /data/anr 0775 system system encryption=Require
122 mkdir /data/tombstones 0771 system system encryption=Require
123 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900124
125 start tombstoned
126
Inseob Kim87ba1f12021-04-27 14:56:05 +0900127 # For security reasons, /data/local/tmp should always be empty.
128 # Do not place files or directories in /data/local/tmp
129 mkdir /data/local 0751 root root encryption=Require
130 mkdir /data/local/tmp 0771 shell shell
131
Inseob Kimdc2af862021-02-17 15:51:56 +0900132service ueventd /system/bin/ueventd
133 class core
134 critical
135 seclabel u:r:ueventd:s0
136 shutdown critical
137
138service console /system/bin/sh
139 class core
140 console
141 disabled
142 user shell
143 group shell log readproc
144 seclabel u:r:shell:s0
145 setenv HOSTNAME console
146
Inseob Kimdc2af862021-02-17 15:51:56 +0900147on fs
148 write /dev/event-log-tags "# content owned by logd
149"
150 chown logd logd /dev/event-log-tags
151 chmod 0644 /dev/event-log-tags
152
153on property:sys.boot_completed=1
154 start logd-auditctl
155