.rc files are read by the init process (PID 1) very early in the Android boot sequence. They define which services to start, which file systems to mount, what properties to set, and what actions to trigger when certain events happen. Understanding .rc files is essential for anyone working on AOSP daemons or boot customization.
Where RC Files Live
- ▸system/core/rootdir/init.rc - the main init.rc, part of AOSP core
- ▸device/<manufacturer>/<device>/init.<device>.rc - device-specific init file
- ▸vendor/etc/init/ - vendor service declarations (loaded from /vendor partition)
- ▸system/etc/init/ - system service declarations
- ▸Each .rc file is scanned and merged by init at boot
RC File Syntax
RC File - Key Sections
# ── SERVICE DEFINITION ───────────────────────
service adbd /system/bin/adbd
class core # service class group
socket adbd stream 660 system system
disabled # don't start automatically
seclabel u:r:adbd:s0 # SELinux label
# ── ACTION / TRIGGER ─────────────────────────
on early-init
setprop sys.init.early 1
on property:sys.boot_completed=1
start myvendordaemon
# ── IMPORT OTHER RC FILES ────────────────────
import /vendor/etc/init/myhal.rcService Options
- ▸class <name> - groups services; 'class_start core' starts all services in the 'core' class
- ▸oneshot - service runs once and exits (not restarted)
- ▸restart_backoff - how long to wait before restarting a crashed service
- ▸user / group - Linux user and group the service runs as
- ▸capabilities - Linux capabilities granted to the service (e.g. NET_ADMIN)
- ▸socket <name> <type> <perm> - creates a Unix domain socket for the service
- ▸file <path> <type> - opens a file and passes the fd to the service
Init Triggers (Actions)
- ▸on early-init - very first stage, minimal filesystem available
- ▸on init - basic setup, /proc and /sys mounted
- ▸on late-init - most services started here
- ▸on boot - triggered after late-init, network interfaces starting
- ▸on property:<key>=<value> - triggered when a property changes to that value
- ▸on fs - triggered when filesystems are being mounted
Tip: To debug init issues, use 'adb shell dmesg | grep init' or 'adb logcat -s init'. To check whether a service is running: 'adb shell getprop init.svc.<service_name>' - returns 'running', 'stopped', or 'restarting'.