韦东山imx6ull_pro开发板启动文件分析
S开头的脚本都是一些驱动外设脚本,以S40network为例,这是一个网络文件的设置脚本,在开机的过程中启动网络服务,对应其他的S开头的脚本都是对应的开发板开机过程中对应启动的服务。
这里主要说明rcK和rcS两个文件:
在类Unix系统(特别是在嵌入式系统或使用 sysvinit
初始化系统的轻量级发行版中)。rcS和rcK是两个重要的脚本,分别用于 启动(Startup)和 关闭 (Shutdown)过程,它们通常位于 /etc/init.d/
目录下,是系统初始化流程的一部分。
1、rcS脚本
这个脚本通常在系统初始化阶段(例如 /etc/rcS
或 /etc/init.d/rcS
),确保所有服务和配置在系统启动时正确加载。
运行机制:当系统进入单用户模式(runlevel S)或 多用户(runlevel 2~5)时,rcS会被调用。
#!/bin/sh
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
psplash -n &
for i in /etc/init.d/S??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
/bin/hostname -F /etc/hostname
总结一下这个脚本的作用就是:
1、启动 psplash 启动画面
2、按照顺序执行,/etc/init.d 目录中的所有启动文件(以S开头)
3、根据脚本类型选择合适的执行方式
4、最后设置系统的主机名
2、rcK 脚本
全称:Runlevel Change Script for Kill(关闭时的运行级别切换脚本)。
作用:在系统关闭或者系统重启时执行,负责停止多有运行的服务并清理资源。
运行机制:当系统进入 关机模式(runlevel 0) 或 重启模式(runlevel 6) 时,rcK
会被调用。
#!/bin/sh
# Stop all init scripts in /etc/init.d
# executing them in reversed numerical order.
#
for i in $(ls -r /etc/init.d/S??*) ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i stop
;;
esac
done
总结,这个脚本是一个典型的sysbinit关闭脚本,用于停止所有服务,通过反向顺序执行,/etc/init.d/目录中的脚本,确保依赖关系。