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 |
Alan Stokes | cfe87cd | 2023-08-23 16:28:10 +0100 | [diff] [blame] | 15 | # Android doesn't need kernel module autoloading, and it causes SELinux |
| 16 | # denials. So disable it by setting modprobe to the empty string. Note: to |
| 17 | # explicitly set a sysctl to an empty string, a trailing newline is needed. |
| 18 | write /proc/sys/kernel/modprobe \n |
| 19 | |
Inseob Kim | de6b689 | 2021-05-26 12:06:59 +0900 | [diff] [blame] | 20 | # set RLIMIT_NICE to allow priorities from 19 to -20 |
| 21 | setrlimit nice 40 40 |
| 22 | |
Jooyung Han | c36b18a | 2021-04-20 03:33:36 +0900 | [diff] [blame] | 23 | start ueventd |
Inseob Kim | 870e76b | 2021-02-25 17:38:32 +0900 | [diff] [blame] | 24 | |
Jooyung Han | 8389345 | 2022-12-13 17:54:19 +0900 | [diff] [blame] | 25 | # Generate empty linker config to suppress warnings |
| 26 | write /linkerconfig/ld.config.txt \# |
| 27 | chmod 644 /linkerconfig/ld.config.txt |
| 28 | |
Jaewan Kim | b24d1dc | 2023-02-13 15:34:56 +0900 | [diff] [blame] | 29 | # Applies debug policy to decide whether to enable adb, adb root, and logcat. |
| 30 | # We don't directly exec the binary to specify stdio_to_kmsg. |
| 31 | exec_start init_debug_policy |
Jiyong Park | 419957e | 2022-09-08 22:28:51 +0900 | [diff] [blame] | 32 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 33 | on init |
Alan Stokes | f6e52e6 | 2023-11-06 15:04:32 +0000 | [diff] [blame] | 34 | mkdir /mnt/apk 0755 root root |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 35 | mkdir /mnt/extra-apk 0755 root root |
Alan Stokes | 1294f94 | 2023-08-21 14:34:12 +0100 | [diff] [blame] | 36 | |
| 37 | # Allow the payload access to the console (default is 0600) |
| 38 | chmod 0666 /dev/console |
| 39 | |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 40 | # Microdroid_manager starts apkdmverity/zipfuse/apexd |
| 41 | start microdroid_manager |
| 42 | |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 43 | # Wait for apexd to finish activating APEXes before starting more processes. |
Istvan Nador | ae0c2f5 | 2023-03-16 16:31:14 +0000 | [diff] [blame] | 44 | # Microdroid starts apexd in VM mode in which apexd doesn't wait for init after setting |
| 45 | # apexd.status to activated, but immediately transitions to ready. Therefore, it's not safe to |
| 46 | # wait for the activated status, by the time this line is reached it may be already be ready. |
| 47 | wait_for_prop apexd.status ready |
Jiyong Park | c516684 | 2022-01-21 12:54:57 +0900 | [diff] [blame] | 48 | perform_apex_config |
| 49 | |
| 50 | # Notify to microdroid_manager that perform_apex_config is done. |
| 51 | # Microdroid_manager shouldn't execute payload before this, because app |
| 52 | # payloads are not designed to run with bootstrap bionic |
| 53 | setprop apex_config.done true |
| 54 | |
Shikha Panwar | 3f6f6a5 | 2022-11-29 17:28:36 +0000 | [diff] [blame] | 55 | on property:microdroid_manager.init_done=1 |
Jiyong Park | 5bd2482 | 2022-08-23 14:50:29 +0900 | [diff] [blame] | 56 | # Stop ueventd to save memory |
| 57 | stop ueventd |
| 58 | |
Oleg Matcovschi | 9873948 | 2022-03-14 06:29:25 -0700 | [diff] [blame] | 59 | on init && property:ro.boot.microdroid.debuggable=1 |
| 60 | # Mount tracefs (with GID=AID_READTRACEFS) |
| 61 | mount tracefs tracefs /sys/kernel/tracing gid=3012 |
| 62 | |
Jaewan Kim | b24d1dc | 2023-02-13 15:34:56 +0900 | [diff] [blame] | 63 | on property:init_debug_policy.adbd.enabled=1 |
Jooyung Han | 16186d9 | 2021-06-01 17:53:28 +0900 | [diff] [blame] | 64 | start adbd |
| 65 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 66 | # Mount filesystems and start core system services. |
| 67 | on late-init |
| 68 | trigger early-fs |
| 69 | |
| 70 | # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter |
| 71 | # '--early' can be specified to skip entries with 'latemount'. |
| 72 | # /system and /vendor must be mounted by the end of the fs stage, |
| 73 | # while /data is optional. |
| 74 | trigger fs |
| 75 | trigger post-fs |
| 76 | |
| 77 | # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter |
| 78 | # to only mount entries with 'latemount'. This is needed if '--early' is |
| 79 | # specified in the previous mount_all command on the fs stage. |
| 80 | # With /system mounted and properties form /system + /factory available, |
| 81 | # some services can be started. |
| 82 | trigger late-fs |
| 83 | |
Nikita Ioffe | 57bc8d7 | 2022-11-27 00:50:50 +0000 | [diff] [blame] | 84 | # Wait for microdroid_manager to finish setting up sysprops from the payload config. |
| 85 | # Some further actions in the boot sequence might depend on the sysprops from the payloag, |
| 86 | # e.g. microdroid.config.enable_authfs configures whether to run authfs_service after |
| 87 | # /data is mounted. |
| 88 | wait_for_prop microdroid_manager.config_done 1 |
| 89 | |
Inseob Kim | afd9dc0 | 2021-04-23 14:47:44 +0900 | [diff] [blame] | 90 | trigger post-fs-data |
| 91 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 92 | # Load persist properties and override properties (if enabled) from /data. |
| 93 | trigger load_persist_props_action |
| 94 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 95 | trigger early-boot |
| 96 | trigger boot |
| 97 | |
| 98 | on post-fs |
| 99 | # Once everything is setup, no need to modify /. |
| 100 | # The bind+remount combination allows this to work in containers. |
| 101 | mount rootfs rootfs / remount bind ro nodev |
| 102 | |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 103 | # TODO(b/185767624): change the hard-coded size? |
Nikita Ioffe | 29e15c8 | 2023-02-25 02:31:51 +0000 | [diff] [blame] | 104 | mount tmpfs tmpfs /data noatime nosuid nodev noexec rw size=128M |
Inseob Kim | 67ab436 | 2021-05-11 16:51:03 +0900 | [diff] [blame] | 105 | |
Inseob Kim | 67ab436 | 2021-05-11 16:51:03 +0900 | [diff] [blame] | 106 | # We chown/chmod /data again so because mount is run as root + defaults |
| 107 | chown system system /data |
| 108 | chmod 0771 /data |
| 109 | |
| 110 | # We restorecon /data in case the userdata partition has been reset. |
Inseob Kim | afd9dc0 | 2021-04-23 14:47:44 +0900 | [diff] [blame] | 111 | restorecon /data |
| 112 | |
Andrew Scull | 195354c | 2022-01-27 16:12:04 +0000 | [diff] [blame] | 113 | # 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] | 114 | # and start apexd |
| 115 | mkdir /data/misc 01771 system misc |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 116 | # work around b/183668221 |
Andrew Scull | 195354c | 2022-01-27 16:12:04 +0000 | [diff] [blame] | 117 | restorecon /data/misc |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 118 | |
Victor Hsieh | 8bb67b6 | 2021-08-04 12:10:58 -0700 | [diff] [blame] | 119 | mkdir /data/misc/authfs 0700 root root |
Victor Hsieh | 8bb67b6 | 2021-08-04 12:10:58 -0700 | [diff] [blame] | 120 | |
Oleg Matcovschi | 9873948 | 2022-03-14 06:29:25 -0700 | [diff] [blame] | 121 | on late-fs && property:ro.debuggable=1 |
| 122 | # Ensure that tracefs has the correct permissions. |
| 123 | # This does not work correctly if it is called in post-fs. |
| 124 | chmod 0755 /sys/kernel/tracing |
| 125 | chmod 0755 /sys/kernel/debug/tracing |
| 126 | |
Inseob Kim | a920f9e | 2021-08-04 03:33:43 +0000 | [diff] [blame] | 127 | on post-fs-data |
| 128 | mark_post_data |
| 129 | |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 130 | mkdir /data/vendor 0771 root root |
| 131 | mkdir /data/vendor_ce 0771 root root |
| 132 | mkdir /data/vendor_de 0771 root root |
Inseob Kim | cd13c69 | 2021-04-23 15:56:33 +0900 | [diff] [blame] | 133 | mkdir /data/vendor/hardware 0771 root root |
| 134 | |
Inseob Kim | 87ba1f1 | 2021-04-27 14:56:05 +0900 | [diff] [blame] | 135 | # For security reasons, /data/local/tmp should always be empty. |
| 136 | # Do not place files or directories in /data/local/tmp |
Inseob Kim | 17d0db1 | 2021-06-09 14:30:47 +0900 | [diff] [blame] | 137 | mkdir /data/local 0751 root root |
Inseob Kim | 87ba1f1 | 2021-04-27 14:56:05 +0900 | [diff] [blame] | 138 | mkdir /data/local/tmp 0771 shell shell |
| 139 | |
Nikita Ioffe | 57bc8d7 | 2022-11-27 00:50:50 +0000 | [diff] [blame] | 140 | on post-fs-data && property:microdroid_manager.authfs.enabled=1 |
| 141 | start authfs_service |
| 142 | |
| 143 | on boot |
| 144 | # Mark boot completed. This will notify microdroid_manager to run payload. |
| 145 | setprop dev.bootcomplete 1 |
| 146 | |
Jooyung Han | 4a9b3bf | 2021-09-10 17:19:00 +0900 | [diff] [blame] | 147 | service apexd-vm /system/bin/apexd --vm |
| 148 | user root |
| 149 | group system |
| 150 | oneshot |
| 151 | disabled |
Nikita Ioffe | 7c6b270 | 2022-09-30 18:40:05 +0100 | [diff] [blame] | 152 | capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN |
Jooyung Han | 4a9b3bf | 2021-09-10 17:19:00 +0900 | [diff] [blame] | 153 | |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 154 | service ueventd /system/bin/ueventd |
Nikita Ioffe | 4fc81ab | 2023-04-25 21:04:01 +0100 | [diff] [blame] | 155 | user root |
David Anderson | 40427e7 | 2023-05-17 17:26:38 -0700 | [diff] [blame] | 156 | group root |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 157 | class core |
| 158 | critical |
| 159 | seclabel u:r:ueventd:s0 |
David Anderson | 40427e7 | 2023-05-17 17:26:38 -0700 | [diff] [blame] | 160 | capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER FSETID MKNOD NET_ADMIN SETGID SETUID SYS_MODULE SYS_RAWIO SYS_ADMIN |
Inseob Kim | dc2af86 | 2021-02-17 15:51:56 +0900 | [diff] [blame] | 161 | |
| 162 | service console /system/bin/sh |
| 163 | class core |
| 164 | console |
| 165 | disabled |
| 166 | user shell |
| 167 | group shell log readproc |
| 168 | seclabel u:r:shell:s0 |
| 169 | setenv HOSTNAME console |
Jaewan Kim | b24d1dc | 2023-02-13 15:34:56 +0900 | [diff] [blame] | 170 | |
| 171 | service init_debug_policy /system/bin/init_debug_policy |
Nikita Ioffe | 4fc81ab | 2023-04-25 21:04:01 +0100 | [diff] [blame] | 172 | user root |
Jaewan Kim | b24d1dc | 2023-02-13 15:34:56 +0900 | [diff] [blame] | 173 | oneshot |
| 174 | disabled |
| 175 | stdio_to_kmsg |