blob: 7d04557f557c9462c85851940c7e4795e38a010a [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
Jiyong Parkc5166842022-01-21 12:54:57 +090029 mkdir /mnt/apk 0755 system system
30 mkdir /mnt/extra-apk 0755 root root
31 # Microdroid_manager starts apkdmverity/zipfuse/apexd
32 start microdroid_manager
33
34 # restorecon so microdroid_manager can create subdirectories
35 restorecon /mnt/extra-apk
36
37 # Wait for apexd to finish activating APEXes before starting more processes.
38 wait_for_prop apexd.status activated
39 perform_apex_config
40
41 # Notify to microdroid_manager that perform_apex_config is done.
42 # Microdroid_manager shouldn't execute payload before this, because app
43 # payloads are not designed to run with bootstrap bionic
44 setprop apex_config.done true
45
46 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
47
Jiyong Park5bd24822022-08-23 14:50:29 +090048on property:dev.bootcomplete=1
49 # Stop ueventd to save memory
50 stop ueventd
51
Oleg Matcovschi98739482022-03-14 06:29:25 -070052on init && property:ro.boot.microdroid.debuggable=1
53 # Mount tracefs (with GID=AID_READTRACEFS)
54 mount tracefs tracefs /sys/kernel/tracing gid=3012
55
Jiyong Parke7407e22021-10-18 15:51:59 +090056on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090057 start adbd
58
Inseob Kimdc2af862021-02-17 15:51:56 +090059# Mount filesystems and start core system services.
60on late-init
61 trigger early-fs
62
63 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
64 # '--early' can be specified to skip entries with 'latemount'.
65 # /system and /vendor must be mounted by the end of the fs stage,
66 # while /data is optional.
67 trigger fs
68 trigger post-fs
69
70 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
71 # to only mount entries with 'latemount'. This is needed if '--early' is
72 # specified in the previous mount_all command on the fs stage.
73 # With /system mounted and properties form /system + /factory available,
74 # some services can be started.
75 trigger late-fs
76
Nikita Ioffe57bc8d72022-11-27 00:50:50 +000077 # Wait for microdroid_manager to finish setting up sysprops from the payload config.
78 # Some further actions in the boot sequence might depend on the sysprops from the payloag,
79 # e.g. microdroid.config.enable_authfs configures whether to run authfs_service after
80 # /data is mounted.
81 wait_for_prop microdroid_manager.config_done 1
82
Inseob Kimafd9dc02021-04-23 14:47:44 +090083 trigger post-fs-data
84
Inseob Kimdc2af862021-02-17 15:51:56 +090085 # Load persist properties and override properties (if enabled) from /data.
86 trigger load_persist_props_action
87
Inseob Kimdc2af862021-02-17 15:51:56 +090088 trigger early-boot
89 trigger boot
90
91on post-fs
92 # Once everything is setup, no need to modify /.
93 # The bind+remount combination allows this to work in containers.
94 mount rootfs rootfs / remount bind ro nodev
95
Inseob Kim17d0db12021-06-09 14:30:47 +090096 # TODO(b/185767624): change the hard-coded size?
97 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +090098
Inseob Kim67ab4362021-05-11 16:51:03 +090099 # We chown/chmod /data again so because mount is run as root + defaults
100 chown system system /data
101 chmod 0771 /data
102
103 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900104 restorecon /data
105
Andrew Scull195354c2022-01-27 16:12:04 +0000106 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000107 # and start apexd
108 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000109 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000110 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000111
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700112 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700113
Oleg Matcovschi98739482022-03-14 06:29:25 -0700114on late-fs && property:ro.debuggable=1
115 # Ensure that tracefs has the correct permissions.
116 # This does not work correctly if it is called in post-fs.
117 chmod 0755 /sys/kernel/tracing
118 chmod 0755 /sys/kernel/debug/tracing
119
Inseob Kima920f9e2021-08-04 03:33:43 +0000120on post-fs-data
121 mark_post_data
122
Inseob Kim17d0db12021-06-09 14:30:47 +0900123 mkdir /data/vendor 0771 root root
124 mkdir /data/vendor_ce 0771 root root
125 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900126 mkdir /data/vendor/hardware 0771 root root
127
128 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900129 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900130 mkdir /data/anr 0775 system system
131 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900132 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900133
134 start tombstoned
135
Inseob Kim87ba1f12021-04-27 14:56:05 +0900136 # For security reasons, /data/local/tmp should always be empty.
137 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900138 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900139 mkdir /data/local/tmp 0771 shell shell
140
Nikita Ioffe57bc8d72022-11-27 00:50:50 +0000141on post-fs-data && property:microdroid_manager.authfs.enabled=1
142 start authfs_service
143
144on boot
145 # Mark boot completed. This will notify microdroid_manager to run payload.
146 setprop dev.bootcomplete 1
147
Shikha Panwarc29d24b2022-05-25 13:48:40 +0000148service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100149 user system
Shikha Panwar7afc1392022-03-24 08:54:43 +0000150 group system
Inseob Kimcd9c1dd2022-07-13 17:13:45 +0900151 shutdown critical
Shikha Panwar7afc1392022-03-24 08:54:43 +0000152
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900153service apexd-vm /system/bin/apexd --vm
154 user root
155 group system
156 oneshot
157 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100158 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900159
Inseob Kimdc2af862021-02-17 15:51:56 +0900160service ueventd /system/bin/ueventd
161 class core
162 critical
163 seclabel u:r:ueventd:s0
164 shutdown critical
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100165 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 +0900166
167service console /system/bin/sh
168 class core
169 console
170 disabled
171 user shell
172 group shell log readproc
173 seclabel u:r:shell:s0
174 setenv HOSTNAME console
175