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