blob: 91931abe39776dc4d5439caf550033f27b6dc956 [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
Jooyung Han83893452022-12-13 17:54:19 +090020 # Generate empty linker config to suppress warnings
21 write /linkerconfig/ld.config.txt \#
22 chmod 644 /linkerconfig/ld.config.txt
23
Jaewan Kimb24d1dc2023-02-13 15:34:56 +090024 # Applies debug policy to decide whether to enable adb, adb root, and logcat.
25 # We don't directly exec the binary to specify stdio_to_kmsg.
26 exec_start init_debug_policy
Jiyong Park419957e2022-09-08 22:28:51 +090027
Inseob Kimdc2af862021-02-17 15:51:56 +090028on init
Jiyong Parkc5166842022-01-21 12:54:57 +090029 mkdir /mnt/apk 0755 system system
30 mkdir /mnt/extra-apk 0755 root root
Alan Stokes1294f942023-08-21 14:34:12 +010031
32 # Allow the payload access to the console (default is 0600)
33 chmod 0666 /dev/console
34
Jiyong Parkc5166842022-01-21 12:54:57 +090035 # Microdroid_manager starts apkdmverity/zipfuse/apexd
36 start microdroid_manager
37
38 # restorecon so microdroid_manager can create subdirectories
39 restorecon /mnt/extra-apk
40
41 # Wait for apexd to finish activating APEXes before starting more processes.
Istvan Nadorae0c2f52023-03-16 16:31:14 +000042 # Microdroid starts apexd in VM mode in which apexd doesn't wait for init after setting
43 # apexd.status to activated, but immediately transitions to ready. Therefore, it's not safe to
44 # wait for the activated status, by the time this line is reached it may be already be ready.
45 wait_for_prop apexd.status ready
Jiyong Parkc5166842022-01-21 12:54:57 +090046 perform_apex_config
47
48 # Notify to microdroid_manager that perform_apex_config is done.
49 # Microdroid_manager shouldn't execute payload before this, because app
50 # payloads are not designed to run with bootstrap bionic
51 setprop apex_config.done true
52
Shikha Panwar3f6f6a52022-11-29 17:28:36 +000053on property:microdroid_manager.init_done=1
Jiyong Park5bd24822022-08-23 14:50:29 +090054 # Stop ueventd to save memory
55 stop ueventd
56
Oleg Matcovschi98739482022-03-14 06:29:25 -070057on init && property:ro.boot.microdroid.debuggable=1
58 # Mount tracefs (with GID=AID_READTRACEFS)
59 mount tracefs tracefs /sys/kernel/tracing gid=3012
60
Jaewan Kimb24d1dc2023-02-13 15:34:56 +090061on property:init_debug_policy.adbd.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090062 start adbd
63
Inseob Kimdc2af862021-02-17 15:51:56 +090064# Mount filesystems and start core system services.
65on late-init
66 trigger early-fs
67
68 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
69 # '--early' can be specified to skip entries with 'latemount'.
70 # /system and /vendor must be mounted by the end of the fs stage,
71 # while /data is optional.
72 trigger fs
73 trigger post-fs
74
75 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
76 # to only mount entries with 'latemount'. This is needed if '--early' is
77 # specified in the previous mount_all command on the fs stage.
78 # With /system mounted and properties form /system + /factory available,
79 # some services can be started.
80 trigger late-fs
81
Nikita Ioffe57bc8d72022-11-27 00:50:50 +000082 # Wait for microdroid_manager to finish setting up sysprops from the payload config.
83 # Some further actions in the boot sequence might depend on the sysprops from the payloag,
84 # e.g. microdroid.config.enable_authfs configures whether to run authfs_service after
85 # /data is mounted.
86 wait_for_prop microdroid_manager.config_done 1
87
Inseob Kimafd9dc02021-04-23 14:47:44 +090088 trigger post-fs-data
89
Inseob Kimdc2af862021-02-17 15:51:56 +090090 # Load persist properties and override properties (if enabled) from /data.
91 trigger load_persist_props_action
92
Inseob Kimdc2af862021-02-17 15:51:56 +090093 trigger early-boot
94 trigger boot
95
96on post-fs
97 # Once everything is setup, no need to modify /.
98 # The bind+remount combination allows this to work in containers.
99 mount rootfs rootfs / remount bind ro nodev
100
Inseob Kim17d0db12021-06-09 14:30:47 +0900101 # TODO(b/185767624): change the hard-coded size?
Nikita Ioffe29e15c82023-02-25 02:31:51 +0000102 mount tmpfs tmpfs /data noatime nosuid nodev noexec rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900103
Inseob Kim67ab4362021-05-11 16:51:03 +0900104 # We chown/chmod /data again so because mount is run as root + defaults
105 chown system system /data
106 chmod 0771 /data
107
108 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900109 restorecon /data
110
Andrew Scull195354c2022-01-27 16:12:04 +0000111 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000112 # and start apexd
113 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000114 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000115 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000116
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700117 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700118
Oleg Matcovschi98739482022-03-14 06:29:25 -0700119on late-fs && property:ro.debuggable=1
120 # Ensure that tracefs has the correct permissions.
121 # This does not work correctly if it is called in post-fs.
122 chmod 0755 /sys/kernel/tracing
123 chmod 0755 /sys/kernel/debug/tracing
124
Inseob Kima920f9e2021-08-04 03:33:43 +0000125on post-fs-data
126 mark_post_data
127
Inseob Kim17d0db12021-06-09 14:30:47 +0900128 mkdir /data/vendor 0771 root root
129 mkdir /data/vendor_ce 0771 root root
130 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900131 mkdir /data/vendor/hardware 0771 root root
132
Inseob Kim87ba1f12021-04-27 14:56:05 +0900133 # For security reasons, /data/local/tmp should always be empty.
134 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900135 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900136 mkdir /data/local/tmp 0771 shell shell
137
Nikita Ioffe57bc8d72022-11-27 00:50:50 +0000138on post-fs-data && property:microdroid_manager.authfs.enabled=1
139 start authfs_service
140
141on boot
142 # Mark boot completed. This will notify microdroid_manager to run payload.
143 setprop dev.bootcomplete 1
144
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900145service apexd-vm /system/bin/apexd --vm
146 user root
147 group system
148 oneshot
149 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100150 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900151
Inseob Kimdc2af862021-02-17 15:51:56 +0900152service ueventd /system/bin/ueventd
Nikita Ioffe4fc81ab2023-04-25 21:04:01 +0100153 user root
David Anderson40427e72023-05-17 17:26:38 -0700154 group root
Inseob Kimdc2af862021-02-17 15:51:56 +0900155 class core
156 critical
157 seclabel u:r:ueventd:s0
David Anderson40427e72023-05-17 17:26:38 -0700158 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 +0900159
160service console /system/bin/sh
161 class core
162 console
163 disabled
164 user shell
165 group shell log readproc
166 seclabel u:r:shell:s0
167 setenv HOSTNAME console
Jaewan Kimb24d1dc2023-02-13 15:34:56 +0900168
169service init_debug_policy /system/bin/init_debug_policy
Nikita Ioffe4fc81ab2023-04-25 21:04:01 +0100170 user root
Jaewan Kimb24d1dc2023-02-13 15:34:56 +0900171 oneshot
172 disabled
173 stdio_to_kmsg