blob: 2b4295f19502cfbf1f8287989dbbb0e69c8d76d3 [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 Hanc36b18a2021-04-20 03:33:36 +090018 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090019
Jiyong Park419957e2022-09-08 22:28:51 +090020# If VM is debuggable, send logs to outside ot the VM via the serial console.
21# If non-debuggable, logs are internally consumed at /dev/null
22on early-init && property:ro.boot.microdroid.app_debuggable=1
23 setprop ro.log.file_logger.path /dev/hvc2
24
25on early-init && property:ro.boot.microdroid.app_debuggable=0
26 setprop ro.log.file_logger.path /dev/null
27
Inseob Kimdc2af862021-02-17 15:51:56 +090028on init
29 # Mount binderfs
30 mkdir /dev/binderfs
31 mount binder binder /dev/binderfs stats=global
32 chmod 0755 /dev/binderfs
33
34 symlink /dev/binderfs/binder /dev/binder
Inseob Kimdc2af862021-02-17 15:51:56 +090035 symlink /dev/binderfs/vndbinder /dev/vndbinder
36
Inseob Kimdc2af862021-02-17 15:51:56 +090037 chmod 0666 /dev/binderfs/binder
38 chmod 0666 /dev/binderfs/vndbinder
39
Jiyong Park858c0402021-07-15 16:19:11 +090040 # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean
41 # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started
42 # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little
43 # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset.
44 mkdir /dev/cpuset/foreground
45 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
46 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
47 mkdir /dev/cpuset/background
48 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
49 copy /dev/cpuset/mems /dev/cpuset/background/mems
50 mkdir /dev/cpuset/system-background
51 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
52 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
53
54 chown system system /dev/cpuset
55 chown system system /dev/cpuset/foreground
56 chown system system /dev/cpuset/background
57 chown system system /dev/cpuset/system-background
58 chown system system /dev/cpuset/tasks
59 chown system system /dev/cpuset/foreground/tasks
60 chown system system /dev/cpuset/background/tasks
61 chown system system /dev/cpuset/system-background/tasks
62
63 chmod 0664 /dev/cpuset/tasks
64 chmod 0664 /dev/cpuset/foreground/tasks
65 chmod 0664 /dev/cpuset/background/tasks
66 chmod 0664 /dev/cpuset/system-background/tasks
67
Inseob Kimdc2af862021-02-17 15:51:56 +090068 start servicemanager
69
Inseob Kim4de509a2022-07-04 19:29:33 +090070on init
Jiyong Parkc5166842022-01-21 12:54:57 +090071 mkdir /mnt/apk 0755 system system
72 mkdir /mnt/extra-apk 0755 root root
73 # Microdroid_manager starts apkdmverity/zipfuse/apexd
74 start microdroid_manager
75
76 # restorecon so microdroid_manager can create subdirectories
77 restorecon /mnt/extra-apk
78
79 # Wait for apexd to finish activating APEXes before starting more processes.
80 wait_for_prop apexd.status activated
81 perform_apex_config
82
83 # Notify to microdroid_manager that perform_apex_config is done.
84 # Microdroid_manager shouldn't execute payload before this, because app
85 # payloads are not designed to run with bootstrap bionic
86 setprop apex_config.done true
87
88 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
89
Jiyong Park5bd24822022-08-23 14:50:29 +090090on property:dev.bootcomplete=1
91 # Stop ueventd to save memory
92 stop ueventd
93
Oleg Matcovschi98739482022-03-14 06:29:25 -070094on init && property:ro.boot.microdroid.debuggable=1
95 # Mount tracefs (with GID=AID_READTRACEFS)
96 mount tracefs tracefs /sys/kernel/tracing gid=3012
97
Jiyong Parke7407e22021-10-18 15:51:59 +090098on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090099 start adbd
100
Inseob Kimdc2af862021-02-17 15:51:56 +0900101# Mount filesystems and start core system services.
102on late-init
103 trigger early-fs
104
105 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
106 # '--early' can be specified to skip entries with 'latemount'.
107 # /system and /vendor must be mounted by the end of the fs stage,
108 # while /data is optional.
109 trigger fs
110 trigger post-fs
111
112 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
113 # to only mount entries with 'latemount'. This is needed if '--early' is
114 # specified in the previous mount_all command on the fs stage.
115 # With /system mounted and properties form /system + /factory available,
116 # some services can be started.
117 trigger late-fs
118
Inseob Kimafd9dc02021-04-23 14:47:44 +0900119 trigger post-fs-data
120
Inseob Kimdc2af862021-02-17 15:51:56 +0900121 # Load persist properties and override properties (if enabled) from /data.
122 trigger load_persist_props_action
123
Inseob Kimdc2af862021-02-17 15:51:56 +0900124 trigger early-boot
125 trigger boot
126
127on post-fs
128 # Once everything is setup, no need to modify /.
129 # The bind+remount combination allows this to work in containers.
130 mount rootfs rootfs / remount bind ro nodev
131
Inseob Kim17d0db12021-06-09 14:30:47 +0900132 # TODO(b/185767624): change the hard-coded size?
133 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900134
Inseob Kim67ab4362021-05-11 16:51:03 +0900135 # We chown/chmod /data again so because mount is run as root + defaults
136 chown system system /data
137 chmod 0771 /data
138
139 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900140 restorecon /data
141
Andrew Scull195354c2022-01-27 16:12:04 +0000142 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000143 # and start apexd
144 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000145 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000146 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000147
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700148 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700149
Oleg Matcovschi98739482022-03-14 06:29:25 -0700150on late-fs && property:ro.debuggable=1
151 # Ensure that tracefs has the correct permissions.
152 # This does not work correctly if it is called in post-fs.
153 chmod 0755 /sys/kernel/tracing
154 chmod 0755 /sys/kernel/debug/tracing
155
Inseob Kima920f9e2021-08-04 03:33:43 +0000156on post-fs-data
157 mark_post_data
158
Inseob Kim17d0db12021-06-09 14:30:47 +0900159 mkdir /data/vendor 0771 root root
160 mkdir /data/vendor_ce 0771 root root
161 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900162 mkdir /data/vendor/hardware 0771 root root
163
164 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900165 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900166 mkdir /data/anr 0775 system system
167 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900168 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900169
170 start tombstoned
171
Inseob Kim87ba1f12021-04-27 14:56:05 +0900172 # For security reasons, /data/local/tmp should always be empty.
173 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900174 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900175 mkdir /data/local/tmp 0771 shell shell
176
Shikha Panwarc29d24b2022-05-25 13:48:40 +0000177service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100178 user system
Shikha Panwar7afc1392022-03-24 08:54:43 +0000179 group system
Inseob Kimcd9c1dd2022-07-13 17:13:45 +0900180 shutdown critical
Shikha Panwar7afc1392022-03-24 08:54:43 +0000181
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900182service apexd-vm /system/bin/apexd --vm
183 user root
184 group system
185 oneshot
186 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100187 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900188
Inseob Kimdc2af862021-02-17 15:51:56 +0900189service ueventd /system/bin/ueventd
190 class core
191 critical
192 seclabel u:r:ueventd:s0
193 shutdown critical
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100194 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER FSETID MKNOD NET_ADMIN SETGID SETUID SYS_MODULE SYS_RAWIO
Inseob Kimdc2af862021-02-17 15:51:56 +0900195
196service console /system/bin/sh
197 class core
198 console
199 disabled
200 user shell
201 group shell log readproc
202 seclabel u:r:shell:s0
203 setenv HOSTNAME console
204