Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 1 | # 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 | |
| 11 | import /init.environ.rc |
| 12 | |
| 13 | # Cgroups are mounted right before early-init using list from /etc/cgroups.json |
| 14 | on early-init |
Inseob Kim | de6b689 | 2021-05-26 12:06:59 +0900 | [diff] [blame] | 15 | # set RLIMIT_NICE to allow priorities from 19 to -20 |
| 16 | setrlimit nice 40 40 |
| 17 | |
Jooyung Han | c36b18a | 2021-04-20 03:33:36 +0900 | [diff] [blame] | 18 | start ueventd |
Inseob Kim | 870e76b | 2021-02-25 17:38:32 +0900 | [diff] [blame] | 19 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 20 | on init |
| 21 | # Mount binderfs |
| 22 | mkdir /dev/binderfs |
| 23 | mount binder binder /dev/binderfs stats=global |
| 24 | chmod 0755 /dev/binderfs |
| 25 | |
| 26 | symlink /dev/binderfs/binder /dev/binder |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 27 | symlink /dev/binderfs/vndbinder /dev/vndbinder |
| 28 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 29 | chmod 0666 /dev/binderfs/binder |
| 30 | chmod 0666 /dev/binderfs/vndbinder |
| 31 | |
Jiyong Park | 858c040 | 2021-07-15 16:19:11 +0900 | [diff] [blame] | 32 | # Prepare cpusets that are pre-defined by Android. Inside Microdroid, these however don't mean |
| 33 | # much because the mapping from vCPUs to physical CPUs are quite flexible; a VM can be started |
| 34 | # with any number of vCPUs and we in general can't be sure that vCPU N is a big core or a little |
| 35 | # core. These nodes are provided just to satisfy the code which puts a PID to a specific cpuset. |
| 36 | mkdir /dev/cpuset/foreground |
| 37 | copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus |
| 38 | copy /dev/cpuset/mems /dev/cpuset/foreground/mems |
| 39 | mkdir /dev/cpuset/background |
| 40 | copy /dev/cpuset/cpus /dev/cpuset/background/cpus |
| 41 | copy /dev/cpuset/mems /dev/cpuset/background/mems |
| 42 | mkdir /dev/cpuset/system-background |
| 43 | copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus |
| 44 | copy /dev/cpuset/mems /dev/cpuset/system-background/mems |
| 45 | |
| 46 | chown system system /dev/cpuset |
| 47 | chown system system /dev/cpuset/foreground |
| 48 | chown system system /dev/cpuset/background |
| 49 | chown system system /dev/cpuset/system-background |
| 50 | chown system system /dev/cpuset/tasks |
| 51 | chown system system /dev/cpuset/foreground/tasks |
| 52 | chown system system /dev/cpuset/background/tasks |
| 53 | chown system system /dev/cpuset/system-background/tasks |
| 54 | |
| 55 | chmod 0664 /dev/cpuset/tasks |
| 56 | chmod 0664 /dev/cpuset/foreground/tasks |
| 57 | chmod 0664 /dev/cpuset/background/tasks |
| 58 | chmod 0664 /dev/cpuset/system-background/tasks |
| 59 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 60 | start servicemanager |
| 61 | |
Andrew Scull | f819594 | 2022-01-13 17:37:52 +0000 | [diff] [blame] | 62 | start vendor.dice-microdroid |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 63 | start diced |
| 64 | |
Inseob Kim | 4de509a | 2022-07-04 19:29:33 +0900 | [diff] [blame] | 65 | on init && property:ro.boot.logd.enabled=1 |
| 66 | # Start logd before any other services run to ensure we capture all of their logs. |
| 67 | # TODO(b/217796229) set filterspec if debug_level is app_only |
| 68 | start logd |
| 69 | start seriallogging |
| 70 | |
| 71 | on init |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 72 | mkdir /mnt/apk 0755 system system |
| 73 | mkdir /mnt/extra-apk 0755 root root |
| 74 | # Microdroid_manager starts apkdmverity/zipfuse/apexd |
| 75 | start microdroid_manager |
| 76 | |
| 77 | # restorecon so microdroid_manager can create subdirectories |
| 78 | restorecon /mnt/extra-apk |
| 79 | |
| 80 | # Wait for apexd to finish activating APEXes before starting more processes. |
| 81 | wait_for_prop apexd.status activated |
| 82 | perform_apex_config |
| 83 | |
| 84 | # Notify to microdroid_manager that perform_apex_config is done. |
| 85 | # Microdroid_manager shouldn't execute payload before this, because app |
| 86 | # payloads are not designed to run with bootstrap bionic |
| 87 | setprop apex_config.done true |
| 88 | |
| 89 | setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0} |
| 90 | |
Oleg Matcovschi | 9873948 | 2022-03-14 06:29:25 -0700 | [diff] [blame] | 91 | on init && property:ro.boot.microdroid.debuggable=1 |
| 92 | # Mount tracefs (with GID=AID_READTRACEFS) |
| 93 | mount tracefs tracefs /sys/kernel/tracing gid=3012 |
| 94 | |
Jiyong Park | e7407e2 | 2021-10-18 15:51:59 +0900 | [diff] [blame] | 95 | on init && property:ro.boot.adb.enabled=1 |
Jooyung Han | 16186d9 | 2021-06-01 17:53:28 +0900 | [diff] [blame] | 96 | start adbd |
| 97 | |
Jiyong Park | 779daa9 | 2021-10-18 18:33:28 +0900 | [diff] [blame] | 98 | on load_persist_props_action && property:ro.boot.logd.enabled=1 |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 99 | start logd |
| 100 | start logd-reinit |
| 101 | |
| 102 | # Mount filesystems and start core system services. |
| 103 | on late-init |
| 104 | trigger early-fs |
| 105 | |
| 106 | # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter |
| 107 | # '--early' can be specified to skip entries with 'latemount'. |
| 108 | # /system and /vendor must be mounted by the end of the fs stage, |
| 109 | # while /data is optional. |
| 110 | trigger fs |
| 111 | trigger post-fs |
| 112 | |
| 113 | # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter |
| 114 | # to only mount entries with 'latemount'. This is needed if '--early' is |
| 115 | # specified in the previous mount_all command on the fs stage. |
| 116 | # With /system mounted and properties form /system + /factory available, |
| 117 | # some services can be started. |
| 118 | trigger late-fs |
| 119 | |
Inseob Kim | afd9dc0 | 2021-04-23 14:47:44 +0900 | [diff] [blame] | 120 | trigger post-fs-data |
| 121 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 122 | # Load persist properties and override properties (if enabled) from /data. |
| 123 | trigger load_persist_props_action |
| 124 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 125 | trigger early-boot |
| 126 | trigger boot |
| 127 | |
| 128 | on post-fs |
| 129 | # Once everything is setup, no need to modify /. |
| 130 | # The bind+remount combination allows this to work in containers. |
| 131 | mount rootfs rootfs / remount bind ro nodev |
| 132 | |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 133 | # TODO(b/185767624): change the hard-coded size? |
| 134 | mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M |
Inseob Kim | 67ab436 | 2021-05-11 16:51:03 +0900 | [diff] [blame] | 135 | |
Inseob Kim | 67ab436 | 2021-05-11 16:51:03 +0900 | [diff] [blame] | 136 | # We chown/chmod /data again so because mount is run as root + defaults |
| 137 | chown system system /data |
| 138 | chmod 0771 /data |
| 139 | |
| 140 | # We restorecon /data in case the userdata partition has been reset. |
Inseob Kim | afd9dc0 | 2021-04-23 14:47:44 +0900 | [diff] [blame] | 141 | restorecon /data |
| 142 | |
Andrew Scull | 195354c | 2022-01-27 16:12:04 +0000 | [diff] [blame] | 143 | # set up misc directory structure first so that we can end early boot |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 144 | # and start apexd |
| 145 | mkdir /data/misc 01771 system misc |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 146 | # work around b/183668221 |
Andrew Scull | 195354c | 2022-01-27 16:12:04 +0000 | [diff] [blame] | 147 | restorecon /data/misc |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 148 | |
Victor Hsieh | 8bb67b6 | 2021-08-04 12:10:58 -0700 | [diff] [blame] | 149 | mkdir /data/misc/authfs 0700 root root |
| 150 | start authfs_service |
| 151 | |
Oleg Matcovschi | 9873948 | 2022-03-14 06:29:25 -0700 | [diff] [blame] | 152 | on late-fs && property:ro.debuggable=1 |
| 153 | # Ensure that tracefs has the correct permissions. |
| 154 | # This does not work correctly if it is called in post-fs. |
| 155 | chmod 0755 /sys/kernel/tracing |
| 156 | chmod 0755 /sys/kernel/debug/tracing |
| 157 | |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 158 | on post-fs-data |
| 159 | mark_post_data |
| 160 | |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 161 | mkdir /data/vendor 0771 root root |
| 162 | mkdir /data/vendor_ce 0771 root root |
| 163 | mkdir /data/vendor_de 0771 root root |
Inseob Kim | cd13c69 | 2021-04-23 15:56:33 +0900 | [diff] [blame] | 164 | mkdir /data/vendor/hardware 0771 root root |
| 165 | |
| 166 | # Start tombstoned early to be able to store tombstones. |
Inseob Kim | 7f8ac32 | 2021-04-29 22:41:37 +0900 | [diff] [blame] | 167 | # microdroid doesn't have anr, but tombstoned requires it |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 168 | mkdir /data/anr 0775 system system |
| 169 | mkdir /data/tombstones 0771 system system |
Inseob Kim | cd13c69 | 2021-04-23 15:56:33 +0900 | [diff] [blame] | 170 | mkdir /data/vendor/tombstones 0771 root root |
Inseob Kim | cd13c69 | 2021-04-23 15:56:33 +0900 | [diff] [blame] | 171 | |
| 172 | start tombstoned |
| 173 | |
Inseob Kim | 87ba1f1 | 2021-04-27 14:56:05 +0900 | [diff] [blame] | 174 | # For security reasons, /data/local/tmp should always be empty. |
| 175 | # Do not place files or directories in /data/local/tmp |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 176 | mkdir /data/local 0751 root root |
Inseob Kim | 87ba1f1 | 2021-04-27 14:56:05 +0900 | [diff] [blame] | 177 | mkdir /data/local/tmp 0771 shell shell |
| 178 | |
Shikha Panwar | c29d24b | 2022-05-25 13:48:40 +0000 | [diff] [blame] | 179 | service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting |
Shikha Panwar | 7afc139 | 2022-03-24 08:54:43 +0000 | [diff] [blame] | 180 | user root |
| 181 | group system |
Inseob Kim | cd9c1dd | 2022-07-13 17:13:45 +0900 | [diff] [blame] | 182 | shutdown critical |
Shikha Panwar | 7afc139 | 2022-03-24 08:54:43 +0000 | [diff] [blame] | 183 | |
Jooyung Han | 4a9b3bf | 2021-09-10 17:19:00 +0900 | [diff] [blame] | 184 | service apexd-vm /system/bin/apexd --vm |
| 185 | user root |
| 186 | group system |
| 187 | oneshot |
| 188 | disabled |
| 189 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 190 | service ueventd /system/bin/ueventd |
| 191 | class core |
| 192 | critical |
| 193 | seclabel u:r:ueventd:s0 |
| 194 | shutdown critical |
| 195 | |
| 196 | service 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 | |
Jiyong Park | ae5a4ed | 2021-11-01 18:36:28 +0900 | [diff] [blame] | 205 | service seriallogging /system/bin/logcat -b all -v threadtime -f /dev/hvc2 *:V |
Jiyong Park | fa91d70 | 2021-10-18 23:51:39 +0900 | [diff] [blame] | 206 | disabled |
| 207 | user logd |
| 208 | group root logd |
| 209 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 210 | on fs |
| 211 | write /dev/event-log-tags "# content owned by logd |
| 212 | " |
| 213 | chown logd logd /dev/event-log-tags |
| 214 | chmod 0644 /dev/event-log-tags |