Understanding the booting process of an OpenWrt router and script priorities

Dear community,

I am interested in the booting process of my OpenWrt router. I tried to explore the file system and found out that some folders have scripts with priority numbers in their names. For example, there is a /lib/preinit/ folder.

What is the first script that runs when I start my router, and what is the order of the scripts? Is there a possibility to track this, perhaps with a serial connection?

At which stage of the boot process?
What are you aiming for? (the suitable answer depends on that)

The preinit scripts are run first, already before any overlay volumes are mounted, (they actually mount the overlay), so you can't have much logic there. Those are for really early low-level actions for the base system. "Do I enter failsafe mode or not?"

After mounting the overlay, normal init scripts from /etc/init.d are run in the numerical order by the symlinks in /etc/rc.d
At priority 10 (pretty early) the "boot" script also runs the uci-defaults files from /etc/uci-defaults (which after running only visible in /rom ). uci-defaults scripts are meant to be used for modifying the config files before most of the init scripts launching the various services.

root@router1:~# ls -1 /etc/rc.d/S*
/etc/rc.d/S00sysfixtime
/etc/rc.d/S00urngd
/etc/rc.d/S10boot
/etc/rc.d/S10system
/etc/rc.d/S11fstab
/etc/rc.d/S11sysctl
/etc/rc.d/S12log
/etc/rc.d/S12rpcd
/etc/rc.d/S13openssl
/etc/rc.d/S15cpufreq
/etc/rc.d/S19dnsmasq
/etc/rc.d/S19dropbear
/etc/rc.d/S19firewall
/etc/rc.d/S19qosify
/etc/rc.d/S19unetd
/etc/rc.d/S19wpad
/etc/rc.d/S20bcp38
/etc/rc.d/S20network
/etc/rc.d/S25packet_steering
/etc/rc.d/S30adblock
/etc/rc.d/S30banip
/etc/rc.d/S30radius
/etc/rc.d/S35odhcpd
/etc/rc.d/S50cron
/etc/rc.d/S50sqm
/etc/rc.d/S50uhttpd
/etc/rc.d/S60nlbwmon
/etc/rc.d/S79luci_statistics
/etc/rc.d/S80collectd
/etc/rc.d/S80ucitrack
/etc/rc.d/S90irqbalance
/etc/rc.d/S94gpio_switch
/etc/rc.d/S94miniupnpd
/etc/rc.d/S95ddns
/etc/rc.d/S95done
/etc/rc.d/S96led
/etc/rc.d/S98sysntpd
/etc/rc.d/S99bootcount
/etc/rc.d/S99urandom_seed
3 Likes