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*