blob: 71d7fe5e71d4a8429a00a24e5d58cce128f50d61 [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
Inseob Kim4de509a2022-07-04 19:29:33 +090040on init
Jiyong Parkc5166842022-01-21 12:54:57 +090041 mkdir /mnt/apk 0755 system system
42 mkdir /mnt/extra-apk 0755 root root
43 # Microdroid_manager starts apkdmverity/zipfuse/apexd
44 start microdroid_manager
45
46 # restorecon so microdroid_manager can create subdirectories
47 restorecon /mnt/extra-apk
48
49 # Wait for apexd to finish activating APEXes before starting more processes.
50 wait_for_prop apexd.status activated
51 perform_apex_config
52
53 # Notify to microdroid_manager that perform_apex_config is done.
54 # Microdroid_manager shouldn't execute payload before this, because app
55 # payloads are not designed to run with bootstrap bionic
56 setprop apex_config.done true
57
58 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
59
Jiyong Park5bd24822022-08-23 14:50:29 +090060on property:dev.bootcomplete=1
61 # Stop ueventd to save memory
62 stop ueventd
63
Oleg Matcovschi98739482022-03-14 06:29:25 -070064on init && property:ro.boot.microdroid.debuggable=1
65 # Mount tracefs (with GID=AID_READTRACEFS)
66 mount tracefs tracefs /sys/kernel/tracing gid=3012
67
Jiyong Parke7407e22021-10-18 15:51:59 +090068on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090069 start adbd
70
Inseob Kimdc2af862021-02-17 15:51:56 +090071# Mount filesystems and start core system services.
72on late-init
73 trigger early-fs
74
75 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
76 # '--early' can be specified to skip entries with 'latemount'.
77 # /system and /vendor must be mounted by the end of the fs stage,
78 # while /data is optional.
79 trigger fs
80 trigger post-fs
81
82 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
83 # to only mount entries with 'latemount'. This is needed if '--early' is
84 # specified in the previous mount_all command on the fs stage.
85 # With /system mounted and properties form /system + /factory available,
86 # some services can be started.
87 trigger late-fs
88
Inseob Kimafd9dc02021-04-23 14:47:44 +090089 trigger post-fs-data
90
Inseob Kimdc2af862021-02-17 15:51:56 +090091 # Load persist properties and override properties (if enabled) from /data.
92 trigger load_persist_props_action
93
Inseob Kimdc2af862021-02-17 15:51:56 +090094 trigger early-boot
95 trigger boot
96
97on post-fs
98 # Once everything is setup, no need to modify /.
99 # The bind+remount combination allows this to work in containers.
100 mount rootfs rootfs / remount bind ro nodev
101
Inseob Kim17d0db12021-06-09 14:30:47 +0900102 # TODO(b/185767624): change the hard-coded size?
103 mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900104
Inseob Kim67ab4362021-05-11 16:51:03 +0900105 # We chown/chmod /data again so because mount is run as root + defaults
106 chown system system /data
107 chmod 0771 /data
108
109 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900110 restorecon /data
111
Andrew Scull195354c2022-01-27 16:12:04 +0000112 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000113 # and start apexd
114 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000115 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000116 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000117
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700118 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700119
Oleg Matcovschi98739482022-03-14 06:29:25 -0700120on late-fs && property:ro.debuggable=1
121 # Ensure that tracefs has the correct permissions.
122 # This does not work correctly if it is called in post-fs.
123 chmod 0755 /sys/kernel/tracing
124 chmod 0755 /sys/kernel/debug/tracing
125
Inseob Kima920f9e2021-08-04 03:33:43 +0000126on post-fs-data
127 mark_post_data
128
Inseob Kim17d0db12021-06-09 14:30:47 +0900129 mkdir /data/vendor 0771 root root
130 mkdir /data/vendor_ce 0771 root root
131 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900132 mkdir /data/vendor/hardware 0771 root root
133
134 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900135 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900136 mkdir /data/anr 0775 system system
137 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900138 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900139
140 start tombstoned
141
Inseob Kim87ba1f12021-04-27 14:56:05 +0900142 # For security reasons, /data/local/tmp should always be empty.
143 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900144 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900145 mkdir /data/local/tmp 0771 shell shell
146
Shikha Panwarc29d24b2022-05-25 13:48:40 +0000147service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100148 user system
Shikha Panwar7afc1392022-03-24 08:54:43 +0000149 group system
Inseob Kimcd9c1dd2022-07-13 17:13:45 +0900150 shutdown critical
Shikha Panwar7afc1392022-03-24 08:54:43 +0000151
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900152service apexd-vm /system/bin/apexd --vm
153 user root
154 group system
155 oneshot
156 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100157 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900158
Inseob Kimdc2af862021-02-17 15:51:56 +0900159service ueventd /system/bin/ueventd
160 class core
161 critical
162 seclabel u:r:ueventd:s0
163 shutdown critical
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100164 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 +0900165
166service console /system/bin/sh
167 class core
168 console
169 disabled
170 user shell
171 group shell log readproc
172 seclabel u:r:shell:s0
173 setenv HOSTNAME console
174