blob: 70c22d4f904802c2c0aef382420d0b34881572ec [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
Jiyong Park419957e2022-09-08 22:28:51 +090024# If VM is debuggable, send logs to outside ot the VM via the serial console.
25# If non-debuggable, logs are internally consumed at /dev/null
Seungjae Yoofa22bb02022-12-08 16:38:42 +090026on early-init && property:ro.boot.microdroid.debuggable=1
Jiyong Park419957e2022-09-08 22:28:51 +090027 setprop ro.log.file_logger.path /dev/hvc2
28
Seungjae Yoofa22bb02022-12-08 16:38:42 +090029on early-init && property:ro.boot.microdroid.debuggable=0
Jiyong Park419957e2022-09-08 22:28:51 +090030 setprop ro.log.file_logger.path /dev/null
31
Inseob Kimdc2af862021-02-17 15:51:56 +090032on init
Jiyong Parkc5166842022-01-21 12:54:57 +090033 mkdir /mnt/apk 0755 system system
34 mkdir /mnt/extra-apk 0755 root root
35 # 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.
42 wait_for_prop apexd.status activated
43 perform_apex_config
44
45 # Notify to microdroid_manager that perform_apex_config is done.
46 # Microdroid_manager shouldn't execute payload before this, because app
47 # payloads are not designed to run with bootstrap bionic
48 setprop apex_config.done true
49
50 setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
51
Shikha Panwar3f6f6a52022-11-29 17:28:36 +000052on property:microdroid_manager.init_done=1
Jiyong Park5bd24822022-08-23 14:50:29 +090053 # Stop ueventd to save memory
54 stop ueventd
55
Oleg Matcovschi98739482022-03-14 06:29:25 -070056on init && property:ro.boot.microdroid.debuggable=1
57 # Mount tracefs (with GID=AID_READTRACEFS)
58 mount tracefs tracefs /sys/kernel/tracing gid=3012
59
Jiyong Parke7407e22021-10-18 15:51:59 +090060on init && property:ro.boot.adb.enabled=1
Jooyung Han16186d92021-06-01 17:53:28 +090061 start adbd
62
Inseob Kimdc2af862021-02-17 15:51:56 +090063# Mount filesystems and start core system services.
64on late-init
65 trigger early-fs
66
67 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
68 # '--early' can be specified to skip entries with 'latemount'.
69 # /system and /vendor must be mounted by the end of the fs stage,
70 # while /data is optional.
71 trigger fs
72 trigger post-fs
73
74 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
75 # to only mount entries with 'latemount'. This is needed if '--early' is
76 # specified in the previous mount_all command on the fs stage.
77 # With /system mounted and properties form /system + /factory available,
78 # some services can be started.
79 trigger late-fs
80
Nikita Ioffe57bc8d72022-11-27 00:50:50 +000081 # Wait for microdroid_manager to finish setting up sysprops from the payload config.
82 # Some further actions in the boot sequence might depend on the sysprops from the payloag,
83 # e.g. microdroid.config.enable_authfs configures whether to run authfs_service after
84 # /data is mounted.
85 wait_for_prop microdroid_manager.config_done 1
86
Inseob Kimafd9dc02021-04-23 14:47:44 +090087 trigger post-fs-data
88
Inseob Kimdc2af862021-02-17 15:51:56 +090089 # Load persist properties and override properties (if enabled) from /data.
90 trigger load_persist_props_action
91
Inseob Kimdc2af862021-02-17 15:51:56 +090092 trigger early-boot
93 trigger boot
94
95on post-fs
96 # Once everything is setup, no need to modify /.
97 # The bind+remount combination allows this to work in containers.
98 mount rootfs rootfs / remount bind ro nodev
99
Inseob Kim17d0db12021-06-09 14:30:47 +0900100 # TODO(b/185767624): change the hard-coded size?
Nikita Ioffe29e15c82023-02-25 02:31:51 +0000101 mount tmpfs tmpfs /data noatime nosuid nodev noexec rw size=128M
Inseob Kim67ab4362021-05-11 16:51:03 +0900102
Inseob Kim67ab4362021-05-11 16:51:03 +0900103 # We chown/chmod /data again so because mount is run as root + defaults
104 chown system system /data
105 chmod 0771 /data
106
107 # We restorecon /data in case the userdata partition has been reset.
Inseob Kimafd9dc02021-04-23 14:47:44 +0900108 restorecon /data
109
Andrew Scull195354c2022-01-27 16:12:04 +0000110 # set up misc directory structure first so that we can end early boot
Inseob Kima920f9e2021-08-04 03:33:43 +0000111 # and start apexd
112 mkdir /data/misc 01771 system misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000113 # work around b/183668221
Andrew Scull195354c2022-01-27 16:12:04 +0000114 restorecon /data/misc
Inseob Kima920f9e2021-08-04 03:33:43 +0000115
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700116 mkdir /data/misc/authfs 0700 root root
Victor Hsieh8bb67b62021-08-04 12:10:58 -0700117
Oleg Matcovschi98739482022-03-14 06:29:25 -0700118on late-fs && property:ro.debuggable=1
119 # Ensure that tracefs has the correct permissions.
120 # This does not work correctly if it is called in post-fs.
121 chmod 0755 /sys/kernel/tracing
122 chmod 0755 /sys/kernel/debug/tracing
123
Inseob Kima920f9e2021-08-04 03:33:43 +0000124on post-fs-data
125 mark_post_data
126
Inseob Kim17d0db12021-06-09 14:30:47 +0900127 mkdir /data/vendor 0771 root root
128 mkdir /data/vendor_ce 0771 root root
129 mkdir /data/vendor_de 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900130 mkdir /data/vendor/hardware 0771 root root
131
132 # Start tombstoned early to be able to store tombstones.
Inseob Kim7f8ac322021-04-29 22:41:37 +0900133 # microdroid doesn't have anr, but tombstoned requires it
Inseob Kim17d0db12021-06-09 14:30:47 +0900134 mkdir /data/anr 0775 system system
135 mkdir /data/tombstones 0771 system system
Inseob Kimcd13c692021-04-23 15:56:33 +0900136 mkdir /data/vendor/tombstones 0771 root root
Inseob Kimcd13c692021-04-23 15:56:33 +0900137
138 start tombstoned
139
Inseob Kim87ba1f12021-04-27 14:56:05 +0900140 # For security reasons, /data/local/tmp should always be empty.
141 # Do not place files or directories in /data/local/tmp
Inseob Kim17d0db12021-06-09 14:30:47 +0900142 mkdir /data/local 0751 root root
Inseob Kim87ba1f12021-04-27 14:56:05 +0900143 mkdir /data/local/tmp 0771 shell shell
144
Nikita Ioffe57bc8d72022-11-27 00:50:50 +0000145on post-fs-data && property:microdroid_manager.authfs.enabled=1
146 start authfs_service
147
148on boot
149 # Mark boot completed. This will notify microdroid_manager to run payload.
150 setprop dev.bootcomplete 1
151
Inseob Kimc16b0cc2023-01-26 14:57:24 +0900152on property:tombstone_transmit.start=1
153 mkdir /data/tombstones 0771 system system
154 start tombstone_transmit
155
Shikha Panwarc29d24b2022-05-25 13:48:40 +0000156service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100157 user system
Shikha Panwar7afc1392022-03-24 08:54:43 +0000158 group system
Inseob Kimcd9c1dd2022-07-13 17:13:45 +0900159 shutdown critical
Shikha Panwar7afc1392022-03-24 08:54:43 +0000160
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900161service apexd-vm /system/bin/apexd --vm
162 user root
163 group system
164 oneshot
165 disabled
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100166 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900167
Inseob Kimdc2af862021-02-17 15:51:56 +0900168service ueventd /system/bin/ueventd
169 class core
170 critical
171 seclabel u:r:ueventd:s0
Nikita Ioffe7c6b2702022-09-30 18:40:05 +0100172 capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER FSETID MKNOD NET_ADMIN SETGID SETUID SYS_MODULE SYS_RAWIO
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