blob: 42545d99a662c58fdf656487ed807f5c9f18d9b9 [file] [log] [blame]
Nick Kralevichf3ef1272012-03-14 15:22:54 -07001# Copyright (C) 2012 The Android Open Source Project
2#
3# IMPORTANT: Do not create world writable files or directories.
4# This is a common source of Android security bugs.
5#
6
Ying Wang5748ee92013-07-23 18:03:37 -07007import /init.environ.rc
Tom Cherryc9f53532019-11-04 10:30:36 -08008import /system/etc/init/hw/init.usb.rc
Mike Lockwood35ea5e42012-08-28 10:25:13 -07009import /init.${ro.hardware}.rc
Yueyao Zhuf7c34ad2017-05-18 12:46:34 -070010import /vendor/etc/init/hw/init.${ro.hardware}.rc
Tom Cherryc9f53532019-11-04 10:30:36 -080011import /system/etc/init/hw/init.usb.configfs.rc
12import /system/etc/init/hw/init.${ro.zygote}.rc
Dima Zavin7634bf82011-12-16 14:23:22 -080013
Suren Baghdasaryan192aee72018-12-21 11:41:50 -080014# Cgroups are mounted right before early-init using list from /etc/cgroups.json
Colin Crossf83d0b92010-04-21 12:04:20 -070015on early-init
Nick Kralevichd28a5352015-10-09 17:09:10 -070016 # Disable sysrq from keyboard
17 write /proc/sys/kernel/sysrq 0
18
Eric Biggers843f46e2020-03-11 09:56:15 -070019 # Android doesn't need kernel module autoloading, and it causes SELinux
20 # denials. So disable it by setting modprobe to the empty string. Note: to
21 # explicitly set a sysctl to an empty string, a trailing newline is needed.
22 write /proc/sys/kernel/modprobe \n
23
Stephen Smalleydeb41e52013-10-01 09:21:47 -040024 # Set the security context of /adb_keys if present.
25 restorecon /adb_keys
26
Alex Deymobb968fb2016-02-29 17:23:36 -080027 # Set the security context of /postinstall if present.
28 restorecon /postinstall
29
Robert Beneac6385692017-05-31 16:07:53 -070030 mkdir /acct/uid
31
Mark Salyzyn64d97d82018-04-09 09:50:32 -070032 # memory.pressure_level used by lmkd
33 chown root system /dev/memcg/memory.pressure_level
34 chmod 0040 /dev/memcg/memory.pressure_level
Robert Beneac6385692017-05-31 16:07:53 -070035 # app mem cgroups, used by activity manager, lmkd and zygote
36 mkdir /dev/memcg/apps/ 0755 system system
Robert Benea3280e482017-06-27 23:09:03 -070037 # cgroup for system_server and surfaceflinger
38 mkdir /dev/memcg/system 0550 system system
Robert Beneac6385692017-05-31 16:07:53 -070039
Maciej Żenczykowski00a21e32020-01-25 00:34:33 -080040 # symlink the Android specific /dev/tun to Linux expected /dev/net/tun
41 mkdir /dev/net 0755 root root
42 symlink ../tun /dev/net/tun
43
Tom Cherryfdeca992019-06-06 11:05:52 -070044 # set RLIMIT_NICE to allow priorities from 19 to -20
45 setrlimit nice 40 40
46
47 # Allow up to 32K FDs per process
48 setrlimit nofile 32768 32768
49
Kiyoung Kime4d3f212019-12-16 14:31:04 +090050 # Set up linker config subdirectories based on mount namespaces
51 mkdir /linkerconfig/bootstrap 0755
52 mkdir /linkerconfig/default 0755
53
Martijn Coenen9226bb32019-12-16 09:59:08 +010054 # Disable dm-verity hash prefetching, since it doesn't help performance
55 # Read more in b/136247322
56 write /sys/module/dm_verity/parameters/prefetch_cluster 0
57
Kiyoung Kim74c22922019-07-08 18:59:50 +090058 # Generate ld.config.txt for early executed processes
Kiyoung Kim03b9bca2020-11-30 14:49:36 +090059 exec -- /system/bin/bootstrap/linkerconfig --target /linkerconfig/bootstrap
Kiyoung Kime4d3f212019-12-16 14:31:04 +090060 chmod 644 /linkerconfig/bootstrap/ld.config.txt
61 copy /linkerconfig/bootstrap/ld.config.txt /linkerconfig/default/ld.config.txt
62 chmod 644 /linkerconfig/default/ld.config.txt
63
64 # Mount bootstrap linker configuration as current
65 mount none /linkerconfig/bootstrap /linkerconfig bind rec
Kiyoung Kim74c22922019-07-08 18:59:50 +090066
Colin Crossf83d0b92010-04-21 12:04:20 -070067 start ueventd
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080068
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +090069 # Run apexd-bootstrap so that APEXes that provide critical libraries
70 # become available. Note that this is executed as exec_start to ensure that
71 # the libraries are available to the processes started after this statement.
72 exec_start apexd-bootstrap
73
Kiyoung Kime4d3f212019-12-16 14:31:04 +090074 # Generate linker config based on apex mounted in bootstrap namespace
75 update_linker_config
76
Tobias Thiererbda05542019-09-11 18:22:10 +010077 # These must already exist by the time boringssl_self_test32 / boringssl_self_test64 run.
78 mkdir /dev/boringssl 0755 root root
79 mkdir /dev/boringssl/selftest 0755 root root
80
Kalesh Singhccf343f2021-12-06 16:13:06 -080081 # Mount tracefs (with GID=AID_READTRACEFS)
82 mount tracefs tracefs /sys/kernel/tracing gid=3012
Kyle Lin9d19a052020-04-23 23:19:25 +080083
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -070084 # create sys dirctory
85 mkdir /dev/sys 0755 system system
86 mkdir /dev/sys/fs 0755 system system
87 mkdir /dev/sys/block 0755 system system
88
Tobias Thiererbda05542019-09-11 18:22:10 +010089# Run boringssl self test for each ABI so that later processes can skip it. http://b/139348610
90on early-init && property:ro.product.cpu.abilist32=*
Tom Cherry60971e62019-09-10 10:40:47 -070091 exec_start boringssl_self_test32
Tobias Thiererbda05542019-09-11 18:22:10 +010092on early-init && property:ro.product.cpu.abilist64=*
Tom Cherry60971e62019-09-10 10:40:47 -070093 exec_start boringssl_self_test64
Tobias Thiererbda05542019-09-11 18:22:10 +010094on property:apexd.status=ready && property:ro.product.cpu.abilist32=*
Tom Cherry60971e62019-09-10 10:40:47 -070095 exec_start boringssl_self_test_apex32
96on property:apexd.status=ready && property:ro.product.cpu.abilist64=*
97 exec_start boringssl_self_test_apex64
98
99service boringssl_self_test32 /system/bin/boringssl_self_test32
Tobias Thiererf0f94382019-09-13 16:51:56 +0100100 setenv BORINGSSL_SELF_TEST_CREATE_FLAG true # Any nonempty value counts as true
Tom Cherrya76bfb22019-09-18 09:41:36 -0700101 reboot_on_failure reboot,boringssl-self-check-failed
Tom Cherryf5e872e2019-09-23 16:21:31 -0700102 stdio_to_kmsg
Tom Cherry60971e62019-09-10 10:40:47 -0700103
104service boringssl_self_test64 /system/bin/boringssl_self_test64
Tobias Thiererf0f94382019-09-13 16:51:56 +0100105 setenv BORINGSSL_SELF_TEST_CREATE_FLAG true # Any nonempty value counts as true
Tom Cherrya76bfb22019-09-18 09:41:36 -0700106 reboot_on_failure reboot,boringssl-self-check-failed
Tom Cherryf5e872e2019-09-23 16:21:31 -0700107 stdio_to_kmsg
Tom Cherry60971e62019-09-10 10:40:47 -0700108
109service boringssl_self_test_apex32 /apex/com.android.conscrypt/bin/boringssl_self_test32
Tobias Thiererf0f94382019-09-13 16:51:56 +0100110 setenv BORINGSSL_SELF_TEST_CREATE_FLAG true # Any nonempty value counts as true
Tom Cherrya76bfb22019-09-18 09:41:36 -0700111 reboot_on_failure reboot,boringssl-self-check-failed
Tom Cherryf5e872e2019-09-23 16:21:31 -0700112 stdio_to_kmsg
Tom Cherry60971e62019-09-10 10:40:47 -0700113
114service boringssl_self_test_apex64 /apex/com.android.conscrypt/bin/boringssl_self_test64
Tobias Thiererf0f94382019-09-13 16:51:56 +0100115 setenv BORINGSSL_SELF_TEST_CREATE_FLAG true # Any nonempty value counts as true
Tom Cherrya76bfb22019-09-18 09:41:36 -0700116 reboot_on_failure reboot,boringssl-self-check-failed
Tom Cherryf5e872e2019-09-23 16:21:31 -0700117 stdio_to_kmsg
Tobias Thiererbda05542019-09-11 18:22:10 +0100118
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119on init
Riley Andrews6dfdc7c2014-06-18 20:35:40 -0700120 sysclktz 0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800121
Nick Kralevich27cb4102016-01-22 18:02:29 -0800122 # Mix device-specific information into the entropy pool
123 copy /proc/cmdline /dev/urandom
Wei Wang0d78bfb2019-01-25 09:31:28 -0800124 copy /system/etc/prop.default /dev/urandom
Nick Kralevich27cb4102016-01-22 18:02:29 -0800125
Elliott Hughes5a0a51b2018-08-22 13:21:21 -0700126 symlink /proc/self/fd/0 /dev/stdin
127 symlink /proc/self/fd/1 /dev/stdout
128 symlink /proc/self/fd/2 /dev/stderr
129
Todd Kjosba8a4752015-10-26 16:22:11 -0700130 # Create energy-aware scheduler tuning nodes
Todd Kjos11cde562016-02-23 09:00:36 -0800131 mkdir /dev/stune/foreground
Tim Murray5dcff8f2016-07-11 13:57:31 -0700132 mkdir /dev/stune/background
Tim Murray955694b2016-07-11 11:40:15 -0700133 mkdir /dev/stune/top-app
Joel Fernandesf50d1092016-12-19 11:01:55 -0800134 mkdir /dev/stune/rt
Todd Kjos11cde562016-02-23 09:00:36 -0800135 chown system system /dev/stune
136 chown system system /dev/stune/foreground
Tim Murray5dcff8f2016-07-11 13:57:31 -0700137 chown system system /dev/stune/background
Tim Murray955694b2016-07-11 11:40:15 -0700138 chown system system /dev/stune/top-app
Joel Fernandesf50d1092016-12-19 11:01:55 -0800139 chown system system /dev/stune/rt
Todd Kjos11cde562016-02-23 09:00:36 -0800140 chown system system /dev/stune/tasks
141 chown system system /dev/stune/foreground/tasks
Tim Murray5dcff8f2016-07-11 13:57:31 -0700142 chown system system /dev/stune/background/tasks
Tim Murray955694b2016-07-11 11:40:15 -0700143 chown system system /dev/stune/top-app/tasks
Joel Fernandesf50d1092016-12-19 11:01:55 -0800144 chown system system /dev/stune/rt/tasks
Todd Kjos11cde562016-02-23 09:00:36 -0800145 chmod 0664 /dev/stune/tasks
146 chmod 0664 /dev/stune/foreground/tasks
Tim Murray5dcff8f2016-07-11 13:57:31 -0700147 chmod 0664 /dev/stune/background/tasks
Tim Murray955694b2016-07-11 11:40:15 -0700148 chmod 0664 /dev/stune/top-app/tasks
Joel Fernandesf50d1092016-12-19 11:01:55 -0800149 chmod 0664 /dev/stune/rt/tasks
Todd Kjosba8a4752015-10-26 16:22:11 -0700150
Suren Baghdasaryanc6baa192020-10-13 10:41:00 -0700151 # cpuctl hierarchy for devices using utilclamp
152 mkdir /dev/cpuctl/foreground
153 mkdir /dev/cpuctl/background
154 mkdir /dev/cpuctl/top-app
155 mkdir /dev/cpuctl/rt
Wei Wang77cb6a02020-11-18 16:04:08 -0800156 mkdir /dev/cpuctl/system
Wei Wangab879792020-11-24 00:26:40 -0800157 mkdir /dev/cpuctl/system-background
Rick Yiu014446d2021-10-20 22:52:43 +0800158 mkdir /dev/cpuctl/dex2oat
Suren Baghdasaryanc6baa192020-10-13 10:41:00 -0700159 chown system system /dev/cpuctl
160 chown system system /dev/cpuctl/foreground
161 chown system system /dev/cpuctl/background
162 chown system system /dev/cpuctl/top-app
163 chown system system /dev/cpuctl/rt
Wei Wang77cb6a02020-11-18 16:04:08 -0800164 chown system system /dev/cpuctl/system
Wei Wangab879792020-11-24 00:26:40 -0800165 chown system system /dev/cpuctl/system-background
Rick Yiu014446d2021-10-20 22:52:43 +0800166 chown system system /dev/cpuctl/dex2oat
Suren Baghdasaryanc6baa192020-10-13 10:41:00 -0700167 chown system system /dev/cpuctl/tasks
168 chown system system /dev/cpuctl/foreground/tasks
169 chown system system /dev/cpuctl/background/tasks
170 chown system system /dev/cpuctl/top-app/tasks
171 chown system system /dev/cpuctl/rt/tasks
Wei Wang77cb6a02020-11-18 16:04:08 -0800172 chown system system /dev/cpuctl/system/tasks
Wei Wangab879792020-11-24 00:26:40 -0800173 chown system system /dev/cpuctl/system-background/tasks
Rick Yiu014446d2021-10-20 22:52:43 +0800174 chown system system /dev/cpuctl/dex2oat/tasks
Suren Baghdasaryanc6baa192020-10-13 10:41:00 -0700175 chmod 0664 /dev/cpuctl/tasks
176 chmod 0664 /dev/cpuctl/foreground/tasks
177 chmod 0664 /dev/cpuctl/background/tasks
178 chmod 0664 /dev/cpuctl/top-app/tasks
179 chmod 0664 /dev/cpuctl/rt/tasks
Wei Wang77cb6a02020-11-18 16:04:08 -0800180 chmod 0664 /dev/cpuctl/system/tasks
Wei Wangab879792020-11-24 00:26:40 -0800181 chmod 0664 /dev/cpuctl/system-background/tasks
Rick Yiu014446d2021-10-20 22:52:43 +0800182 chmod 0664 /dev/cpuctl/dex2oat/tasks
Wei Wang77cb6a02020-11-18 16:04:08 -0800183
184 # Create a cpu group for NNAPI HAL processes
185 mkdir /dev/cpuctl/nnapi-hal
186 chown system system /dev/cpuctl/nnapi-hal
187 chown system system /dev/cpuctl/nnapi-hal/tasks
188 chmod 0664 /dev/cpuctl/nnapi-hal/tasks
189 write /dev/cpuctl/nnapi-hal/cpu.uclamp.min 1
190 write /dev/cpuctl/nnapi-hal/cpu.uclamp.latency_sensitive 1
191
Rick Yiua983f8a2020-12-01 15:45:01 +0800192 # Create a cpu group for camera daemon processes
193 mkdir /dev/cpuctl/camera-daemon
194 chown system system /dev/cpuctl/camera-daemon
195 chown system system /dev/cpuctl/camera-daemon/tasks
196 chmod 0664 /dev/cpuctl/camera-daemon/tasks
197
Wei Wang6a285722020-11-30 10:56:29 -0800198 # Create an stune group for camera-specific processes
199 mkdir /dev/stune/camera-daemon
200 chown system system /dev/stune/camera-daemon
201 chown system system /dev/stune/camera-daemon/tasks
202 chmod 0664 /dev/stune/camera-daemon/tasks
203
Miao Wangc3991a72020-02-07 15:01:24 -0800204 # Create an stune group for NNAPI HAL processes
205 mkdir /dev/stune/nnapi-hal
206 chown system system /dev/stune/nnapi-hal
207 chown system system /dev/stune/nnapi-hal/tasks
208 chmod 0664 /dev/stune/nnapi-hal/tasks
209 write /dev/stune/nnapi-hal/schedtune.boost 1
210 write /dev/stune/nnapi-hal/schedtune.prefer_idle 1
211
Rick Yiuc7bf1a02019-04-23 21:33:56 +0800212 # Create blkio group and apply initial settings.
213 # This feature needs kernel to support it, and the
214 # device's init.rc must actually set the correct values.
Rick Yiu2b3bf842019-02-21 14:37:36 +0800215 mkdir /dev/blkio/background
216 chown system system /dev/blkio
217 chown system system /dev/blkio/background
218 chown system system /dev/blkio/tasks
219 chown system system /dev/blkio/background/tasks
220 chmod 0664 /dev/blkio/tasks
221 chmod 0664 /dev/blkio/background/tasks
Rick Yiuc7bf1a02019-04-23 21:33:56 +0800222 write /dev/blkio/blkio.weight 1000
Rick Yiuad74d8d2020-06-04 14:28:19 +0800223 write /dev/blkio/background/blkio.weight 200
Daeho Jeong272e7a62021-02-15 14:37:01 +0900224 write /dev/blkio/background/blkio.bfq.weight 10
Rick Yiuc7bf1a02019-04-23 21:33:56 +0800225 write /dev/blkio/blkio.group_idle 0
226 write /dev/blkio/background/blkio.group_idle 0
Rick Yiu2b3bf842019-02-21 14:37:36 +0800227
Jeff Sharkeyfc000482015-03-16 10:17:47 -0700228 restorecon_recursive /mnt
Jeff Sharkey5dd0f862012-08-17 16:01:16 -0700229
Luis Hector Chavez87749452018-02-14 08:35:01 -0800230 mount configfs none /config nodev noexec nosuid
Daniel Rosenberg79035232017-11-29 14:49:08 -0800231 chmod 0770 /config/sdcardfs
Daniel Rosenberg4edec252016-02-18 19:48:31 -0800232 chown system package_info /config/sdcardfs
233
Hridya Valsarajub237d762020-02-03 12:33:57 -0800234 # Mount binderfs
235 mkdir /dev/binderfs
236 mount binder binder /dev/binderfs stats=global
237 chmod 0755 /dev/binderfs
238
Martijn Coenen959dcf12020-04-28 22:27:10 +0200239 # Mount fusectl
240 mount fusectl none /sys/fs/fuse/connections
241
Hridya Valsarajub237d762020-02-03 12:33:57 -0800242 symlink /dev/binderfs/binder /dev/binder
243 symlink /dev/binderfs/hwbinder /dev/hwbinder
244 symlink /dev/binderfs/vndbinder /dev/vndbinder
245
246 chmod 0666 /dev/binderfs/hwbinder
247 chmod 0666 /dev/binderfs/binder
248 chmod 0666 /dev/binderfs/vndbinder
249
San Mehat6ea3cc62010-02-19 18:25:22 -0800250 mkdir /mnt/secure 0700 root root
Jeff Sharkeyfc000482015-03-16 10:17:47 -0700251 mkdir /mnt/secure/asec 0700 root root
252 mkdir /mnt/asec 0755 root system
253 mkdir /mnt/obb 0755 root system
Zimc1b53de2020-01-24 22:13:58 +0000254 mkdir /mnt/media_rw 0750 root external_storage
Jeff Sharkeyfc000482015-03-16 10:17:47 -0700255 mkdir /mnt/user 0755 root root
256 mkdir /mnt/user/0 0755 root root
Zimc9f8e5d2019-08-09 20:02:49 +0100257 mkdir /mnt/user/0/self 0755 root root
258 mkdir /mnt/user/0/emulated 0755 root root
259 mkdir /mnt/user/0/emulated/0 0755 root root
Zimfc64dad2019-09-23 14:21:27 +0100260
261 # Prepare directories for pass through processes
Zim6ca090e2020-01-20 14:16:14 +0000262 mkdir /mnt/pass_through 0700 root root
Zima67b40b2020-01-31 16:26:13 +0000263 mkdir /mnt/pass_through/0 0710 root media_rw
264 mkdir /mnt/pass_through/0/self 0710 root media_rw
265 mkdir /mnt/pass_through/0/emulated 0710 root media_rw
266 mkdir /mnt/pass_through/0/emulated/0 0710 root media_rw
Zimfc64dad2019-09-23 14:21:27 +0100267
Jeff Sharkeyae0a5ac2015-04-06 14:08:54 -0700268 mkdir /mnt/expand 0771 system system
Daichi Hirono7abc71e2015-12-11 13:29:04 +0900269 mkdir /mnt/appfuse 0711 root root
San Mehat6ea3cc62010-02-19 18:25:22 -0800270
Jeff Sharkeyf38f29c2015-06-23 14:30:37 -0700271 # Storage views to support runtime permissions
Jeff Sharkeyb9f438f2015-08-06 11:39:44 -0700272 mkdir /mnt/runtime 0700 root root
273 mkdir /mnt/runtime/default 0755 root root
274 mkdir /mnt/runtime/default/self 0755 root root
275 mkdir /mnt/runtime/read 0755 root root
276 mkdir /mnt/runtime/read/self 0755 root root
277 mkdir /mnt/runtime/write 0755 root root
278 mkdir /mnt/runtime/write/self 0755 root root
Sudheer Shanka81c687d2019-01-16 23:25:28 -0800279 mkdir /mnt/runtime/full 0755 root root
280 mkdir /mnt/runtime/full/self 0755 root root
San Mehat6ea3cc62010-02-19 18:25:22 -0800281
Jeff Sharkeyfc000482015-03-16 10:17:47 -0700282 # Symlink to keep legacy apps working in multi-user world
Nick Kralevichd2f0a2c2016-04-12 20:36:01 -0700283 symlink /storage/self/primary /mnt/sdcard
Jeff Sharkeyb9f438f2015-08-06 11:39:44 -0700284 symlink /mnt/user/0/primary /mnt/runtime/default/self/primary
Kenny Rootc7858a32010-07-15 12:14:44 -0700285
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800286 write /proc/sys/kernel/panic_on_oops 1
287 write /proc/sys/kernel/hung_task_timeout_secs 0
288 write /proc/cpu/alignment 4
Riley Andrewse850f572015-07-20 16:01:48 -0700289
290 # scheduler tunables
291 # Disable auto-scaling of scheduler tunables with hotplug. The tunables
292 # will vary across devices in unpredictable ways if allowed to scale with
293 # cpu cores.
294 write /proc/sys/kernel/sched_tunable_scaling 0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800295 write /proc/sys/kernel/sched_latency_ns 10000000
296 write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000
San Mehat7baff712009-09-16 13:32:23 -0700297 write /proc/sys/kernel/sched_child_runs_first 0
Riley Andrewse850f572015-07-20 16:01:48 -0700298
Nick Kralevichd707fb32011-10-06 11:47:11 -0700299 write /proc/sys/kernel/randomize_va_space 2
Nick Kralevich27cca212011-12-05 14:48:08 -0800300 write /proc/sys/vm/mmap_min_addr 32768
Nick Kralevichbe341cc2013-02-21 18:36:43 -0800301 write /proc/sys/net/ipv4/ping_group_range "0 2147483647"
Mark Salyzyn39944c82015-09-08 11:24:07 -0700302 write /proc/sys/net/unix/max_dgram_qlen 600
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800303
Sandeep Patil5fee4962016-12-07 10:55:45 -0800304 # Assign reasonable ceiling values for socket rcv/snd buffers.
305 # These should almost always be overridden by the target per the
306 # the corresponding technology maximums.
307 write /proc/sys/net/core/rmem_max 262144
308 write /proc/sys/net/core/wmem_max 262144
309
Sreeram Ramachandranfd949222014-04-09 17:44:56 -0700310 # reflect fwmark from incoming packets onto generated replies
311 write /proc/sys/net/ipv4/fwmark_reflect 1
312 write /proc/sys/net/ipv6/fwmark_reflect 1
313
314 # set fwmark on accepted sockets
315 write /proc/sys/net/ipv4/tcp_fwmark_accept 1
316
Greg Hackmannf3fd1222014-12-03 09:57:00 -0800317 # disable icmp redirects
318 write /proc/sys/net/ipv4/conf/all/accept_redirects 0
319 write /proc/sys/net/ipv6/conf/all/accept_redirects 0
320
Nick Kralevich15ffc532017-08-25 12:55:52 -0700321 # /proc/net/fib_trie leaks interface IP addresses
322 chmod 0400 /proc/net/fib_trie
323
Tim Murrayb769c8d2015-06-08 14:56:29 -0700324 # sets up initial cpusets for ActivityManager
Tim Murrayb769c8d2015-06-08 14:56:29 -0700325 # this ensures that the cpusets are present and usable, but the device's
326 # init.rc must actually set the correct cpus
Tim Murrayf429d372015-10-15 12:38:15 -0700327 mkdir /dev/cpuset/foreground
Wei Wang8dbd12b2017-04-13 18:27:35 -0700328 copy /dev/cpuset/cpus /dev/cpuset/foreground/cpus
329 copy /dev/cpuset/mems /dev/cpuset/foreground/mems
Tim Murrayf429d372015-10-15 12:38:15 -0700330 mkdir /dev/cpuset/background
Wei Wang8dbd12b2017-04-13 18:27:35 -0700331 copy /dev/cpuset/cpus /dev/cpuset/background/cpus
332 copy /dev/cpuset/mems /dev/cpuset/background/mems
Tim Murrayf429d372015-10-15 12:38:15 -0700333
334 # system-background is for system tasks that should only run on
335 # little cores, not on bigs
Tim Murrayf429d372015-10-15 12:38:15 -0700336 mkdir /dev/cpuset/system-background
Wei Wang8dbd12b2017-04-13 18:27:35 -0700337 copy /dev/cpuset/cpus /dev/cpuset/system-background/cpus
338 copy /dev/cpuset/mems /dev/cpuset/system-background/mems
Tim Murrayf429d372015-10-15 12:38:15 -0700339
Tim Murray658ae902018-04-13 10:15:49 -0700340 # restricted is for system tasks that are being throttled
341 # due to screen off.
342 mkdir /dev/cpuset/restricted
343 copy /dev/cpuset/cpus /dev/cpuset/restricted/cpus
344 copy /dev/cpuset/mems /dev/cpuset/restricted/mems
345
Tim Murray6647bb52016-01-11 16:16:35 -0800346 mkdir /dev/cpuset/top-app
Wei Wang8dbd12b2017-04-13 18:27:35 -0700347 copy /dev/cpuset/cpus /dev/cpuset/top-app/cpus
348 copy /dev/cpuset/mems /dev/cpuset/top-app/mems
Tim Murray6647bb52016-01-11 16:16:35 -0800349
Rick Yiua983f8a2020-12-01 15:45:01 +0800350 # create a cpuset for camera daemon processes
351 mkdir /dev/cpuset/camera-daemon
352 copy /dev/cpuset/cpus /dev/cpuset/camera-daemon/cpus
353 copy /dev/cpuset/mems /dev/cpuset/camera-daemon/mems
354
Tim Murrayf429d372015-10-15 12:38:15 -0700355 # change permissions for all cpusets we'll touch at runtime
Tim Murrayb769c8d2015-06-08 14:56:29 -0700356 chown system system /dev/cpuset
357 chown system system /dev/cpuset/foreground
358 chown system system /dev/cpuset/background
Todd Kjosba8a4752015-10-26 16:22:11 -0700359 chown system system /dev/cpuset/system-background
Tim Murray6647bb52016-01-11 16:16:35 -0800360 chown system system /dev/cpuset/top-app
Tim Murray658ae902018-04-13 10:15:49 -0700361 chown system system /dev/cpuset/restricted
Rick Yiua983f8a2020-12-01 15:45:01 +0800362 chown system system /dev/cpuset/camera-daemon
Tim Murrayb769c8d2015-06-08 14:56:29 -0700363 chown system system /dev/cpuset/tasks
364 chown system system /dev/cpuset/foreground/tasks
365 chown system system /dev/cpuset/background/tasks
Todd Kjosba8a4752015-10-26 16:22:11 -0700366 chown system system /dev/cpuset/system-background/tasks
Tim Murray6647bb52016-01-11 16:16:35 -0800367 chown system system /dev/cpuset/top-app/tasks
Tim Murray658ae902018-04-13 10:15:49 -0700368 chown system system /dev/cpuset/restricted/tasks
Rick Yiua983f8a2020-12-01 15:45:01 +0800369 chown system system /dev/cpuset/camera-daemon/tasks
Tim Murray4284f9f2015-11-10 14:31:09 -0800370
371 # set system-background to 0775 so SurfaceFlinger can touch it
372 chmod 0775 /dev/cpuset/system-background
373
Jeff Vander Stoep3f62a022015-07-23 15:18:36 -0700374 chmod 0664 /dev/cpuset/foreground/tasks
375 chmod 0664 /dev/cpuset/background/tasks
Todd Kjosba8a4752015-10-26 16:22:11 -0700376 chmod 0664 /dev/cpuset/system-background/tasks
Tim Murray6647bb52016-01-11 16:16:35 -0800377 chmod 0664 /dev/cpuset/top-app/tasks
Tim Murray658ae902018-04-13 10:15:49 -0700378 chmod 0664 /dev/cpuset/restricted/tasks
Jeff Vander Stoep3f62a022015-07-23 15:18:36 -0700379 chmod 0664 /dev/cpuset/tasks
Rick Yiua983f8a2020-12-01 15:45:01 +0800380 chmod 0664 /dev/cpuset/camera-daemon/tasks
Tim Murrayb769c8d2015-06-08 14:56:29 -0700381
Tim Murray1504cb52019-02-15 11:51:09 -0800382 # make the PSI monitor accessible to others
383 chown system system /proc/pressure/memory
384 chmod 0664 /proc/pressure/memory
Tim Murrayb769c8d2015-06-08 14:56:29 -0700385
Riley Andrews6dfdc7c2014-06-18 20:35:40 -0700386 # qtaguid will limit access to specific data based on group memberships.
387 # net_bw_acct grants impersonation of socket owners.
388 # net_bw_stats grants access to other apps' detailed tagged-socket stats.
JP Abgrall3e54aab2013-01-04 14:34:58 -0800389 chown root net_bw_acct /proc/net/xt_qtaguid/ctrl
390 chown root net_bw_stats /proc/net/xt_qtaguid/stats
391
Riley Andrews6dfdc7c2014-06-18 20:35:40 -0700392 # Allow everybody to read the xt_qtaguid resource tracking misc dev.
393 # This is needed by any process that uses socket tagging.
JP Abgrall8e3ff702011-09-11 16:12:27 -0700394 chmod 0644 /dev/xt_qtaguid
395
Luis Hector Chavezf8a7e372018-02-12 11:30:46 -0800396 mount bpf bpf /sys/fs/bpf nodev noexec nosuid
Chenbo Feng2cba6f22017-10-23 11:57:59 -0700397
Riley Andrews6dfdc7c2014-06-18 20:35:40 -0700398 # Create location for fs_mgr to store abbreviated output from filesystem
399 # checker programs.
Ken Sumrall4eaf9052013-09-18 17:49:21 -0700400 mkdir /dev/fscklogs 0770 root system
401
Riley Andrews6dfdc7c2014-06-18 20:35:40 -0700402 # pstore/ramoops previous console log
Luis Hector Chavezf8a7e372018-02-12 11:30:46 -0800403 mount pstore pstore /sys/fs/pstore nodev noexec nosuid
Mark Salyzyn7ab805e2018-06-29 10:32:11 -0700404 chown system log /sys/fs/pstore
405 chmod 0550 /sys/fs/pstore
Todd Poynor479efb52013-11-21 20:23:54 -0800406 chown system log /sys/fs/pstore/console-ramoops
407 chmod 0440 /sys/fs/pstore/console-ramoops
Mark Salyzyn4eb0ba02017-06-27 09:32:32 -0700408 chown system log /sys/fs/pstore/console-ramoops-0
409 chmod 0440 /sys/fs/pstore/console-ramoops-0
Mark Salyzyn4b0313e2014-12-15 07:52:19 -0800410 chown system log /sys/fs/pstore/pmsg-ramoops-0
411 chmod 0440 /sys/fs/pstore/pmsg-ramoops-0
Todd Poynor479efb52013-11-21 20:23:54 -0800412
Greg Hackmanncee87572015-01-26 10:40:29 -0800413 # enable armv8_deprecated instruction hooks
414 write /proc/sys/abi/swp 1
415
Greg Hackmann40a96e42016-02-01 09:59:44 -0800416 # Linux's execveat() syscall may construct paths containing /dev/fd
417 # expecting it to point to /proc/self/fd
418 symlink /proc/self/fd /dev/fd
419
Yueyao (Nathan) Zhu60c6dac2016-06-21 12:04:54 -0700420 export DOWNLOAD_CACHE /data/cache
421
David Lin27b2c1e2017-03-08 17:36:18 -0800422 # This allows the ledtrig-transient properties to be created here so
423 # that they can be chown'd to system:system later on boot
424 write /sys/class/leds/vibrator/trigger "transient"
425
Haibo Huangd60a19b2018-11-04 09:50:05 -0800426 # This is used by Bionic to select optimized routines.
427 write /dev/cpu_variant:${ro.bionic.arch} ${ro.bionic.cpu_variant}
428 chmod 0444 /dev/cpu_variant:${ro.bionic.arch}
429 write /dev/cpu_variant:${ro.bionic.2nd_arch} ${ro.bionic.2nd_cpu_variant}
430 chmod 0444 /dev/cpu_variant:${ro.bionic.2nd_arch}
431
Yifan Hongc9a9d272019-04-08 13:29:07 -0700432 # Allow system processes to read / write power state.
433 chown system system /sys/power/state
434 chown system system /sys/power/wakeup_count
435 chmod 0660 /sys/power/state
436
Tri Voc6a84e82019-07-16 14:31:55 -0700437 chown radio wakelock /sys/power/wake_lock
438 chown radio wakelock /sys/power/wake_unlock
439 chmod 0660 /sys/power/wake_lock
440 chmod 0660 /sys/power/wake_unlock
441
Tom Cherryf18b7482018-10-17 13:14:55 -0700442 # Start logd before any other services run to ensure we capture all of their logs.
443 start logd
Suren Baghdasaryanc29c2ba2019-10-22 17:18:42 -0700444 # Start lmkd before any other services run so that it can register them
Martin Liu9f8b0242021-07-01 11:55:02 +0800445 write /proc/sys/vm/watermark_boost_factor 0
Suren Baghdasaryan68986822020-02-13 16:17:10 -0800446 chown root system /sys/module/lowmemorykiller/parameters/adj
447 chmod 0664 /sys/module/lowmemorykiller/parameters/adj
448 chown root system /sys/module/lowmemorykiller/parameters/minfree
449 chmod 0664 /sys/module/lowmemorykiller/parameters/minfree
Suren Baghdasaryanc29c2ba2019-10-22 17:18:42 -0700450 start lmkd
Jiyong Park407b0002019-02-02 19:45:23 +0900451
Tom Cherryf18b7482018-10-17 13:14:55 -0700452 # Start essential services.
453 start servicemanager
454 start hwservicemanager
455 start vndservicemanager
456
Riley Andrewse4b7b292014-06-16 15:06:21 -0700457# Healthd can trigger a full boot from charger mode by signaling this
458# property when the power button is held.
459on property:sys.boot_from_charger_mode=1
460 class_stop charger
461 trigger late-init
462
Riley Andrews80c7a5e2014-07-11 15:05:23 -0700463# Indicate to fw loaders that the relevant mounts are up.
464on firmware_mounts_complete
465 rm /dev/.booting
466
Riley Andrewse4b7b292014-06-16 15:06:21 -0700467# Mount filesystems and start core system services.
468on late-init
469 trigger early-fs
Wei Wangabfbec32016-08-23 11:58:09 -0700470
471 # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
472 # '--early' can be specified to skip entries with 'latemount'.
473 # /system and /vendor must be mounted by the end of the fs stage,
474 # while /data is optional.
Riley Andrewse4b7b292014-06-16 15:06:21 -0700475 trigger fs
476 trigger post-fs
Riley Andrewse4b7b292014-06-16 15:06:21 -0700477
Wei Wangabfbec32016-08-23 11:58:09 -0700478 # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
479 # to only mount entries with 'latemount'. This is needed if '--early' is
480 # specified in the previous mount_all command on the fs stage.
481 # With /system mounted and properties form /system + /factory available,
482 # some services can be started.
483 trigger late-fs
484
Paul Lawrence948410a2015-07-01 14:40:56 -0700485 # Now we can mount /data. File encryption requires keymaster to decrypt
Wei Wangabfbec32016-08-23 11:58:09 -0700486 # /data, which in turn can only be loaded when system properties are present.
Paul Lawrence948410a2015-07-01 14:40:56 -0700487 trigger post-fs-data
Wei Wangabfbec32016-08-23 11:58:09 -0700488
Maciej Żenczykowski6c72c162020-06-22 01:11:24 -0700489 # Should be before netd, but after apex, properties and logging is available.
490 trigger load_bpf_programs
491
Wei Wangfa14d212018-09-05 10:12:40 -0700492 # Now we can start zygote for devices with file based encryption
493 trigger zygote-start
494
Riley Andrews67cb1ae2014-07-15 20:39:41 -0700495 # Remove a file to wake up anything waiting for firmware.
496 trigger firmware_mounts_complete
497
Riley Andrewse4b7b292014-06-16 15:06:21 -0700498 trigger early-boot
499 trigger boot
500
Daniel Rosenberg1be83e32019-06-17 13:23:05 -0700501on early-fs
502 # Once metadata has been mounted, we'll need vold to deal with userdata checkpointing
Daniel Rosenberg6156b9b2018-10-11 15:35:07 -0700503 start vold
Daniel Rosenberg1be83e32019-06-17 13:23:05 -0700504
505on post-fs
Daniel Rosenberg6156b9b2018-10-11 15:35:07 -0700506 exec - system system -- /system/bin/vdc checkpoint markBootAttempt
Steven Morelandd6275022017-03-24 16:23:07 +0000507
Luis Hector Chavez30780a72018-02-14 08:36:16 -0800508 # Once everything is setup, no need to modify /.
Luis Hector Chavezd07d0942018-07-11 08:13:34 -0700509 # The bind+remount combination allows this to work in containers.
510 mount rootfs rootfs / remount bind ro nodev
Brian Swetland56de7a12010-09-08 15:06:45 -0700511
Zimc46c2352020-09-11 11:06:29 +0100512 # Mount default storage into root namespace
513 mount none /mnt/user/0 /storage bind rec
514 mount none none /storage slave rec
515
Nick Kralevich715c4dc2015-12-07 16:57:08 -0800516 # Make sure /sys/kernel/debug (if present) is labeled properly
Paul Lawrencea8d84342016-11-14 15:40:18 -0800517 # Note that tracefs may be mounted under debug, so we need to cross filesystems
518 restorecon --recursive --cross-filesystems /sys/kernel/debug
Paul Lawrenced2abcbd2016-11-02 14:23:31 -0700519
Ken Sumrall752923c2010-12-03 16:33:31 -0800520 # We chown/chmod /cache again so because mount is run as root + defaults
521 chown system cache /cache
522 chmod 0770 /cache
Stephen Smalley1eee4192012-01-13 08:54:34 -0500523 # We restorecon /cache in case the cache partition has been reset.
Nick Kraleviche1695912014-07-09 12:39:21 -0700524 restorecon_recursive /cache
Ken Sumrall752923c2010-12-03 16:33:31 -0800525
Tao Baoe48aed02015-05-11 14:08:18 -0700526 # Create /cache/recovery in case it's not there. It'll also fix the odd
527 # permissions if created by the recovery system.
528 mkdir /cache/recovery 0770 system cache
Ken Sumrall752923c2010-12-03 16:33:31 -0800529
Christopher Tate63c463f2016-01-28 17:09:42 -0800530 # Backup/restore mechanism uses the cache partition
531 mkdir /cache/backup_stage 0700 system system
532 mkdir /cache/backup 0700 system system
533
Ken Sumrall752923c2010-12-03 16:33:31 -0800534 #change permissions on vmallocinfo so we can grab it from bugreports
535 chown root log /proc/vmallocinfo
536 chmod 0440 /proc/vmallocinfo
537
Dima Zavin94812662012-09-25 14:22:02 -0700538 chown root log /proc/slabinfo
539 chmod 0440 /proc/slabinfo
540
Martin Liu0abd0d62020-06-14 17:21:13 +0800541 chown root log /proc/pagetypeinfo
542 chmod 0440 /proc/pagetypeinfo
543
Ken Sumrall752923c2010-12-03 16:33:31 -0800544 #change permissions on kmsg & sysrq-trigger so bugreports can grab kthread stacks
545 chown root system /proc/kmsg
546 chmod 0440 /proc/kmsg
547 chown root system /proc/sysrq-trigger
548 chmod 0220 /proc/sysrq-trigger
Colin Crossb35e36e2012-08-02 18:14:33 -0700549 chown system log /proc/last_kmsg
550 chmod 0440 /proc/last_kmsg
Ken Sumrall752923c2010-12-03 16:33:31 -0800551
dcashman5822a4a2014-03-25 16:31:07 -0700552 # make the selinux kernel policy world-readable
553 chmod 0444 /sys/fs/selinux/policy
554
Ken Sumrall752923c2010-12-03 16:33:31 -0800555 # create the lost+found directories, so as to enforce our permissions
Chia-chi Yehea744142011-07-08 16:52:18 -0700556 mkdir /cache/lost+found 0770 root root
Ken Sumrall752923c2010-12-03 16:33:31 -0800557
Paul Crowleyfe305ab2018-05-17 10:12:34 -0700558 restorecon_recursive /metadata
559 mkdir /metadata/vold
560 chmod 0700 /metadata/vold
David Anderson0664f312019-03-05 22:16:36 -0800561 mkdir /metadata/password_slots 0771 root system
Mark Salyzynee016ce2019-05-23 10:00:34 -0700562 mkdir /metadata/bootstat 0750 system log
David Anderson001747e2019-07-03 15:10:53 -0700563 mkdir /metadata/ota 0700 root system
David Anderson456e5012019-08-01 14:37:35 -0700564 mkdir /metadata/ota/snapshots 0700 root system
Gavin Corkery8c922562020-05-11 14:10:09 +0100565 mkdir /metadata/userspacereboot 0770 root system
Gavin Corkerybadf3962020-12-05 17:25:09 +0000566 mkdir /metadata/watchdog 0770 root system
Paul Crowleyfe305ab2018-05-17 10:12:34 -0700567
Martijn Coenen4517e572019-03-12 22:05:20 +0100568 mkdir /metadata/apex 0700 root system
569 mkdir /metadata/apex/sessions 0700 root system
Nikita Ioffea4620442020-06-22 17:47:23 +0100570 # On some devices we see a weird behaviour in which /metadata/apex doesn't
571 # have a correct label. To workaround this bug, explicitly call restorecon
572 # on /metadata/apex. For most of the boot sequences /metadata/apex will
573 # already have a correct selinux label, meaning that this call will be a
574 # no-op.
575 restorecon_recursive /metadata/apex
576
Mohammad Samiul Islamd192d542020-05-07 15:52:48 +0100577 mkdir /metadata/staged-install 0770 root system
Jeff Vander Stoep75d0b332021-11-17 08:55:35 +0100578 mkdir /metadata/sepolicy 0700 root root
Janis Danisevskis1ad8d212017-04-06 12:44:59 -0700579on late-fs
Joel Galensond48c4cf2017-06-13 10:15:05 -0700580 # Ensure that tracefs has the correct permissions.
581 # This does not work correctly if it is called in post-fs.
Alistair Delvaebb5b3b2020-01-29 09:10:47 -0800582 chmod 0755 /sys/kernel/tracing
Joel Galensond48c4cf2017-06-13 10:15:05 -0700583 chmod 0755 /sys/kernel/debug/tracing
584
Janis Danisevskis1ad8d212017-04-06 12:44:59 -0700585 # HALs required before storage encryption can get unlocked (FBE/FDE)
586 class_start early_hal
587
Martijn Coenen3b68bf22020-11-30 10:05:40 +0100588 # Load trusted keys from dm-verity protected partitions
589 exec -- /system/bin/fsverity_init --load-verified-keys
590
Alexander Potapenko53cd1e92021-09-29 13:30:02 +0000591# Only enable the bootreceiver tracing instance for kernels 5.10 and above.
592on late-fs && property:ro.kernel.version=4.9
593 setprop bootreceiver.enable 0
594on late-fs && property:ro.kernel.version=4.14
595 setprop bootreceiver.enable 0
596on late-fs && property:ro.kernel.version=4.19
597 setprop bootreceiver.enable 0
598on late-fs && property:ro.kernel.version=5.4
599 setprop bootreceiver.enable 0
600on late-fs
601 # Bootreceiver tracing instance is enabled by default.
602 setprop bootreceiver.enable ${bootreceiver.enable:-1}
603
604on property:ro.product.cpu.abilist64=* && property:bootreceiver.enable=1
Alexander Potapenko439608b2021-03-02 16:50:16 +0100605 # Set up a tracing instance for system_server to monitor error_report_end events.
606 # These are sent by kernel tools like KASAN and KFENCE when a memory corruption
Alexander Potapenkoec37ba82021-08-03 07:47:40 +0000607 # is detected. This is only needed for 64-bit systems.
Alexander Potapenko439608b2021-03-02 16:50:16 +0100608 mkdir /sys/kernel/tracing/instances/bootreceiver 0700 system system
609 restorecon_recursive /sys/kernel/tracing/instances/bootreceiver
610 write /sys/kernel/tracing/instances/bootreceiver/buffer_size_kb 1
611 write /sys/kernel/tracing/instances/bootreceiver/trace_options disable_on_free
612 write /sys/kernel/tracing/instances/bootreceiver/events/error_report/error_report_end/enable 1
613
Ken Sumrall752923c2010-12-03 16:33:31 -0800614on post-fs-data
Martijn Coenene94b3662021-03-09 10:57:00 +0100615
Martijn Coenenf0bc58a2019-04-23 16:26:01 +0200616 mark_post_data
617
Paul Lawrenceb920cb42018-10-04 08:37:17 -0700618 # Start checkpoint before we touch data
Paul Lawrenceb920cb42018-10-04 08:37:17 -0700619 exec - system system -- /system/bin/vdc checkpoint prepareCheckpoint
620
Colin Cross31712be2010-04-09 12:26:06 -0700621 # We chown/chmod /data again so because mount is run as root + defaults
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800622 chown system system /data
623 chmod 0771 /data
Stephen Smalley1eee4192012-01-13 08:54:34 -0500624 # We restorecon /data in case the userdata partition has been reset.
625 restorecon /data
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800626
Elliott Hughes2f74a5d2016-02-02 09:15:59 -0800627 # Make sure we have the device encryption key.
Paul Lawrence806d10b2015-04-28 22:07:10 +0000628 installkey /data
629
Yongqin Liua197ff12014-12-05 13:45:02 +0800630 # Start bootcharting as soon as possible after the data partition is
631 # mounted to collect more data.
Paul Crowley68258e82019-10-28 07:55:03 -0700632 mkdir /data/bootchart 0755 shell shell encryption=Require
Elliott Hughesa3641af2016-11-10 17:43:47 -0800633 bootchart start
Yongqin Liua197ff12014-12-05 13:45:02 +0800634
Paul Crowley7583da12021-04-08 17:04:43 +0000635 # Avoid predictable entropy pool. Carry over entropy from previous boot.
636 copy /data/system/entropy.dat /dev/urandom
637
Tom Cherry2c9c8eb2020-10-16 10:02:40 -0700638 mkdir /data/vendor 0771 root root encryption=Require
639 mkdir /data/vendor_ce 0771 root root encryption=None
640 mkdir /data/vendor_de 0771 root root encryption=None
641 mkdir /data/vendor/hardware 0771 root root
642
Josh Gao81c94cd2020-10-01 13:01:15 -0700643 # Start tombstoned early to be able to store tombstones.
Kevin Brodsky13d86ad2020-12-17 15:32:50 +0000644 mkdir /data/anr 0775 system system encryption=Require
Josh Gao81c94cd2020-10-01 13:01:15 -0700645 mkdir /data/tombstones 0771 system system encryption=Require
646 mkdir /data/vendor/tombstones 0771 root root
647 mkdir /data/vendor/tombstones/wifi 0771 wifi wifi
648 start tombstoned
649
Kevin Brodsky13d86ad2020-12-17 15:32:50 +0000650 # Make sure that apexd is started in the default namespace
651 enter_default_mount_ns
652
Paul Crowley7583da12021-04-08 17:04:43 +0000653 # set up keystore directory structure first so that we can end early boot
654 # and start apexd
655 mkdir /data/misc 01771 system misc encryption=Require
656 mkdir /data/misc/keystore 0700 keystore keystore
657 # work around b/183668221
658 restorecon /data/misc /data/misc/keystore
659
660 # Boot level 30
661 # odsign signing keys have MAX_BOOT_LEVEL=30
662 # This is currently the earliest boot level, but we start at 30
663 # to leave room for earlier levels.
664 setprop keystore.boot_level 30
665
666 # Now that /data is mounted and we have created /data/misc/keystore,
667 # we can tell keystore to stop allowing use of early-boot keys,
668 # and access its database for the first time to support creation and
669 # use of MAX_BOOT_LEVEL keys.
670 exec - system system -- /system/bin/vdc keymaster earlyBootEnded
671
Daniel Normanebaa3e52021-11-16 20:28:29 +0000672 # Multi-installed APEXes are selected using persist props.
673 # Load persist properties and override properties (if enabled) from /data,
674 # before starting apexd.
675 load_persist_props
676 start logd
677 start logd-reinit
678 # Some existing vendor rc files use 'on load_persist_props_action' to know
679 # when persist props are ready. These are difficult to change due to GRF,
680 # so continue triggering this action here even though props are already loaded
681 # by the 'load_persist_props' call above.
682 trigger load_persist_props_action
683
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +0900684 # /data/apex is now available. Start apexd to scan and activate APEXes.
Eric Biggers915b8d72021-04-28 10:15:38 -0700685 #
686 # To handle userspace reboots as well as devices that use FDE, make sure
687 # that apexd is started cleanly here (set apexd.status="") and that it is
688 # restarted if it's already running.
Nikita Ioffeb8591b52020-04-21 20:50:53 +0100689 mkdir /data/apex 0755 root system encryption=None
690 mkdir /data/apex/active 0755 root system
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +0900691 mkdir /data/apex/backup 0700 root system
Mohammad Samiul Islam60e30a52021-04-27 21:44:10 +0100692 mkdir /data/apex/decompressed 0755 root system encryption=Require
Jooyung Hanbaa7c132019-04-18 11:01:35 +0900693 mkdir /data/apex/hashtree 0700 root system
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +0900694 mkdir /data/apex/sessions 0700 root system
Mohammad Samiul Islam64fe2c62020-12-09 21:05:28 +0000695 mkdir /data/app-staging 0751 system system encryption=DeleteIfNecessary
Kelvin Zhang1f455c82021-02-10 09:32:17 -0500696 mkdir /data/apex/ota_reserved 0700 root system encryption=Require
Eric Biggers915b8d72021-04-28 10:15:38 -0700697 setprop apexd.status ""
698 restart apexd
Martijn Coenen3848e1b2018-08-17 13:52:25 +0200699
Paul Crowley7583da12021-04-08 17:04:43 +0000700 # create rest of basic filesystem structure
Mark Salyzyn93394032017-07-14 10:37:57 -0700701 mkdir /data/misc/recovery 0770 system log
Siqi Linb9b76de2017-07-26 13:18:15 -0700702 copy /data/misc/recovery/ro.build.fingerprint /data/misc/recovery/ro.build.fingerprint.1
703 chmod 0440 /data/misc/recovery/ro.build.fingerprint.1
704 chown system log /data/misc/recovery/ro.build.fingerprint.1
705 write /data/misc/recovery/ro.build.fingerprint ${ro.build.fingerprint}
706 chmod 0440 /data/misc/recovery/ro.build.fingerprint
707 chown system log /data/misc/recovery/ro.build.fingerprint
Mark Salyzyn93394032017-07-14 10:37:57 -0700708 mkdir /data/misc/recovery/proc 0770 system log
709 copy /data/misc/recovery/proc/version /data/misc/recovery/proc/version.1
710 chmod 0440 /data/misc/recovery/proc/version.1
711 chown system log /data/misc/recovery/proc/version.1
712 copy /proc/version /data/misc/recovery/proc/version
713 chmod 0440 /data/misc/recovery/proc/version
714 chown system log /data/misc/recovery/proc/version
Ajay Panicker604208e2016-09-20 11:52:14 -0700715 mkdir /data/misc/bluedroid 02770 bluetooth bluetooth
Pavlin Radoslavov8175bb22015-06-19 19:12:46 -0700716 # Fix the access permissions and group ownership for 'bt_config.conf'
717 chmod 0660 /data/misc/bluedroid/bt_config.conf
Ajay Panicker604208e2016-09-20 11:52:14 -0700718 chown bluetooth bluetooth /data/misc/bluedroid/bt_config.conf
719 mkdir /data/misc/bluetooth 0770 bluetooth bluetooth
720 mkdir /data/misc/bluetooth/logs 0770 bluetooth bluetooth
Jack Yu6097da82020-07-08 17:08:16 +0800721 mkdir /data/misc/nfc 0770 nfc nfc
722 mkdir /data/misc/nfc/logs 0770 nfc nfc
David Zeuthene83f3862019-10-28 13:42:14 -0400723 mkdir /data/misc/credstore 0700 credstore credstore
Andres Morales6a49c2f2015-04-16 13:16:24 -0700724 mkdir /data/misc/gatekeeper 0700 system system
Brian Carlstrom04918932011-06-30 22:50:29 -0700725 mkdir /data/misc/keychain 0771 system system
Sreeram Ramachandranb46efdb2014-07-07 22:09:54 -0700726 mkdir /data/misc/net 0750 root shell
Robert Greenwalt2aa33a32013-07-16 09:46:17 -0700727 mkdir /data/misc/radio 0770 system radio
Robert Greenwaltd6d47802012-09-26 16:04:27 -0700728 mkdir /data/misc/sms 0770 system radio
fionaxu06b8e2e2017-11-21 12:31:57 -0800729 mkdir /data/misc/carrierid 0770 system radio
Niklas Lindgrenfd665382018-05-21 16:53:00 +0200730 mkdir /data/misc/apns 0770 system radio
Shuo Qianf0e65d82019-10-14 13:24:58 -0700731 mkdir /data/misc/emergencynumberdb 0770 system radio
Elliott Hughesf820e852012-10-19 18:10:05 -0700732 mkdir /data/misc/zoneinfo 0775 system system
Ricky Wai88d5dcb2017-10-27 16:35:35 +0100733 mkdir /data/misc/network_watchlist 0774 system system
Abodunrinwa Tokid6ab6452017-04-27 18:46:59 +0100734 mkdir /data/misc/textclassifier 0771 system system
Chia-chi Yeh9bb4d412011-07-08 20:03:03 -0700735 mkdir /data/misc/vpn 0770 system vpn
Torne (Richard Coles)234f6962014-05-22 18:40:21 +0100736 mkdir /data/misc/shared_relro 0771 shared_relro shared_relro
Oscar Montemayord0aa32c2010-01-06 13:18:12 -0800737 mkdir /data/misc/systemkeys 0700 system system
Mike Lockwood48d116e2009-07-08 18:42:08 -0400738 mkdir /data/misc/wifi 0770 wifi wifi
Stephen Smalley82e87ed2014-01-29 13:53:03 -0500739 mkdir /data/misc/wifi/sockets 0770 wifi wifi
Stephen Smalley82e87ed2014-01-29 13:53:03 -0500740 mkdir /data/misc/wifi/wpa_supplicant 0770 wifi wifi
Jaewan Kim373d9fa2014-03-10 17:13:07 +0900741 mkdir /data/misc/ethernet 0770 system system
Stephen Smalley82e87ed2014-01-29 13:53:03 -0500742 mkdir /data/misc/dhcp 0770 dhcp dhcp
Robin Lee3094f822014-04-25 15:21:35 +0100743 mkdir /data/misc/user 0771 root root
Stephen Smalley82e87ed2014-01-29 13:53:03 -0500744 # give system access to wpa_supplicant.conf for backup and restore
Amith Yamasanieefef322009-07-02 12:08:13 -0700745 chmod 0660 /data/misc/wifi/wpa_supplicant.conf
Paul Crowley68258e82019-10-28 07:55:03 -0700746 mkdir /data/local 0751 root root encryption=Require
Glenn Kastenb0f908a2013-02-22 14:54:45 -0800747 mkdir /data/misc/media 0700 media media
Glenn Kasten845a4ff2016-02-23 15:23:46 -0800748 mkdir /data/misc/audioserver 0700 audioserver audioserver
Keun Soo Yimbe54c542016-03-01 12:45:27 -0800749 mkdir /data/misc/cameraserver 0700 cameraserver cameraserver
Paul Crowleyf8a6fa52015-06-03 13:33:43 +0100750 mkdir /data/misc/vold 0700 root root
Yasuhiro Matsudaf93db4b2015-06-15 18:49:35 +0900751 mkdir /data/misc/boottrace 0771 system shell
David Zeuthen15914782015-10-07 14:00:55 -0400752 mkdir /data/misc/update_engine 0700 root root
Tianjie Xu74fa3ca2017-11-03 10:59:36 -0700753 mkdir /data/misc/update_engine_log 02750 root log
Calin Juravle9b3e5d52015-11-10 19:16:43 +0000754 mkdir /data/misc/trace 0700 root root
Vishnu Naird09ab7a2017-11-27 09:54:31 -0800755 # create location to store surface and window trace files
756 mkdir /data/misc/wmtrace 0700 system system
Hongming Jin87f55fe2021-02-09 11:54:46 -0800757 # create location to store accessibility trace files
758 mkdir /data/misc/a11ytrace 0700 system system
Calin Juravle807f23a2016-02-01 19:27:01 +0000759 # profile file layout
760 mkdir /data/misc/profiles 0771 system system
761 mkdir /data/misc/profiles/cur 0771 system system
Calin Juravle11197dd2021-05-14 11:28:04 -0700762 mkdir /data/misc/profiles/ref 0771 system system
David Sehr0eb24e12016-05-28 14:10:38 -0700763 mkdir /data/misc/profman 0770 system shell
Ryan Campbell0b364732017-02-21 17:27:02 -0800764 mkdir /data/misc/gcov 0770 root root
Paul Crowley26aabfd2019-08-16 12:39:17 -0700765 mkdir /data/misc/installd 0700 root root
Oli Lan90c523b2020-01-17 11:41:04 +0000766 mkdir /data/misc/apexdata 0711 root root
Oli Lan4370ff52019-12-02 18:24:12 +0000767 mkdir /data/misc/apexrollback 0700 root root
Andrei Onea3c505882020-12-23 15:26:11 +0000768 mkdir /data/misc/appcompat/ 0700 system system
Yifan Hong7d286882020-02-08 16:38:56 -0800769 mkdir /data/misc/snapshotctl_log 0755 root root
Jerry Changaedac7e2020-01-02 10:57:30 +0800770 # create location to store pre-reboot information
771 mkdir /data/misc/prereboot 0700 system system
Orion Hodson44bedf62021-04-09 15:04:15 +0100772 # directory used for on-device refresh metrics file.
773 mkdir /data/misc/odrefresh 0777 system system
Martijn Coenen00e51a42020-11-27 12:21:34 +0100774 # directory used for on-device signing key blob
775 mkdir /data/misc/odsign 0700 root root
Andrew Walbran1f885ae2021-07-14 13:39:13 +0000776 # Directory for VirtualizationService temporary image files.
Andrew Walbran2934ee02021-05-19 17:09:44 +0000777 mkdir /data/misc/virtualizationservice 0700 virtualizationservice virtualizationservice
Stephen Smalleydeb41e52013-10-01 09:21:47 -0400778
Paul Crowley68258e82019-10-28 07:55:03 -0700779 mkdir /data/preloads 0775 system system encryption=None
Anton Hanssonc38a6362018-10-24 15:29:16 +0100780
Nick Kralevichf3ef1272012-03-14 15:22:54 -0700781 # For security reasons, /data/local/tmp should always be empty.
782 # Do not place files or directories in /data/local/tmp
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800783 mkdir /data/local/tmp 0771 shell shell
Max Bires181d11c2018-01-18 14:23:51 -0800784 mkdir /data/local/traces 0777 shell shell
Paul Crowley68258e82019-10-28 07:55:03 -0700785 mkdir /data/data 0771 system system encryption=None
786 mkdir /data/app-private 0771 system system encryption=Require
787 mkdir /data/app-ephemeral 0771 system system encryption=Require
788 mkdir /data/app-asec 0700 root root encryption=Require
789 mkdir /data/app-lib 0771 system system encryption=Require
790 mkdir /data/app 0771 system system encryption=Require
791 mkdir /data/property 0700 root root encryption=Require
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800792
Seigo Nonaka18e43722020-11-17 20:06:49 -0800793 # create directory for updated font files.
794 mkdir /data/fonts/ 0771 root root encryption=Require
795 mkdir /data/fonts/files 0771 system system
796 mkdir /data/fonts/config 0770 system system
797
Colin Cross7201ef82020-08-31 16:15:28 -0700798 # Create directories to push tests to for each linker namespace.
799 # Create the subdirectories in case the first test is run as root
800 # so it doesn't end up owned by root.
Christopher Ferris2163bbb2021-09-08 12:36:24 -0700801 # Set directories to be executable by any process so that debuggerd,
802 # aka crash_dump, can read any executables/shared libraries.
803 mkdir /data/local/tests 0701 shell shell
804 mkdir /data/local/tests/product 0701 shell shell
805 mkdir /data/local/tests/system 0701 shell shell
806 mkdir /data/local/tests/unrestricted 0701 shell shell
807 mkdir /data/local/tests/vendor 0701 shell shell
Colin Cross7201ef82020-08-31 16:15:28 -0700808
Chia-chi Yehea744142011-07-08 16:52:18 -0700809 # create dalvik-cache, so as to enforce our permissions
Paul Crowley68258e82019-10-28 07:55:03 -0700810 mkdir /data/dalvik-cache 0771 root root encryption=Require
Andreas Gampe7dfcc922015-12-08 09:33:07 -0800811 # create the A/B OTA directory, so as to enforce our permissions
Paul Crowley68258e82019-10-28 07:55:03 -0700812 mkdir /data/ota 0771 root root encryption=Require
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800813
Tao Bao380d6b12016-05-25 16:41:08 -0700814 # create the OTA package directory. It will be accessed by GmsCore (cache
815 # group), update_engine and update_verifier.
Paul Crowley68258e82019-10-28 07:55:03 -0700816 mkdir /data/ota_package 0770 system cache encryption=Require
Tao Bao380d6b12016-05-25 16:41:08 -0700817
Mårten Kongstadb45280d2011-05-30 10:24:54 +0200818 # create resource-cache and double-check the perms
Paul Crowley68258e82019-10-28 07:55:03 -0700819 mkdir /data/resource-cache 0771 system system encryption=Require
Mårten Kongstadb45280d2011-05-30 10:24:54 +0200820 chown system system /data/resource-cache
821 chmod 0771 /data/resource-cache
822
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800823 # create the lost+found directories, so as to enforce our permissions
Paul Crowley68258e82019-10-28 07:55:03 -0700824 mkdir /data/lost+found 0770 root root encryption=None
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800825
James Dong09cdc0e2012-01-06 15:19:26 -0800826 # create directory for DRM plug-ins - give drm the read/write access to
827 # the following directory.
Paul Crowley68258e82019-10-28 07:55:03 -0700828 mkdir /data/drm 0770 drm drm encryption=Require
aimitakeshie572d592010-07-27 08:38:35 +0900829
Jeff Tinker08d64302013-04-23 19:54:17 -0700830 # create directory for MediaDrm plug-ins - give drm the read/write access to
831 # the following directory.
Paul Crowley68258e82019-10-28 07:55:03 -0700832 mkdir /data/mediadrm 0770 mediadrm mediadrm encryption=Require
Jeff Tinker08d64302013-04-23 19:54:17 -0700833
Tom Cherryc3193102017-11-21 10:40:25 -0800834 # NFC: create data/nfc for nv storage
Paul Crowley68258e82019-10-28 07:55:03 -0700835 mkdir /data/nfc 0770 nfc nfc encryption=Require
Tom Cherryc3193102017-11-21 10:40:25 -0800836 mkdir /data/nfc/param 0770 nfc nfc
837
Paul Lawrencec410b3b2015-03-26 15:49:42 +0000838 # Create all remaining /data root dirs so that they are made through init
839 # and get proper encryption policy installed
Paul Crowley68258e82019-10-28 07:55:03 -0700840 mkdir /data/backup 0700 system system encryption=Require
841 mkdir /data/ss 0700 system system encryption=Require
Jeff Sharkey11705862015-11-09 17:07:35 -0800842
Paul Crowley68258e82019-10-28 07:55:03 -0700843 mkdir /data/system 0775 system system encryption=Require
Artur Satayev441e6b92021-03-30 11:49:05 +0100844 mkdir /data/system/environ 0700 system system
845 # b/183861600 attempt to fix selinux label before running derive_classpath service
846 restorecon /data/system/environ
Jeff Vander Stoep148dea72018-04-16 16:04:38 -0700847 mkdir /data/system/dropbox 0700 system system
Nick Kralevich9c0437f2015-04-07 16:44:08 -0700848 mkdir /data/system/heapdump 0700 system system
Jeff Sharkeyc9b84a32016-04-14 21:09:34 -0600849 mkdir /data/system/users 0775 system system
Jeff Sharkey3b9c83a2016-02-03 14:44:44 -0700850
Paul Crowley68258e82019-10-28 07:55:03 -0700851 mkdir /data/system_de 0770 system system encryption=None
852 mkdir /data/system_ce 0770 system system encryption=None
Jeff Sharkey3b9c83a2016-02-03 14:44:44 -0700853
Paul Crowley68258e82019-10-28 07:55:03 -0700854 mkdir /data/misc_de 01771 system misc encryption=None
855 mkdir /data/misc_ce 01771 system misc encryption=None
Jeff Sharkey11705862015-11-09 17:07:35 -0800856
Paul Crowley68258e82019-10-28 07:55:03 -0700857 mkdir /data/user 0711 system system encryption=None
858 mkdir /data/user_de 0711 system system encryption=None
Ricky Wai3cca2702019-12-12 12:55:03 +0000859
860 # Unlink /data/user/0 if we previously symlink it to /data/data
861 rm /data/user/0
862
863 # Bind mount /data/user/0 to /data/data
864 mkdir /data/user/0 0700 system system encryption=None
865 mount none /data/data /data/user/0 bind rec
Paul Lawrencec410b3b2015-03-26 15:49:42 +0000866
Ricky Wai3cca2702019-12-12 12:55:03 +0000867 # A tmpfs directory, which will contain all apps CE DE data directory that
868 # bind mount from the original source.
Ricky Wai1a5ae502020-03-04 13:30:09 +0000869 mount tmpfs tmpfs /data_mirror nodev noexec nosuid mode=0700,uid=0,gid=1000
Ricky Wai3cca2702019-12-12 12:55:03 +0000870 restorecon /data_mirror
871 mkdir /data_mirror/data_ce 0700 root root
872 mkdir /data_mirror/data_de 0700 root root
873
874 # Create CE and DE data directory for default volume
875 mkdir /data_mirror/data_ce/null 0700 root root
876 mkdir /data_mirror/data_de/null 0700 root root
877
878 # Bind mount CE and DE data directory to mirror's default volume directory
879 mount none /data/user /data_mirror/data_ce/null bind rec
880 mount none /data/user_de /data_mirror/data_de/null bind rec
881
Ricky Waifdc09862019-12-13 17:32:18 +0000882 # Create mirror directory for jit profiles
883 mkdir /data_mirror/cur_profiles 0700 root root
884 mount none /data/misc/profiles/cur /data_mirror/cur_profiles bind rec
Ricky Wai420830f2021-06-08 12:15:14 +0100885 mkdir /data_mirror/ref_profiles 0700 root root
886 mount none /data/misc/profiles/ref /data_mirror/ref_profiles bind rec
Ricky Waifdc09862019-12-13 17:32:18 +0000887
Paul Crowley68258e82019-10-28 07:55:03 -0700888 mkdir /data/cache 0770 system cache encryption=Require
Yueyao (Nathan) Zhu60c6dac2016-06-21 12:04:54 -0700889 mkdir /data/cache/recovery 0770 system cache
890 mkdir /data/cache/backup_stage 0700 system system
891 mkdir /data/cache/backup 0700 system system
892
Paul Crowley68258e82019-10-28 07:55:03 -0700893 # Delete these if need be, per b/139193659
894 mkdir /data/rollback 0700 system system encryption=DeleteIfNecessary
895 mkdir /data/rollback-observer 0700 system system encryption=DeleteIfNecessary
JW Wang5fc74a42020-11-13 15:45:49 +0800896 mkdir /data/rollback-history 0700 system system encryption=DeleteIfNecessary
Paul Crowley8184d7c2019-08-09 14:13:41 -0700897
Songchun Fan28496242019-12-17 12:41:34 -0800898 # Create root dir for Incremental Service
Songchun Fan73d9e7d2019-12-19 16:04:11 -0800899 mkdir /data/incremental 0771 system system encryption=Require
Songchun Fan28496242019-12-17 12:41:34 -0800900
Jeffrey Huang8dccf3f2020-02-19 10:56:17 -0800901 # Create directories for statsd
Jeffrey Huang8dccf3f2020-02-19 10:56:17 -0800902 mkdir /data/misc/stats-active-metric/ 0770 statsd system
Jeffrey Huang58c88612020-03-05 08:53:11 -0800903 mkdir /data/misc/stats-data/ 0770 statsd system
904 mkdir /data/misc/stats-metadata/ 0770 statsd system
905 mkdir /data/misc/stats-service/ 0770 statsd system
Jeffrey Huang8dccf3f2020-02-19 10:56:17 -0800906 mkdir /data/misc/train-info/ 0770 statsd system
907
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +0900908 # Wait for apexd to finish activating APEXes before starting more processes.
Oli Lan3cb185e2020-02-06 11:55:51 +0000909 wait_for_prop apexd.status activated
Oli Lan13e51e72019-11-19 18:08:45 +0000910 perform_apex_config
911
Daniel Rosenbergebfe3592019-12-20 13:17:19 -0800912 # Special-case /data/media/obb per b/64566063
913 mkdir /data/media 0770 media_rw media_rw encryption=None
914 exec - media_rw media_rw -- /system/bin/chattr +F /data/media
915 mkdir /data/media/obb 0770 media_rw media_rw encryption=Attempt
916
Anton Hansson3c5cc312019-12-05 15:38:37 +0000917 exec_start derive_sdk
Jiyong Parkdcbaf9f2019-02-22 22:15:25 +0900918
Paul Crowley59497452016-02-01 16:37:13 +0000919 init_user0
920
Martijn Coenenc7a26dc2021-01-18 11:14:22 +0100921 # Set SELinux security contexts on upgrade or policy update.
922 restorecon --recursive --skip-ce /data
923
Artur Satayev7df79972021-03-30 11:56:40 +0100924 # Define and export *CLASSPATH variables
925 # Must start before 'odsign', as odsign depends on *CLASSPATH variables
926 exec_start derive_classpath
927 load_exports /data/system/environ/classpath
Artur Satayev7df79972021-03-30 11:56:40 +0100928
Martijn Coenen00e51a42020-11-27 12:21:34 +0100929 # Start the on-device signing daemon, and wait for it to finish, to ensure
930 # ART artifacts are generated if needed.
satayev52cc8962021-03-19 11:08:49 +0000931 # Must start after 'derive_classpath' to have *CLASSPATH variables set.
Martijn Coenen648dec62021-03-17 08:44:55 +0100932 start odsign
933
934 # Before we can lock keys and proceed to the next boot stage, wait for
935 # odsign to be done with the key
936 wait_for_prop odsign.key.done 1
Martijn Coenen00e51a42020-11-27 12:21:34 +0100937
Martijn Coenenc7a26dc2021-01-18 11:14:22 +0100938 # Lock the fs-verity keyring, so no more keys can be added
939 exec -- /system/bin/fsverity_init --lock
940
Paul Crowley7583da12021-04-08 17:04:43 +0000941 # Bump the boot level to 1000000000; this prevents further on-device signing.
942 # This is a special value that shuts down the thread which listens for
943 # further updates.
944 setprop keystore.boot_level 1000000000
Martijn Coenene94b3662021-03-09 10:57:00 +0100945
Oli Lana466ca82020-01-23 19:52:42 +0000946 # Allow apexd to snapshot and restore device encrypted apex data in the case
947 # of a rollback. This should be done immediately after DE_user data keys
948 # are loaded. APEXes should not access this data until this has been
Oli Lan3cb185e2020-02-06 11:55:51 +0000949 # completed and apexd.status becomes "ready".
Oli Lana466ca82020-01-23 19:52:42 +0000950 exec_start apexd-snapshotde
951
Neil Fuller09bdb322019-06-06 15:18:36 +0100952 # Check any timezone data in /data is newer than the copy in the time zone data
953 # module, delete if not.
954 exec - system system -- /system/bin/tzdatacheck /apex/com.android.tzdata/etc/tz /data/misc/zoneinfo
Neil Fullerada7e492019-02-22 14:05:40 +0000955
Steven Morelandf38aab42017-01-25 10:52:15 -0800956 # If there is no post-fs-data action in the init.<device>.rc file, you
Ken Sumrall752923c2010-12-03 16:33:31 -0800957 # must uncomment this line, otherwise encrypted filesystems
958 # won't work.
959 # Set indication (checked by vold) that we have finished this action
960 #setprop vold.post_fs_data_done 1
961
Joel Fernandesae7f0522019-01-31 19:27:23 -0500962 # sys.memfd_use set to false by default, which keeps it disabled
963 # until it is confirmed that apps and vendor processes don't make
964 # IOCTLs on ashmem fds any more.
965 setprop sys.use_memfd false
966
Wei Wangec78cca2019-04-19 10:58:39 -0700967 # Set fscklog permission
968 chown root system /dev/fscklogs/log
969 chmod 0770 /dev/fscklogs/log
970
Zim8dacabe2020-02-10 20:24:40 +0000971 # Enable FUSE by default
972 setprop persist.sys.fuse true
973
Wei Wang53842e72017-04-20 14:37:55 -0700974# It is recommended to put unnecessary data/ initialization from post-fs-data
975# to start-zygote in device's init.rc to unblock zygote start.
976on zygote-start && property:ro.crypto.state=unencrypted
Martijn Coenen648dec62021-03-17 08:44:55 +0100977 wait_for_prop odsign.verification.done 1
Wei Wang53842e72017-04-20 14:37:55 -0700978 # A/B update verifier that marks a successful boot.
979 exec_start update_verifier_nonencrypted
Keun young Park6423ccd2020-06-23 20:32:54 -0700980 start statsd
Wei Wang53842e72017-04-20 14:37:55 -0700981 start netd
982 start zygote
983 start zygote_secondary
984
985on zygote-start && property:ro.crypto.state=unsupported
Martijn Coenen648dec62021-03-17 08:44:55 +0100986 wait_for_prop odsign.verification.done 1
Wei Wang53842e72017-04-20 14:37:55 -0700987 # A/B update verifier that marks a successful boot.
988 exec_start update_verifier_nonencrypted
Keun young Park6423ccd2020-06-23 20:32:54 -0700989 start statsd
Wei Wang53842e72017-04-20 14:37:55 -0700990 start netd
991 start zygote
992 start zygote_secondary
993
Wei Wangbae9ba32017-03-09 12:35:02 -0800994on zygote-start && property:ro.crypto.state=encrypted && property:ro.crypto.type=file
Martijn Coenen648dec62021-03-17 08:44:55 +0100995 wait_for_prop odsign.verification.done 1
Wei Wang53842e72017-04-20 14:37:55 -0700996 # A/B update verifier that marks a successful boot.
997 exec_start update_verifier_nonencrypted
Keun young Park6423ccd2020-06-23 20:32:54 -0700998 start statsd
Wei Wang53842e72017-04-20 14:37:55 -0700999 start netd
1000 start zygote
1001 start zygote_secondary
Wei Wangbae9ba32017-03-09 12:35:02 -08001002
Jaegeuk Kim58ff5072019-04-02 07:01:43 -07001003on boot && property:ro.config.low_ram=true
1004 # Tweak background writeout
1005 write /proc/sys/vm/dirty_expire_centisecs 200
1006 write /proc/sys/vm/dirty_background_ratio 5
1007
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001008on boot
Riley Andrews6dfdc7c2014-06-18 20:35:40 -07001009 # basic network init
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001010 ifup lo
1011 hostname localhost
1012 domainname localdomain
1013
Benedict Wong00308f82018-03-12 19:00:50 -07001014 # IPsec SA default expiration length
1015 write /proc/sys/net/core/xfrm_acq_expires 3600
1016
Riley Andrews6dfdc7c2014-06-18 20:35:40 -07001017 # Memory management. Basic kernel parameters, and allow the high
1018 # level system server to be able to adjust the kernel OOM driver
1019 # parameters to match how it is managing things.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001020 write /proc/sys/vm/overcommit_memory 1
The Android Open Source Projecte037fd72009-03-13 13:04:37 -07001021 write /proc/sys/vm/min_free_order_shift 4
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001022
Srinivas Paladugu3a632832019-01-09 11:28:59 -08001023 # System server manages zram writeback
1024 chown root system /sys/block/zram0/idle
1025 chmod 0664 /sys/block/zram0/idle
1026 chown root system /sys/block/zram0/writeback
1027 chmod 0664 /sys/block/zram0/writeback
1028
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -07001029 # to access F2FS sysfs on dm-<num> directly
1030 mkdir /dev/sys/fs/by-name 0755 system system
Guo Weichaobcefbb12021-05-26 11:12:11 +08001031 symlink /sys/fs/f2fs/${dev.mnt.dev.data} /dev/sys/fs/by-name/userdata
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -07001032
1033 # to access dm-<num> sysfs
1034 mkdir /dev/sys/block/by-name 0755 system system
Guo Weichaobcefbb12021-05-26 11:12:11 +08001035 symlink /sys/devices/virtual/block/${dev.mnt.dev.data} /dev/sys/block/by-name/userdata
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -07001036
Jaegeuk Kim58ff5072019-04-02 07:01:43 -07001037 # F2FS tuning. Set cp_interval larger than dirty_expire_centisecs, 30 secs,
Jaegeuk Kimf65df962019-03-29 09:16:51 -07001038 # to avoid power consumption when system becomes mostly idle. Be careful
1039 # to make it too large, since it may bring userdata loss, if they
1040 # are not aware of using fsync()/sync() to prepare sudden power-cut.
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -07001041 write /dev/sys/fs/by-name/userdata/cp_interval 200
1042 write /dev/sys/fs/by-name/userdata/gc_urgent_sleep_time 50
1043 write /dev/sys/fs/by-name/userdata/iostat_enable 1
Jaegeuk Kimf65df962019-03-29 09:16:51 -07001044
Jaegeuk Kimfe9e8a32019-11-27 15:42:10 -08001045 # limit discard size to 128MB in order to avoid long IO latency
1046 # for filesystem tuning first (dm or sda)
1047 # Note that, if dm-<num> is used, sda/mmcblk0 should be tuned in vendor/init.rc
Jaegeuk Kim43dca3c2020-07-20 17:34:47 -07001048 write /dev/sys/block/by-name/userdata/queue/discard_max_bytes 134217728
Jaegeuk Kimfe9e8a32019-11-27 15:42:10 -08001049
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001050 # Permissions for System Server and daemons.
Arve Hjønnevåg70a163f2012-05-02 17:57:50 -07001051 chown system system /sys/power/autosleep
Todd Poynor0653b972012-04-11 14:48:51 -07001052
1053 chown system system /sys/devices/system/cpu/cpufreq/interactive/timer_rate
1054 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_rate
Todd Poynor2b5b3bb2012-12-20 18:52:03 -08001055 chown system system /sys/devices/system/cpu/cpufreq/interactive/timer_slack
1056 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_slack
Todd Poynor0653b972012-04-11 14:48:51 -07001057 chown system system /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
1058 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
1059 chown system system /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
1060 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
Todd Poynor2b5b3bb2012-12-20 18:52:03 -08001061 chown system system /sys/devices/system/cpu/cpufreq/interactive/target_loads
1062 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/target_loads
Todd Poynor0653b972012-04-11 14:48:51 -07001063 chown system system /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
1064 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
Todd Poynorf35c2032012-04-19 13:17:24 -07001065 chown system system /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
1066 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
Todd Poynor8d3ea1d2012-04-24 15:37:13 -07001067 chown system system /sys/devices/system/cpu/cpufreq/interactive/boost
1068 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boost
Todd Poynor4ff10e62012-05-03 15:20:48 -07001069 chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse
Todd Poynor33045a62012-04-27 20:21:18 -07001070 chown system system /sys/devices/system/cpu/cpufreq/interactive/input_boost
1071 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/input_boost
Todd Poynor4f247d72012-12-19 17:43:06 -08001072 chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration
1073 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration
Todd Poynor6b5de1c2013-03-25 13:17:13 -07001074 chown system system /sys/devices/system/cpu/cpufreq/interactive/io_is_busy
1075 chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/io_is_busy
Todd Poynor0653b972012-04-11 14:48:51 -07001076
1077 # Assume SMP uses shared cpufreq policy for all CPUs
1078 chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
1079 chmod 0660 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
1080
David Lin27b2c1e2017-03-08 17:36:18 -08001081 chown system system /sys/class/leds/vibrator/trigger
1082 chown system system /sys/class/leds/vibrator/activate
1083 chown system system /sys/class/leds/vibrator/brightness
1084 chown system system /sys/class/leds/vibrator/duration
1085 chown system system /sys/class/leds/vibrator/state
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001086 chown system system /sys/class/timed_output/vibrator/enable
1087 chown system system /sys/class/leds/keyboard-backlight/brightness
1088 chown system system /sys/class/leds/lcd-backlight/brightness
1089 chown system system /sys/class/leds/button-backlight/brightness
The Android Open Source Projectf614d642009-03-18 17:39:49 -07001090 chown system system /sys/class/leds/jogball-backlight/brightness
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001091 chown system system /sys/class/leds/red/brightness
1092 chown system system /sys/class/leds/green/brightness
1093 chown system system /sys/class/leds/blue/brightness
1094 chown system system /sys/class/leds/red/device/grpfreq
1095 chown system system /sys/class/leds/red/device/grppwm
1096 chown system system /sys/class/leds/red/device/blink
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001097 chown system system /sys/module/sco/parameters/disable_esco
1098 chown system system /sys/kernel/ipv4/tcp_wmem_min
1099 chown system system /sys/kernel/ipv4/tcp_wmem_def
1100 chown system system /sys/kernel/ipv4/tcp_wmem_max
1101 chown system system /sys/kernel/ipv4/tcp_rmem_min
1102 chown system system /sys/kernel/ipv4/tcp_rmem_def
1103 chown system system /sys/kernel/ipv4/tcp_rmem_max
1104 chown root radio /proc/cmdline
1105
Riley Andrews6dfdc7c2014-06-18 20:35:40 -07001106 # Define default initial receive window size in segments.
paulhuf8cdebf2021-03-17 13:59:02 +08001107 setprop net.tcp_def_init_rwnd 60
JP Abgrall7c862c82014-02-21 12:05:01 -08001108
Bowgo Tsai5998c742021-10-21 21:24:16 +08001109 # Update dm-verity state and set partition.*.verified properties.
1110 verity_update_state
1111
Steven Morelandd6275022017-03-24 16:23:07 +00001112 # Start standard binderized HAL daemons
1113 class_start hal
1114
Ken Sumrall752923c2010-12-03 16:33:31 -08001115 class_start core
Ken Sumrall752923c2010-12-03 16:33:31 -08001116
1117on nonencrypted
Paul Lawrence13d5bb42014-01-30 10:43:52 -08001118 class_start main
Ken Sumrall752923c2010-12-03 16:33:31 -08001119 class_start late_start
1120
Riley Andrews1bbef882014-06-26 13:55:03 -07001121on property:sys.init_log_level=*
1122 loglevel ${sys.init_log_level}
1123
Dima Zavinca47cef2011-08-24 15:28:23 -07001124on charger
1125 class_start charger
1126
Elliott Hughesa3641af2016-11-10 17:43:47 -08001127on property:sys.boot_completed=1
1128 bootchart stop
Paul Crowley570d20d2019-09-11 15:02:44 -07001129 # Setup per_boot directory so other .rc could start to use it on boot_completed
1130 exec - system system -- /bin/rm -rf /data/per_boot
Paul Crowley68258e82019-10-28 07:55:03 -07001131 mkdir /data/per_boot 0700 system system encryption=Require key=per_boot_ref
Elliott Hughesa3641af2016-11-10 17:43:47 -08001132
JP Abgrall7c862c82014-02-21 12:05:01 -08001133# system server cannot write to /proc/sys files,
1134# and chown/chmod does not work for /proc/sys/ entries.
1135# So proxy writes through init.
Colin Cross57fdb5c2013-07-25 10:34:30 -07001136on property:sys.sysctl.extra_free_kbytes=*
Suren Baghdasaryan92cb2e82021-07-21 15:16:20 -07001137 exec -- /system/bin/extra_free_kbytes.sh ${sys.sysctl.extra_free_kbytes}
Riley Andrews6dfdc7c2014-06-18 20:35:40 -07001138
Michael Rosenfelde853d372021-02-10 18:38:05 -08001139# Allow users to drop caches
1140on property:perf.drop_caches=3
1141 write /proc/sys/vm/drop_caches 3
1142 setprop perf.drop_caches 0
1143
JP Abgrall7c862c82014-02-21 12:05:01 -08001144# "tcp_default_init_rwnd" Is too long!
Chiachang Wang7396fed2020-10-15 21:09:25 +08001145on property:net.tcp_def_init_rwnd=*
1146 write /proc/sys/net/ipv4/tcp_default_init_rwnd ${net.tcp_def_init_rwnd}
JP Abgrall7c862c82014-02-21 12:05:01 -08001147
Ryan Savitskif0f7e702020-01-14 22:02:53 +00001148# perf_event_open syscall security:
1149# Newer kernels have the ability to control the use of the syscall via SELinux
1150# hooks. init tests for this, and sets sys_init.perf_lsm_hooks to 1 if the
1151# kernel has the hooks. In this case, the system-wide perf_event_paranoid
1152# sysctl is set to -1 (unrestricted use), and the SELinux policy is used for
1153# controlling access. On older kernels, the paranoid value is the only means of
1154# controlling access. It is normally 3 (allow only root), but the shell user
1155# can lower it to 1 (allowing thread-scoped pofiling) via security.perf_harden.
1156on property:sys.init.perf_lsm_hooks=1
1157 write /proc/sys/kernel/perf_event_paranoid -1
1158on property:security.perf_harden=0 && property:sys.init.perf_lsm_hooks=""
Daniel Micay2b22a662015-09-04 16:23:01 -04001159 write /proc/sys/kernel/perf_event_paranoid 1
Ryan Savitskif0f7e702020-01-14 22:02:53 +00001160on property:security.perf_harden=1 && property:sys.init.perf_lsm_hooks=""
1161 write /proc/sys/kernel/perf_event_paranoid 3
1162
1163# Additionally, simpleperf profiler uses debug.* and security.perf_harden
1164# sysprops to be able to indirectly set these sysctls.
1165on property:security.perf_harden=0
Yabin Cui4f0da7c2018-06-29 14:52:47 -07001166 write /proc/sys/kernel/perf_event_max_sample_rate ${debug.perf_event_max_sample_rate:-100000}
1167 write /proc/sys/kernel/perf_cpu_time_max_percent ${debug.perf_cpu_time_max_percent:-25}
1168 write /proc/sys/kernel/perf_event_mlock_kb ${debug.perf_event_mlock_kb:-516}
Ryan Savitskif0f7e702020-01-14 22:02:53 +00001169# Default values.
Daniel Micay2b22a662015-09-04 16:23:01 -04001170on property:security.perf_harden=1
Ryan Savitskif0f7e702020-01-14 22:02:53 +00001171 write /proc/sys/kernel/perf_event_max_sample_rate 100000
1172 write /proc/sys/kernel/perf_cpu_time_max_percent 25
1173 write /proc/sys/kernel/perf_event_mlock_kb 516
1174
Primiano Tucci253289f2020-10-09 13:59:41 +01001175# This property can be set only on userdebug/eng. See neverallow rule in
1176# /system/sepolicy/private/property.te .
1177on property:security.lower_kptr_restrict=1
1178 write /proc/sys/kernel/kptr_restrict 0
1179
1180on property:security.lower_kptr_restrict=0
1181 write /proc/sys/kernel/kptr_restrict 2
1182
Colin Cross57fdb5c2013-07-25 10:34:30 -07001183
Wei Wangeeab4912017-06-27 22:08:45 -07001184# on shutdown
1185# In device's init.rc, this trigger can be used to do device-specific actions
1186# before shutdown. e.g disable watchdog and mask error handling
1187
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001188## Daemon processes to be run by init.
1189##
Tom Cherry31438482018-07-20 14:57:00 -07001190service ueventd /system/bin/ueventd
Ken Sumrall752923c2010-12-03 16:33:31 -08001191 class core
Colin Crossf83d0b92010-04-21 12:04:20 -07001192 critical
Stephen Smalley1eee4192012-01-13 08:54:34 -05001193 seclabel u:r:ueventd:s0
Keun-young Parkcccb34f2017-07-05 11:38:44 -07001194 shutdown critical
Colin Crossf83d0b92010-04-21 12:04:20 -07001195
Brian Swetlandb4d65392010-10-27 15:40:23 -07001196service console /system/bin/sh
Ken Sumrall752923c2010-12-03 16:33:31 -08001197 class core
Brian Swetlandb4d65392010-10-27 15:40:23 -07001198 console
1199 disabled
1200 user shell
Nick Kralevichc39ba5a2015-11-07 16:52:17 -08001201 group shell log readproc
Stephen Smalley610653f2013-12-23 14:11:02 -05001202 seclabel u:r:shell:s0
Dmitry Shmidtd0fb2512017-10-11 11:18:51 -07001203 setenv HOSTNAME console
Brian Swetlandb4d65392010-10-27 15:40:23 -07001204
Mike Lockwoodd49b4ef2010-11-19 09:12:27 -05001205on property:ro.debuggable=1
Calin Juravle9b3e5d52015-11-10 19:16:43 +00001206 # Give writes to anyone for the trace folder on debug builds.
1207 # The folder is used to store method traces.
1208 chmod 0773 /data/misc/trace
Vishnu Naird09ab7a2017-11-27 09:54:31 -08001209 # Give reads to anyone for the window trace folder on debug builds.
1210 chmod 0775 /data/misc/wmtrace
Hongming Jin87f55fe2021-02-09 11:54:46 -08001211 # Give reads to anyone for the accessibility trace folder on debug builds.
1212 chmod 0775 /data/misc/a11ytrace
Tom Cherry71c3ef12019-08-27 14:57:32 -07001213
1214on init && property:ro.debuggable=1
Brian Swetlandb4d65392010-10-27 15:40:23 -07001215 start console
Nikita Ioffeba6968e2019-10-07 16:26:33 +01001216
Nikita Ioffeac692142019-11-01 20:56:33 +00001217on userspace-reboot-requested
Nikita Ioffeba6968e2019-10-07 16:26:33 +01001218 # TODO(b/135984674): reset all necessary properties here.
Nikita Ioffe018ddd72019-12-20 16:34:48 +00001219 setprop sys.boot_completed ""
Nikita Ioffec2bc1a32020-02-07 17:42:27 +00001220 setprop dev.bootcomplete ""
Nikita Ioffe018ddd72019-12-20 16:34:48 +00001221 setprop sys.init.updatable_crashing ""
1222 setprop sys.init.updatable_crashing_process_name ""
Nikita Ioffe018ddd72019-12-20 16:34:48 +00001223 setprop sys.user.0.ce_available ""
Nikita Ioffe1131a212019-12-30 16:05:11 +00001224 setprop sys.shutdown.requested ""
Nikita Ioffe764c1ac2020-01-27 17:14:46 +00001225 setprop service.bootanim.exit ""
Nicolas Geoffraye106f0a2020-12-15 18:34:47 +00001226 setprop service.bootanim.progress ""
Nikita Ioffeba6968e2019-10-07 16:26:33 +01001227
Nikita Ioffe12a36072019-10-23 20:11:32 +01001228on userspace-reboot-fs-remount
1229 # Make sure that vold is running.
1230 # This is mostly a precaution measure in case vold for some reason wasn't running when
1231 # userspace reboot was initiated.
1232 start vold
1233 exec - system system -- /system/bin/vdc checkpoint resetCheckpoint
1234 exec - system system -- /system/bin/vdc checkpoint markBootAttempt
Nikita Ioffebf66f432020-04-07 00:26:15 +01001235 # Unmount /data_mirror mounts in the reverse order of corresponding mounts.
1236 umount /data_mirror/data_ce/null/0
1237 umount /data_mirror/data_ce/null
1238 umount /data_mirror/data_de/null
1239 umount /data_mirror/cur_profiles
Ricky Wai420830f2021-06-08 12:15:14 +01001240 umount /data_mirror/ref_profiles
Nikita Ioffebf66f432020-04-07 00:26:15 +01001241 umount /data_mirror
Nikita Ioffe12a36072019-10-23 20:11:32 +01001242 remount_userdata
Nikita Ioffe764c1ac2020-01-27 17:14:46 +00001243 start bootanim
Nikita Ioffe12a36072019-10-23 20:11:32 +01001244
Nikita Ioffe3f4b0d62019-10-09 15:23:02 +01001245on userspace-reboot-resume
Nikita Ioffe12a36072019-10-23 20:11:32 +01001246 trigger userspace-reboot-fs-remount
Nikita Ioffeba6968e2019-10-07 16:26:33 +01001247 trigger post-fs-data
1248 trigger zygote-start
1249 trigger early-boot
1250 trigger boot
Nikita Ioffec0df1872019-11-13 21:47:06 +00001251
1252on property:sys.boot_completed=1 && property:sys.init.userspace_reboot.in_progress=1
Nikita Ioffe85ff4ab2020-02-06 23:33:42 +00001253 setprop sys.init.userspace_reboot.in_progress ""