blob: ce26a35e6fc2c8b3a8cb295126adde61c24b88ef [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
Alan Stokescfe87cd2023-08-23 16:28:10 +010015 # 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 Kimde6b6892021-05-26 12:06:59 +090020 # set RLIMIT_NICE to allow priorities from 19 to -20
21 setrlimit nice 40 40
22
Jooyung Hanc36b18a2021-04-20 03:33:36 +090023 start ueventd
Inseob Kim870e76b2021-02-25 17:38:32 +090024
Jooyung Han83893452022-12-13 17:54:19 +090025 # Generate empty linker config to suppress warnings
26 write /linkerconfig/ld.config.txt \#
27 chmod 644 /linkerconfig/ld.config.txt
28
Jaewan Kimb24d1dc2023-02-13 15:34:56 +090029 # 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 Park419957e2022-09-08 22:28:51 +090032
Alan Stokes20ccdbb2023-11-08 16:23:52 +000033 # Wait for ueventd to have finished cold boot.
34 # This is needed by prng-seeder (at least).
35 # (In Android this happens inside apexd-bootstrap.)
36 wait_for_prop ro.cold_boot_done true
37
Nikita Ioffeaa9f6032025-01-21 18:06:46 +000038 # We need to define ANDROID_TZDATA_ROOT otherwise libicu complains.
39 # For now set it to a non-existent value, because libicu APIs that don't depend on tzdata work
40 # correctly without it.
41 # Once loading tzdata APEX is supported, we can set this value to /apex/com.android.tzdata.
42 # This is no-op for most microdroid VMs, and is only used if com.android.i18n APEX was mounted.
43 export ANDROID_TZDATA_ROOT /does/not/exist
44 # Set ANDROID_I18N_ROOT otherwise libicu will complain.
45 # This is no-op for most microdroid VMs, and is only used if com.android.i18n APEX was mounted.
46 export ANDROID_I18N_ROOT /apex/com.android.i18n
47
Inseob Kimdc2af862021-02-17 15:51:56 +090048on init
Alan Stokesf6e52e62023-11-06 15:04:32 +000049 mkdir /mnt/apk 0755 root root
Jiyong Parkc5166842022-01-21 12:54:57 +090050 mkdir /mnt/extra-apk 0755 root root
Alan Stokes1294f942023-08-21 14:34:12 +010051
52 # Allow the payload access to the console (default is 0600)
53 chmod 0666 /dev/console
54
Jiyong Parkc5166842022-01-21 12:54:57 +090055 # Microdroid_manager starts apkdmverity/zipfuse/apexd
56 start microdroid_manager
57
Jiyong Parkc5166842022-01-21 12:54:57 +090058 # Wait for apexd to finish activating APEXes before starting more processes.
Istvan Nadorae0c2f52023-03-16 16:31:14 +000059 # Microdroid starts apexd in VM mode in which apexd doesn't wait for init after setting
60 # apexd.status to activated, but immediately transitions to ready. Therefore, it's not safe to
61 # wait for the activated status, by the time this line is reached it may be already be ready.
62 wait_for_prop apexd.status ready
Jiyong Parkc5166842022-01-21 12:54:57 +090063 perform_apex_config
64
65 # Notify to microdroid_manager that perform_apex_config is done.
66 # Microdroid_manager shouldn't execute payload before this, because app
67 # payloads are not designed to run with bootstrap bionic
68 setprop apex_config.done true
69
Shikha Panwar3f6f6a52022-11-29 17:28:36 +000070on property:microdroid_manager.init_done=1
Jiyong Park5bd24822022-08-23 14:50:29 +090071 # Stop ueventd to save memory
72 stop ueventd
73
Oleg Matcovschi98739482022-03-14 06:29:25 -070074on init && property:ro.boot.microdroid.debuggable=1
75 # Mount tracefs (with GID=AID_READTRACEFS)
76 mount tracefs tracefs /sys/kernel/tracing gid=3012
77
Jaewan Kimb24d1dc2023-02-13 15:34:56 +090078on property:init_debug_policy.adbd.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090079 start adbd
80
Inseob Kimdc2af862021-02-17 15:51:56 +090081# Mount filesystems and start core system services.
82on late-init
83 trigger early-fs
84
85 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
86 # '--early' can be specified to skip entries with 'latemount'.
87 # /system and /vendor must be mounted by the end of the fs stage,
88 # while /data is optional.
89 trigger fs
90 trigger post-fs
91
92 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
93 # to only mount entries with 'latemount'. This is needed if '--early' is
94 # specified in the previous mount_all command on the fs stage.
95 # With /system mounted and properties form /system + /factory available,
96 # some services can be started.
97 trigger late-fs
98
Nikita Ioffe57bc8d72022-11-27 00:50:50 +000099 # Wait for microdroid_manager to finish setting up sysprops from the payload config.
100 # Some further actions in the boot sequence might depend on the sysprops from the payloag,
101 # e.g. microdroid.config.enable_authfs configures whether to run authfs_service after
102 # /data is mounted.
103 wait_for_prop microdroid_manager.config_done 1
104
Inseob Kimafd9dc02021-04-23 14:47:44 +0900105 trigger post-fs-data
106
Inseob Kimdc2af862021-02-17 15:51:56 +0900107 trigger early-boot
108 trigger boot
109
110on post-fs
111 # Once everything is setup, no need to modify /.
112 # The bind+remount combination allows this to work in containers.
113 mount rootfs rootfs / remount bind ro nodev
114
Inseob Kim17d0db12021-06-09 14:30:47 +0900115 # TODO(b/185767624): change the hard-coded size?
Nikita Ioffe29e15c82023-02-25 02:31:51 +0000116 mount tmpfs tmpfs /data noatime nosuid nodev noexec rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900117
Inseob Kim67ab4362021-05-11 16:51:03 +0900118 # We chown/chmod /data again so because mount is run as root + defaults
119 chown system system /data
120 chmod 0771 /data
121
122 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900123 restorecon /data
124
Andrew Scull195354c2022-01-27 16:12:04 +0000125 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000126 # and start apexd
127 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000128 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000129 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000130
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700131 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700132
Oleg Matcovschi98739482022-03-14 06:29:25 -0700133on late-fs && property:ro.debuggable=1
134 # Ensure that tracefs has the correct permissions.
135 # This does not work correctly if it is called in post-fs.
136 chmod 0755 /sys/kernel/tracing
137 chmod 0755 /sys/kernel/debug/tracing
138
Inseob Kima920f9e2021-08-04 03:33:43 +0000139on post-fs-data
140 mark_post_data
141
Inseob Kim17d0db12021-06-09 14:30:47 +0900142 mkdir /data/vendor 0771 root root
143 mkdir /data/vendor_ce 0771 root root
144 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900145 mkdir /data/vendor/hardware 0771 root root
146
Inseob Kim87ba1f12021-04-27 14:56:05 +0900147 # For security reasons, /data/local/tmp should always be empty.
148 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900149 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900150 mkdir /data/local/tmp 0771 shell shell
151
Nikita Ioffe57bc8d72022-11-27 00:50:50 +0000152on post-fs-data && property:microdroid_manager.authfs.enabled=1
153 start authfs_service
154
155on boot
156 # Mark boot completed. This will notify microdroid_manager to run payload.
157 setprop dev.bootcomplete 1
158
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900159service apexd-vm /system/bin/apexd --vm
160 user root
161 group system
162 oneshot
163 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100164 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900165
Inseob Kimdc2af862021-02-17 15:51:56 +0900166service ueventd /system/bin/ueventd
Nikita Ioffe4fc81ab2023-04-25 21:04:01 +0100167 user root
David Anderson40427e72023-05-17 17:26:38 -0700168 group root
Inseob Kimdc2af862021-02-17 15:51:56 +0900169 class core
170 critical
171 seclabel u:r:ueventd:s0
David Anderson40427e72023-05-17 17:26:38 -0700172 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER FSETID MKNOD NET_ADMIN SETGID SETUID SYS_MODULE SYS_RAWIO SYS_ADMIN
Inseob Kimdc2af862021-02-17 15:51:56 +0900173
174service console /system/bin/sh
175 class core
176 console
177 disabled
178 user shell
179 group shell log readproc
180 seclabel u:r:shell:s0
181 setenv HOSTNAME console
Jaewan Kimb24d1dc2023-02-13 15:34:56 +0900182
183service init_debug_policy /system/bin/init_debug_policy
Nikita Ioffe4fc81ab2023-04-25 21:04:01 +0100184 user root
Jaewan Kimb24d1dc2023-02-13 15:34:56 +0900185 oneshot
186 disabled
187 stdio_to_kmsg