android init.rc

编程入门 行业动态 更新时间:2024-10-10 07:21:48

<a href=https://www.elefans.com/category/jswz/34/1771384.html style=android init.rc"/>

android init.rc

init是Android中linux的第一个用户级进程,主要是解析init.rc脚本。
init.rc脚本包括了文件系统初始化、装载的许多过程。init.rc的工作主要是:
1)设置一些环境变量
2)创建system、sdcard、data、cache等目录(见案例1)
3)把一些文件系统mount到一些目录去,如,mount tmpfs tmpfs /sqlite_stmt_journals
4)设置一些文件的用户群组、权限
5)设置一些线程参数
6)设置TCP缓存大小
init脚本的关键字(如mkdir,chmod,service等等)可以参考init进程的
system/core/init/keyword.h文件。
init.rc的使用方法,可以参考说明文件system/core/init/readme.txt
如果想要修改启动过程只需要修改init.c(system/core/init)或者init.rc里的内容即可.


     在 Android中使用启动脚本init.rc可以在系统的初始化过程中进行一些简单的初始化操作。
这个脚本被直接安装到目标系统的根文件系统中,被 init可执行程序解析。 init.rc是在init启动后被执行的启动脚本。
      我们可以通过修改init.rc脚本来修改启动过程。但是,一般情况下,我们不直接修改init.rc,而是在文件init.%PRODUCT%.rc(如init.qcom.rc)文件中添加或修改我们需要的额外的初始化配置。因为init.c中的main函数在解析完init.rc以后会继续解析init.%PRODUCT%.rc文件。要特别强调的是,init.rc文件和init.%PRODUCT%.rc文件都是用Android Init Language语言来编写的。


init.rc mi3

# Copyright (C) 2012 The Android Open Source Project## IMPORTANT: Do not create world writable files or directories.# This is a common source of Android security bugs.#import /init.environ.rcimport /init.usb.rcimport /init.${ro.hardware}.rcimport /init.trace.rcon early-init# Set init and its forked children's oom_adj.write /proc/1/oom_adj -16# Set the security context for the init process.# This should occur before anything else (e.g. ueventd) is started.setcon u:r:init:s0start ueventd# create mountpointsmkdir /mnt 0775 root systemon initsysclktz 0loglevel 3# Backward compatibilitysymlink /system/etc /etcsymlink /sys/kernel/debug /d# Right now vendor lives on the same filesystem as system,# but someday that may change.symlink /system/vendor /vendor# Create cgroup mount point for cpu accountingmkdir /acctmount cgroup none /acct cpuacctmkdir /acct/uid# Create cgroup mount point for memorymount tmpfs none /sys/fs/cgroup mode=0750,uid=0,gid=1000mkdir /sys/fs/cgroup/memory 0750 root systemmount cgroup none /sys/fs/cgroup/memory memorywrite /sys/fs/cgroup/memory/memory.move_charge_at_immigrate 1chown root system /sys/fs/cgroup/memory/taskschmod 0660 /sys/fs/cgroup/memory/tasksmkdir /sys/fs/cgroup/memory/sw 0750 root systemwrite /sys/fs/cgroup/memory/sw/memory.swappiness 100write /sys/fs/cgroup/memory/sw/memory.move_charge_at_immigrate 1chown root system /sys/fs/cgroup/memory/sw/taskschmod 0660 /sys/fs/cgroup/memory/sw/tasksmkdir /systemmkdir /data 0771 system systemmkdir /cache 0770 system cachemkdir /config 0500 root root# See storage config details at  /mnt/shell 0700 shell shellmkdir /mnt/media_rw 0700 media_rw media_rwmkdir /storage 0751 root sdcard_r# Directory for putting things only root should see.mkdir /mnt/secure 0700 root root# Directory for staging bindmountsmkdir /mnt/secure/staging 0700 root root# Directory-target for where the secure container# imagefile directory will be bind-mountedmkdir /mnt/secure/asec  0700 root root# Secure container public mount points.mkdir /mnt/asec  0700 root systemmount tmpfs tmpfs /mnt/asec mode=0755,gid=1000# Filesystem image public mount points.mkdir /mnt/obb 0700 root systemmount tmpfs tmpfs /mnt/obb mode=0755,gid=1000write /proc/sys/kernel/panic_on_oops 1write /proc/sys/kernel/hung_task_timeout_secs 0write /proc/cpu/alignment 4write /proc/sys/kernel/sched_latency_ns 10000000write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000write /proc/sys/kernel/sched_compat_yield 1write /proc/sys/kernel/sched_child_runs_first 0write /proc/sys/kernel/randomize_va_space 2write /proc/sys/kernel/kptr_restrict 2write /proc/sys/kernel/dmesg_restrict 1write /proc/sys/vm/mmap_min_addr 32768write /proc/sys/net/ipv4/ping_group_range "0 2147483647"write /proc/sys/kernel/sched_rt_runtime_us 950000write /proc/sys/kernel/sched_rt_period_us 1000000write /proc/sys/vm/legacy_va_layout 1# Create cgroup mount points for process groupsmkdir /dev/cpuctlmount cgroup none /dev/cpuctl cpuchown system system /dev/cpuctlchown system system /dev/cpuctl/taskschmod 0660 /dev/cpuctl/taskswrite /dev/cpuctl/cpu.shares 1024write /dev/cpuctl/cpu.rt_runtime_us 950000write /dev/cpuctl/cpu.rt_period_us 1000000mkdir /dev/cpuctl/appschown system system /dev/cpuctl/apps/taskschmod 0666 /dev/cpuctl/apps/taskswrite /dev/cpuctl/apps/cpu.shares 1024write /dev/cpuctl/apps/cpu.rt_runtime_us 800000write /dev/cpuctl/apps/cpu.rt_period_us 1000000mkdir /dev/cpuctl/apps/bg_non_interactivechown system system /dev/cpuctl/apps/bg_non_interactive/taskschmod 0666 /dev/cpuctl/apps/bg_non_interactive/tasks# 5.0 %write /dev/cpuctl/apps/bg_non_interactive/cpu.shares 52write /dev/cpuctl/apps/bg_non_interactive/cpu.rt_runtime_us 700000write /dev/cpuctl/apps/bg_non_interactive/cpu.rt_period_us 1000000# qtaguid will limit access to specific data based on group memberships.#   net_bw_acct grants impersonation of socket owners.#   net_bw_stats grants access to other apps' detailed tagged-socket stats.chown root net_bw_acct /proc/net/xt_qtaguid/ctrlchown root net_bw_stats /proc/net/xt_qtaguid/stats# Allow everybody to read the xt_qtaguid resource tracking misc dev.# This is needed by any process that uses socket tagging.chmod 0644 /dev/xt_qtaguid# Create location for fs_mgr to store abbreviated output from filesystem# checker programs.mkdir /dev/fscklogs 0770 root system# Allow updater to execv ota with suid in rootfschown root updater /bin/otachmod 06754 /bin/otaon post-fs# once everything is setup, no need to modify /mount rootfs rootfs / ro remount# mount shared so changes propagate into child namespacesmount rootfs rootfs / shared rec# We chown/chmod /cache again so because mount is run as root + defaultschown system cache /cachechmod 0770 /cache# We restorecon /cache in case the cache partition has been reset.restorecon /cache# This may have been created by the recovery system with odd permissionschown system cache /cache/recoverychmod 0770 /cache/recovery# This may have been created by the recovery system with the wrong context.restorecon /cache/recovery#change permissions on vmallocinfo so we can grab it from bugreportschown root log /proc/vmallocinfochmod 0440 /proc/vmallocinfochown root log /proc/slabinfochmod 0440 /proc/slabinfo#change permissions on kmsg & sysrq-trigger so bugreports can grab kthread stackschown root system /proc/kmsgchmod 0440 /proc/kmsgchown root system /proc/sysrq-triggerchmod 0220 /proc/sysrq-triggerchown system log /proc/last_kmsgchmod 0440 /proc/last_kmsg# create the lost+found directories, so as to enforce our permissionsmkdir /cache/lost+found 0770 root rooton post-fs-data# We chown/chmod /data again so because mount is run as root + defaultschown system system /datachmod 0771 /data# We restorecon /data in case the userdata partition has been reset.restorecon /data# Avoid predictable entropy pool. Carry over entropy from previous boot.copy /data/system/entropy.dat /dev/urandom# Create dump dir and collect dumps.# Do this before we mount cache so eventually we can use cache for# storing dumps on platforms which do not have a dedicated dump partition.mkdir /data/dontpanic 0750 root log# Collect apanic data, free resources and re-arm triggercopy /proc/apanic_console /data/dontpanic/apanic_consolechown root log /data/dontpanic/apanic_consolechmod 0640 /data/dontpanic/apanic_consolecopy /proc/apanic_threads /data/dontpanic/apanic_threadschown root log /data/dontpanic/apanic_threadschmod 0640 /data/dontpanic/apanic_threadswrite /proc/apanic_console 1# create basic filesystem structuremkdir /data/misc 01771 system miscmkdir /data/misc/adb 02750 system shellmkdir /data/misc/bluedroid 0770 bluetooth net_bt_stackmkdir /data/misc/bluetooth 0770 system systemmkdir /data/misc/keystore 0700 keystore keystoremkdir /data/misc/keychain 0771 system systemmkdir /data/misc/radio 0770 system radiomkdir /data/misc/sms 0770 system radiomkdir /data/misc/zoneinfo 0775 system systemmkdir /data/misc/vpn 0770 system vpnmkdir /data/misc/systemkeys 0700 system system# give system access to wpa_supplicant.conf for backup and restoremkdir /data/misc/wifi 0770 wifi wifichmod 0660 /data/misc/wifi/wpa_supplicant.confmkdir /data/local 0751 root rootmkdir /data/misc/media 0700 media media# For security reasons, /data/local/tmp should always be empty.# Do not place files or directories in /data/local/tmpmkdir /data/local/tmp 0771 shell shellmkdir /data/data 0771 system systemmkdir /data/data/mediaserver 0700 media mediamkdir /data/app-private 0771 system systemmkdir /data/app-asec 0700 root rootmkdir /data/app-lib 0771 system systemmkdir /data/app 0771 system systemmkdir /data/property 0700 root rootmkdir /data/ssh 0750 root shellmkdir /data/ssh/empty 0700 root root# create dalvik-cache, so as to enforce our permissionsmkdir /data/dalvik-cache 0771 system system# create resource-cache and double-check the permsmkdir /data/resource-cache 0771 system systemchown system system /data/resource-cachechmod 0771 /data/resource-cache# create the lost+found directories, so as to enforce our permissionsmkdir /data/lost+found 0770 root root# create directory for DRM plug-ins - give drm the read/write access to# the following directory.mkdir /data/drm 0770 drm drm# create directory for MediaDrm plug-ins - give drm the read/write access to# the following directory.mkdir /data/mediadrm 0770 mediadrm mediadrm# symlink to bugreport storage locationsymlink /data/data/com.android.shell/files/bugreports /data/bugreports# Separate location for storing security policy files on datamkdir /data/security 0711 system system# If there is no fs-post-data action in the init.<device>.rc file, you# must uncomment this line, otherwise encrypted filesystems# won't work.# Set indication (checked by vold) that we have finished this action#setprop vold.post_fs_data_done 1on boot# basic network initifup lohostname localhostdomainname localdomain# set RLIMIT_NICE to allow priorities from 19 to -20setrlimit 13 40 40# Memory management.  Basic kernel parameters, and allow the high# level system server to be able to adjust the kernel OOM driver# parameters to match how it is managing things.write /proc/sys/vm/overcommit_memory 1write /proc/sys/vm/min_free_order_shift 4chown root system /sys/module/lowmemorykiller/parameters/adjchmod 0664 /sys/module/lowmemorykiller/parameters/adjchown root system /sys/module/lowmemorykiller/parameters/minfreechmod 0664 /sys/module/lowmemorykiller/parameters/minfree# atomic allocations can get upto 5/8th of this sizewrite /proc/sys/vm/min_free_kbytes 16384# Tweak background writeoutwrite /proc/sys/vm/dirty_expire_centisecs 200write /proc/sys/vm/dirty_background_ratio  5# Permissions for System Server and daemons.chown radio system /sys/android_power/statechown radio system /sys/android_power/request_statechown radio system /sys/android_power/acquire_full_wake_lockchown radio system /sys/android_power/acquire_partial_wake_lockchown radio system /sys/android_power/release_wake_lockchown system system /sys/power/autosleepchown system system /sys/power/statechown system system /sys/power/wakeup_countchown radio system /sys/power/wake_lockchown radio system /sys/power/wake_unlockchmod 0660 /sys/power/statechmod 0660 /sys/power/wake_lockchmod 0660 /sys/power/wake_unlockchown system system /sys/class/leds/flashlight/brightnesschmod 0664 /sys/class/leds/flashlight/brightnesschown system system /sys/devices/system/cpu/cpufreq/interactive/timer_ratechmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_ratechown system system /sys/devices/system/cpu/cpufreq/interactive/timer_slackchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_slackchown system system /sys/devices/system/cpu/cpufreq/interactive/min_sample_timechmod 0660 /sys/devices/system/cpu/cpufreq/interactive/min_sample_timechown system system /sys/devices/system/cpu/cpufreq/interactive/hispeed_freqchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/hispeed_freqchown system system /sys/devices/system/cpu/cpufreq/interactive/target_loadschmod 0660 /sys/devices/system/cpu/cpufreq/interactive/target_loadschown system system /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_loadchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_loadchown system system /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delaychmod 0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delaychown system system /sys/devices/system/cpu/cpufreq/interactive/boostchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostchown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulsechown system system /sys/devices/system/cpu/cpufreq/interactive/input_boostchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/input_boostchown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse_durationchmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse_durationchown system system /sys/devices/system/cpu/cpufreq/interactive/io_is_busychmod 0660 /sys/devices/system/cpu/cpufreq/interactive/io_is_busy# Assume SMP uses shared cpufreq policy for all CPUschown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freqchmod 0660 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freqchown system system /sys/class/timed_output/vibrator/enablechown system system /sys/class/leds/keyboard-backlight/brightnesschown system system /sys/class/leds/lcd-backlight/brightnesschown system system /sys/class/leds/button-backlight/brightnesschown system system /sys/class/leds/jogball-backlight/brightnesschown system system /sys/class/leds/red/brightnesschown system system /sys/class/leds/green/brightnesschown system system /sys/class/leds/blue/brightnesschown system system /sys/class/leds/red/device/grpfreqchown system system /sys/class/leds/red/device/grppwmchown system system /sys/class/leds/red/device/blinkchown system system /sys/class/timed_output/vibrator/enablechown system system /sys/class/timed_output/vibrator/patternchown system system /sys/module/sco/parameters/disable_escochown system system /sys/kernel/ipv4/tcp_wmem_minchown system system /sys/kernel/ipv4/tcp_wmem_defchown system system /sys/kernel/ipv4/tcp_wmem_maxchown system system /sys/kernel/ipv4/tcp_rmem_minchown system system /sys/kernel/ipv4/tcp_rmem_defchown system system /sys/kernel/ipv4/tcp_rmem_maxchown root radio /proc/cmdlinechmod 0444 /proc/cmdline# Set these so we can remotely update SELinux policychown system system /sys/fs/selinux/loadchown system system /sys/fs/selinux/enforce#----AKM8963 sysfs entry----chown system system /sys/class/compass/akm8963/enable_magchown system system /sys/class/compass/akm8963/delay_mag# Define TCP buffer sizes for various networks#   ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208setprop net.tcp.buffersize.wifi    524288,1048576,2097152,262144,524288,1048576setprop net.tcp.buffersize.lte     524288,1048576,2097152,262144,524288,1048576setprop net.tcp.buffersize.umts    4094,87380,110208,4096,16384,110208setprop net.tcp.buffersize.hspa    4094,87380,262144,4096,16384,262144setprop net.tcp.buffersize.hsupa   4094,87380,262144,4096,16384,262144setprop net.tcp.buffersize.hsdpa   4094,87380,262144,4096,16384,262144setprop net.tcp.buffersize.hspap   4094,87380,1220608,4096,16384,1220608setprop net.tcp.buffersize.edge    4093,26280,35040,4096,16384,35040setprop net.tcp.buffersize.gprs    4092,8760,11680,4096,8760,11680setprop net.tcp.buffersize.evdo    4094,87380,262144,4096,16384,262144class_start coreclass_start mainclass_start late_starton chargermount ext4 /dev/block/platform/sdhci-tegra.3/by-name/system /system wait ro barrier=1setprop sys.usb.config adbwrite /sys/kernel/cluster/immediate 1write /sys/kernel/cluster/force 1write /sys/kernel/cluster/active lpwrite /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor userspacewrite /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 51000write /sys/class/input/input1/enabled 0class_start chargeron property:vold.decrypt=trigger_reset_mainclass_reset mainon property:vold.decrypt=trigger_load_persist_propsload_persist_propson property:vold.decrypt=trigger_post_fs_datatrigger post-fs-dataon property:vold.decrypt=trigger_restart_min_frameworkclass_start mainon property:vold.decrypt=trigger_restart_frameworkclass_start mainclass_start late_starton property:vold.decrypt=trigger_shutdown_frameworkclass_reset late_startclass_reset mainon property:sys.powerctl=*powerctl ${sys.powerctl}# system server cannot write to /proc/sys files, so proxy it through initon property:sys.sysctl.extra_free_kbytes=*write /proc/sys/vm/extra_free_kbytes ${sys.sysctl.extra_free_kbytes}## Daemon processes to be run by init.##service ueventd /sbin/ueventdclass corecriticalseclabel u:r:ueventd:s0service healthd /sbin/healthdclass corecriticalseclabel u:r:healthd:s0service healthd-charger /sbin/healthd -nclass chargercriticalseclabel u:r:healthd:s0on property:selinux.reload_policy=1restart ueventdrestart installdservice console /system/bin/shclass coreconsoledisableduser shellgroup logon property:ro.debuggable=1start console# adbd is controlled via property triggers in init.<platform>.usb.rcservice adbd /sbin/adbdclass coresocket adbd stream 660 system systemdisabledseclabel u:r:adbd:s0# mdbd is controlled via property triggers in init.<platform>.usb.rcservice mdbd /sbin/mdbdclass coresocket mdbd stream 660 system systemdisabledseclabel u:r:mdbd:s0# adbd on at boot in emulatoron property:ro.kernel.qemu=1start adbdservice servicemanager /system/bin/servicemanagerclass coreuser systemgroup systemcriticalonrestart restart healthdonrestart restart zygoteonrestart restart mediaonrestart restart surfaceflingeronrestart restart drmservice vold /system/bin/voldclass coresocket vold stream 0660 root mountioprio be 2service akmd /system/bin/akmd8963class coreuser systemgroup system misc inputservice netd /system/bin/netdclass mainsocket netd stream 0660 root systemsocket dnsproxyd stream 0660 root inetsocket mdns stream 0660 root systemservice debuggerd /system/bin/debuggerdclass mainservice ril-daemon /system/bin/rildclass mainsocket rild stream 660 root radiosocket rild-debug stream 660 radio systemuser rootgroup radio cache inet misc audio logdisabledservice surfaceflinger /system/bin/surfaceflingerclass mainuser systemgroup graphics drmrpconrestart restart zygoteservice zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-serverclass mainsocket zygote stream 660 root systemonrestart write /sys/android_power/request_state wakeonrestart write /sys/power/state ononrestart restart mediaonrestart restart netdservice drm /system/bin/drmserverclass mainuser drmgroup drm system inet drmrpcservice media /system/bin/mediaserverclass mainuser mediagroup audio camera inet net_bt net_bt_admin net_bw_acct drmrpc mediadrm radioioprio rt 4service bootanim /system/bin/bootanimationclass mainuser graphicsgroup graphicsdisabledoneshotservice installd /system/bin/installdclass mainsocket installd stream 600 system systemservice flash_recovery /system/etc/install-recovery.shclass mainoneshotservice racoon /system/bin/racoonclass mainsocket racoon stream 600 system system# IKE uses UDP port 500. Racoon will setuid to vpn after binding the port.group vpn net_admin inetdisabledoneshotservice mtpd /system/bin/mtpdclass mainsocket mtpd stream 600 system systemuser vpngroup vpn net_admin inet net_rawdisabledoneshotservice keystore /system/bin/keystore /data/misc/keystoreclass mainuser keystoregroup keystore drmrpcservice dumpstate /system/bin/dumpstate -sclass mainsocket dumpstate stream 0660 shell logdisabledoneshotservice otad /bin/otadclass mainsocket otad stream 0660 updater updaterseclabel u:r:otad:s0service sshd /system/bin/start-sshclass maindisabledservice mdnsd /system/bin/mdnsdclass mainuser mdnsrgroup inet net_rawsocket mdnsd stream 0660 mdnsr inetdisabledoneshotimport /init.miui.rc


更多推荐

android init.rc

本文发布于:2024-03-07 23:51:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:android   init   rc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!