am57xx_env根文件加载过程
1. /etc/inittab
# The default runlevel.
id:
5:initdefault:
/*默认启动级别为5*/
si::
sysinit:
/etc/init.d/rcS
# What to do in single-user mode.
~~:
S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change of runlevel.
# Runlevel 0 is halt;Runlevel 1 is single-user;Runlevels 2-5 are multi-user;Runlevel 6 is reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
O2:12345:respawn:/sbin/getty -L 115200 ttyO2
1:12345:respawn:/sbin/getty 38400 tty1
总结:在etc目录中目录rc0.d、rc1.d、rc2.d、rc3.d、rc4.d、rc5.d、rc6.d、rcS.d表示不同运行等级,其中只是链接文件,实际指向目录/etc/init.d中文件;不同级别对应不同目录,运行了不同个数的脚本。
2. /etc/init.d/rcS
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
# Make sure proc is mounted
[ -d "/proc/1" ] || mount /proc
/*确认proc并挂载*/
. /etc/default/rcS /*为/etc/rcS.d目录中启动脚本设置默认值*/
# Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
trap ":" INT QUIT TSTP
# Call all parts in order.
exec /etc/init.d/rc S /*使用S等级启动服务*/
--- /etc/default/rcS
#Defaults for the boot scripts in /etc/rcS.d
# Time files in /tmp are kept in days.
TMPTIME=0
# Set to yes if you want sulogin to be spawned on bootup
SULOGIN=no
# Set to no if you want to be able to login over telnet/rlogin
# before system startup is complete (as soon as inetd is started)
DELAYLOGIN=no
# Assume that the BIOS clock is set to UTC time (recommended)
UTC=yes
/*使用BIOS时钟设置UTC时间*/
# Set VERBOSE to "no" if you would like a more quiet bootup.
VERBOSE=no
/*设置VERBOSE为no,可以更加简便的启动*/
# Set EDITMOTD to "no" if you don't want /etc/motd to be edited automatically
EDITMOTD=no
# Whether to fsck root on boot
ENABLE_ROOTFS_FSCK=no
# Set FSCKFIX to "yes" if you want to add "-y" to the fsck at startup.
FSCKFIX=yes
# Set TICKADJ to the correct tick value for this specific machine
#TICKADJ=10000
# Enable caching in populate-volatile.sh
VOLATILE_ENABLE_CACHE=yes
# Indicate whether the rootfs is intended to be read-only or not.
# Setting ROOTFS_READ_ONLY to yes and rebooting will give you a read-only rootfs.
# Normally you should not change this value.
ROOTFS_READ_ONLY=no
--- /etc/init.d/rc
#!/bin/sh
. /etc/default/rcS
export VERBOSE
startup_progress()
{
step=$(($step + $step_change))
if [ "$num_steps" != "0" ]; then
progress=$((($step * $progress_size / $num_steps) + $first_step))
else
progress=$progress_size
fi
if [ -e /mnt/.psplash/psplash_fifo ]; then
echo "PROGRESS $progress" > /mnt/.psplash/psplash_fifo
fi
}
startup()
{
[ "$VERBOSE" = very ] && echo "INIT: Running $@..."
/*以.sh结尾的脚本是必须执行的脚本,不是以.sh结尾的脚本服务是可以开启或关闭的,通过start或stop参数*/
case "$1" in
/*传入的第一个参数是要执行的文件名,第二个参数是start*/
*.sh)
(
/*若文件名是以.sh结尾的则执行这个脚本*/
trap - INT QUIT TSTP
scriptname=$1
shift
. $scriptname
)
;;
*)
/*若不是以.sh结尾的*/
/*实际上rc进程调用的脚本都称为初始化脚本。要启动、停止或者重启一个服务,应该用参数start、stop和restart。*/
"$@" /*执行这个脚本带参数,比如传入的是$@=“/etc/rcS.d/S02banner start”,即带start参数执行这个脚本,这样可以灵活的控制服务的start或者stop*/
;;
esac
startup_progress
}
#忽略这三个信号,防止脚本执行时使用ctrl-C就退出脚本.
trap ":" INT QUIT TSTP
#设置终端,将CR字符映射为NL字符,避免阶梯效应
stty onlcr 0>&1
# Limit stack size for startup scripts
[ "$STACK_SIZE" == "" ] || ulimit -S -s $STACK_SIZE
# Now find out what the current and what the previous runlevel are.
runlevel=$RUNLEVEL
# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel=$1
if [ "$runlevel" = "" ]
then
echo "Usage: $0
" >&2
exit 1
fi
previous=$PREVLEVEL
[ "$previous" = "" ] && previous=N
/*传入参数是S的话,则runlevel=S、previous=N*/
export runlevel previous
/*检查该目录是否为空目录,执行里面的脚本等*/
if [ -d /etc/rc$runlevel.d ]
then
PROGRESS_STATE=0
progress_size=$(((100 - $PROGRESS_STATE) / 3))
case "$runlevel" in
0|6)
first_step=-100
progress_size=100
step_change=1
;;
S)
first_step=$PROGRESS_STATE
progress_size=$(($progress_size * 2))
step_change=1
;;
*)
first_step=$(($progress_size * 2 + $PROGRESS_STATE))
step_change=1
;;
esac
num_steps=0
for s in /etc/rc$runlevel.d/[SK]*; /*取/etc/rcS.d目录下以S或K开头的文件名*/
do
/*去掉变量s中所有的/etc/rcS.d/S?的部分,若s剩下的文件名中为这5个中则跳出for*/
case "${s##/etc/rc$runlevel.d/S??}" in
gdm|xdm|kdm|reboot|halt)
break
;;
esac
num_steps=$(($num_steps + 1))/*表示查找到目录/etc/rcS.d下有多少个脚本*/
done
step=0
/*第一步,运行KILL脚本*/
if [ $previous != N ]
then
for i in /etc/rc$runlevel.d/K[0-9][0-9]*
do
[ ! -f $i ] && continue
startup $i stop /*在本文件中startup()函数*/
done
fi
/*第二步,运行这个级别的START脚本*/
for i in /etc/rc$runlevel.d/S* /*取得S开头的脚本*/
do
[ ! -f $i ] && continue /*检查是否为常规文件,不是则进行下次循环*/
/*如果previous=N/S,则此if语句不执行*/
if [ $previous != N ] && [ $previous != S ]
then
suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]} /*获得i文件名的后缀*/
stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix /*获得stop文件名*/
previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
/*如果有起始脚本并且灭有停止脚本,则不进行这项服务,continue继续下一次循环*/
[ -f $previous_start ] && [ ! -f $stop ] && continue
fi
case "$runlevel" in
0|6) /*运行级别0或者6*/
startup $i stop
;;
*) /*在本文件中startup()函数,运行名称$i的脚本*/
startup $i start
;;
esac
done
fi
if [ "x$runlevel" != "xS" ] && [ ! -x /etc/rc${runlevel}.d/S??xserver-nodm ]; then
if type psplash-write >/dev/null 2>&1; then
TMPDIR=/mnt/.psplash psplash-write "QUIT" || true
umount -l /mnt/.psplash
fi
fi
3. /etc/init.d/***
3.1
/etc/init.d/alignment.sh
#!/bin/sh
if [ -e /proc/cpu/alignment ]; then
echo "3" > /proc/cpu/alignment
fi
/* 设置Linux对出现字节对齐错误的处理方式:0(忽略),1(提醒警告),2(修复),3(修复+提醒警告),4(信号),5(信号+提醒警告)*/
3.2 /etc/init.d/alsa-state(声音系统)
安装了alsa的驱动,但是每一次开机的时候,声卡总是静音,要进行手工调解。
决定进行改造:
每次重启电脑后,音量设置都复位了,需重新调整音量。经研究,原来是我没有把ALSA声音系统的当前设置状态保存到 /var/lib/alsa/asound.state中。而每次重启电脑时,ALSA系统的初始化脚本(/etc/init.d/alsa)会用 /var/lib/alsa/asound.state这个默认的配置文件来设置ALSA系统的状态。所以就造成用户自已配置的状态失效,每次重启都还原到初始状态。有一个工具叫alsactl,它可自动把当前配置信息保存到/var/lib/alsa/asound.state中。alsactl包含在alsa-utils软件包中。用以下命令安装:
debian:~# apt-get install alsa-utils
把音量、音 {MOD}等调整好后,保存到/var/lib/alsa/asound.state文件中:
debian:~# alsactl store
重启电脑,马上就可聆听到自由的声音了。
脚本内容:
#! /bin/sh
# source function library
. /etc/init.d/functions
asound_restore(){
echo "ALSA: Restoring mixer settings..."
if test -x /usr/sbin/alsactl -a -e /var/lib/alsa/asound.state
then
/usr/sbin/alsactl -f /var/lib/alsa/asound.state restore &
fi
}
asound_store(){
echo "ALSA: Storing mixer settings..."
if test -x /usr/sbin/alsactl
then
/usr/sbin/alsactl -f /var/lib/alsa/asound.state store
fi
}
case "$1" in
start)asound_restore ;;
stop)asound_store ;;
status)
status /usr/sbin/alsactl;
exit $?
;;
*)
echo "Usage: /etc/init.d/alsa-state {start|stop|status}"
exit 1
;;
esac
3.3 /etc/init.d/functions
该脚本是给/etc/init.d里边的文件使用的。提供了一些基础的功能,看看里边究竟有些什么。首先会设置umask,path,还有语言环境,然后会设置success,failure,warning,normal几种情况下的字体颜 {MOD}。提供的重要方法:
checkpid:检查是否已存在pid,如果有一个存在,返回0(通过查看/proc目录)
daemon:启动某个服务。/etc/init.d目录部分脚本的start使用到这个
killproc:杀死某个进程。/etc/init.d目录部分脚本的stop使用到这个
pidfileofproc:寻找某个进程的pid
pidofproc:类似上面的,只是还查找了pidof命令
status:返回一个服务的状态
echo_success,echo_failure,echo_passed,echo_warning分别输出各类信息
success,failure,passed,warning分别记录日志并调用相应的方法
action:打印某个信息并执行给定的命令,它会根据命令执行的结果来调用success,failure方法
strstr:判断$1是否含有$2
confirm:显示"Start service $1(Y)es/(N)o/(C)ontinue?[Y]"的提示信息,并返回选择结果
脚本内容:
# -*-Shell-script-*-
NORMAL="\033[0;39m" # Standard console grey
SUCCESS="\033[1;32m" # Success is green
WARNING="\033[1;33m" # Warnings are yellow
FAILURE="\033[1;31m" # Failures are red
INFO="\033[1;36m" # Information is light cyan
BRACKET="\033[1;34m" # Brackets are blue
pidofproc () {
# pidof output null when no program is running, so no "2>/dev/null".
pid=`pidof $1`
status=$?
case $status in
0)
echo $pid
return 0
;;
127)
echo "ERROR: command pidof not found" >&2
exit 127
;;
*)
return $status
;;
esac
}
machine_id() { # return the machine ID
awk 'BEGIN { FS=": " } /Hardware/
{ gsub(" ", "_", $2); print tolower($2) } '
}
killproc() { # kill the named process(es)
pid=`pidofproc $1` && kill $pid
}
status() {
local pid
if [ "$#" = 0 ]; then
echo "Usage: status {program}"
return 1
fi
pid=`pidofproc $1`
if [ -n "$pid" ]; then
echo "$1 (pid $pid) is running..."
return 0
else
echo "$1 is stopped"
fi
return 3
}
success() {
echo -n -e "${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
return 0
}
failure() {
local rc=$*
echo -n -e "${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
return $rc
}
warning() {
local rc=$*
echo -n -e "${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
return $rc
}
passed() {
local rc=$*
echo -n -e "${BRACKET}[${SUCCESS} PASS ${BRACKET}]${NORMAL}"
return $rc
}
3.4 /etc/init.d/avahi-daemon(零配置网络服务)
Zeroconf(Zero configuration networking)零配置网络服务规范,是一种用于自动生成可用IP地址的网络技术,不需要额外的手动配置和专属的配置服务器。“零 配置网络服务”的目标,是让非专业用户也能便捷的连接各种网络设备,例如计算机,打印机等。整个搭建网络的过程都是通过程式自动化实现。如果没有 zeroconf,用户必须手动配置一些服务,例如DHCP、DNS,计算机网络的其他设置等。这些对非技术用户和新用户们来说是很难的事情。Zeroconf规范的提出者是Apple公司。
Avahi是Zeroconf规范的开源实现。Avahi允许程序在不需要进行手动网络配置的情况 下,在一个本地网络中发布和获知各种服务和主机。例如,当某用户把他的计算机接入到某个局域网时,如果他的机器运行有Avahi服务,则Avahi程式自 动广播,从而发现网络中可用的打印机、共享文件和可相互聊天的其他用户。这有点象他正在接收局域网中的各种网络广告一样。
脚本内容:
#!/bin/sh
if [ -f /lib/lsb/init-functions ]
then
. /lib/lsb/init-functions
else
# int log_begin_message (char *message)
log_begin_msg () {
if [ -z "$1" ]; then
return 1
fi
echo " * $@"
}
# int log_end_message (int exitstatus)
log_end_msg () {
# If no arguments were passed, return
[ -z "$1" ] && return 1
# Only do the fancy stuff if we have an appropriate terminal
# and if /usr is already mounted
TPUT=/usr/bin/tput
EXPR=/usr/bin/expr
if [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1; then
COLS=`$TPUT cols`
if [ -n "$COLS" ]; then
COL=`$EXPR $COLS - 7`
else
COL=73
fi
UP=`$TPUT cuu1`
END=`$TPUT hpa $COL`
START=`$TPUT hpa 0`
RED=`$TPUT setaf 1`
NORMAL=`$TPUT op`
if [ $1 -eq 0 ]; then
echo "$UP$END[ ok ]"
else
echo -e "$UP$START $RED*$NORMAL$END[${RED}fail${NORMAL}]"
fi
else
if [ $1 -eq 0 ]; then
echo " ...done."
else
echo " ...fail!"
fi
fi
return $1
}
log_warning_msg () {
if log_use_fancy_output; then
YELLOW=`$TPUT setaf 3`
NORMAL=`$TPUT op`
echo "$YELLOW*$NORMAL $@"
else
echo "$@"
fi
}
fi
#set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="Avahi mDNS/DNS-SD Daemon"
NAME="avahi-daemon"
DAEMON="/usr/sbin/$NAME"
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
# don't start if /etc/default/avahi-daemon says so.
AVAHI_DAEMON_START=1
test -f /etc/default/avahi-daemon && . /etc/default/avahi-daemon
if [ "$AVAHI_DAEMON_START" != "1" -a "$1" != "stop" ]; then
log_warning_msg "Not starting $DESC $NAME, disabled via /etc/default/$NAME"
exit 0
fi
# Function that starts the daemon/service.
d_start() {
modprobe capability >/dev/null 2>&1 || true
$DAEMON -c && return 0
if [ -s /etc/localtime ]; then
if [ ! -d /etc/avahi/etc ]; then
mkdir -p /etc/avahi/etc >/dev/null 2>&1
fi
cp -fp /etc/localtime /etc/avahi/etc >/dev/null 2>&1
fi;
$DAEMON -D
}
# Function that stops the daemon/service.
d_stop() {
$DAEMON -c && $DAEMON -k
}
# Function that reload the config file for the daemon/service.
d_reload() {
$DAEMON -c && $DAEMON -r
}
# Function that check the status of the daemon/service.
d_status() {
$DAEMON -c
status=$?
if [ $status = 0 ]; then
echo "$DESC is running"
return 0
else
echo "$DESC is not running"
return 3
fi
}
case "$1" in
start)
log_begin_msg "Starting $DESC: $NAME"
d_start
log_end_msg $?
;;
stop)
log_begin_msg "Stopping $DESC: $NAME"
d_stop
log_end_msg $?
;;
reload)
log_begin_msg "Reloading services for $DESC: $NAME"
d_reload
log_end_msg $?
;;
restart|force-reload)
log_begin_msg "Restarting $DESC: $NAME"
$DAEMON -c && d_stop
d_start
log_end_msg $?
;;
status)
d_status
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload|status}" >&2
exit 1
;;
esac
exit $?
3.5 /etc/init.d/banner.sh
/*建立tty设备节点*/
#!/bin/sh
if [ ! -e /dev/tty ]; then
/bin/mknod -m 0666 /dev/tty c 5 0
fi
if ( > /dev/tty0 ) 2>/dev/null; then
vtmaster=/dev/tty0
elif ( > /dev/vc/0 ) 2>/dev/null; then
vtmaster=/dev/vc/0
elif ( > /dev/console ) 2>/dev/null; then
vtmaster=/dev/console
else
vtmaster=/dev/null
fi
echo > $vtmaster
echo "Please wait: booting..." > $vtmaster
3.6 /etc/init.d/bootlogd
/*启动日志:记录启动信息*/
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/sbin/bootlogd
NAME=bootlogd
DESC="Bootlog daemon"
# source function library
. /etc/init.d/functions
test -f $DAEMON || exit 0
[ -r /etc/default/bootlogd ] && . /etc/default/bootlogd
## set -e # not needed
case "$BOOTLOGD_ENABLE" in
[Nn]*)
exit 0
;;
esac
STOPPER=
ACTION="$1"
case "$0" in
*stop-bootlog*)
STOPPER=Y
if [ "$ACTION" = start ]
then
ACTION=stop
fi
;;
esac
case "$ACTION" in
start)
[ "${VERBOSE}" != "no" ] && echo -n "Starting $DESC: "
if [ -d /proc/1/. ]
then
umask 027
start-stop-daemon --start --quiet
--exec $DAEMON -- -r -c
else
$DAEMON -r -c
fi
[ "${VERBOSE}" != "no" ] && echo "$NAME."
;;
stop)
# stop may get called during bootup, so let it honor
# rcS VERBOSE setting
[ "${VERBOSE}" != "no" ] && echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --exec $DAEMON
if [ "$STOPPER" ] && [ "$(which savelog 2>/dev/null)" ] &&
[ -f /var/log/boot ] && [ -f /var/log/boot~ ]
then
cd /var/log
chgrp adm boot
savelog -p -c 5 boot > /dev/null 2>&1
mv boot.0 boot
mv boot~ boot.0
fi
[ "${VERBOSE}" != "no" ] && echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --exec $DAEMON
echo "$NAME."
;;
status)
status $DAEMON
exit $?
;;
*)
N=${0##*/}
N=${N#[SK]??}
echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
3.7 /etc/init.d/bootmisc.sh
#!/bin/sh
. /etc/default/rcS
# Put a nologin file in /etc to prevent people from logging in before
# system startup is complete.
if test "$DELAYLOGIN" = yes
then
echo "System bootup in progress - please wait" > /etc/nologin
cp /etc/nologin /etc/nologin.boot
fi
# Set pseudo-terminal access permissions.
if test -c /dev/ttyp0
then
chmod 666 /dev/tty[p-za-e][0-9a-f]
chown root:tty /dev/tty[p-za-e][0-9a-f]
fi
# Apply /proc settings if defined
SYSCTL_CONF="/etc/sysctl.conf"
if [ -f "${SYSCTL_CONF}" ]
then
if [ -x "/sbin/sysctl" ]
then
# busybox sysctl does not support -q
VERBOSE_REDIR="1>/dev/null"
if [ "${VERBOSE}" != "no" ]; then
VERBOSE_REDIR="1>&1"
fi
eval /sbin/sysctl -p "${SYSCTL_CONF}" $VERBOSE_REDIR
else
echo "To have ${SYSCTL_CONF} applied during boot, install package ."
fi
fi
/*更新motd文件*/
/*motd即message of today(布告栏信息),每次用户登录时, motd文件的内容会显示在用户的终端*/
if test "$EDITMOTD" != no
then
uname -a > /etc/motd.tmp
sed 1d /etc/motd >> /etc/motd.tmp
mv /etc/motd.tmp /etc/motd
fi
/*使用硬件时钟设置系统时钟:如果timestamp更加接近当前时间,使用timestamp替代*/
test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh start
if test -e /etc/timestamp
then
SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M%2S`
read TIMESTAMP < /etc/timestamp
if [ ${TIMESTAMP} -gt $SYSTEMDATE ]; then
# format the timestamp as date expects it (2m2d2H2M4Y.2S)
TS_YR=${TIMESTAMP%??????????}
TS_SEC=${TIMESTAMP#????????????}
TS_FIRST12=${TIMESTAMP%??}
TS_MIDDLE8=${TS_FIRST12#????}
date -u ${TS_MIDDLE8}${TS_YR}.${TS_SEC}
test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh stop
fi
fi
: exit 0
3.8 /etc/init.d/checkroot.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides: checkroot
# Required-Start: udev
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Check to root file system.
### END INIT INFO
. /etc/default/rcS
# Set SULOGIN in /etc/default/rcS to yes if you want a sulogin to be spawned
# from this script *before anything else* with a timeout, like SCO does.
test "$SULOGIN" = yes && sulogin -t 30 $CONSOLE
# Read /etc/fstab.
exec 9< /etc/fstab
rootmode=rw
rootopts=rw
rootcheck=$ENABLE_ROOTFS_FSCK
swap_on_md=no
devfs=
while read fs mnt type opts dump pass junk <&9
do
case "$fs" in
""|#*)
continue;
;;
/dev/md*)
# Swap on md device.
test "$type" = swap && swap_on_md=yes
;;
/dev/*)
;;
*)
# Might be a swapfile.
test "$type" = swap && swap_on_md=yes
;;
esac
test "$type" = devfs && devfs="$fs"
test "$mnt" != / && continue
rootopts="$opts"
test "$pass" = 0 -o "$pass" = "" && rootcheck=no
case "$opts" in
ro|ro,*|*,ro|*,ro,*)
rootmode=ro
;;
esac
done
exec 0>&9 9>&-
# Check for conflicting configurations
if [ "$rootmode" = "ro" -a "$ROOTFS_READ_ONLY" = "no" ] ||
[ "$rootmode" = "rw" -a "$ROOTFS_READ_ONLY" = "yes" ]; then
echo ""
echo "WARN: conflicting configurations in /etc/fstab and /etc/default/rcS"
echo " regarding the writability of rootfs. Please fix one of them."
echo ""
fi
# Activate the swap device(s) in /etc/fstab. This needs to be done
# before fsck, since fsck can be quite memory-hungry.
test "$VERBOSE" != no && echo "Activating swap"
swapon -a 2> /dev/null
# Check the root filesystem.
if test -f /fastboot || test $rootcheck = no
then
test $rootcheck = yes && echo "Fast boot, no filesystem check"
else
# Ensure that root is quiescent and read-only before fsck'ing.
mount -n -o remount,ro /
if test $? = 0
then
if test -f /forcefsck
then
force="-f"
else
force=""
fi
if test "$FSCKFIX" = yes
then
fix="-y"
else
fix="-a"
fi
spinner="-C"
case "$TERM" in
dumb|network|unknown|"") spinner="" ;;
esac
test `uname -m` = s390 && spinner="" # This should go away
test "$VERBOSE" != no && echo "Checking root filesystem..."
fsck $spinner $force $fix /
# If there was a failure, drop into single-user mode.
# NOTE: "failure" is defined as exiting with a return code of
# 2 or larger. A return code of 1 indicates that filesystem
# errors were corrected but that the boot may proceed.
if test "$?" -gt 1
then
# Surprise! Re-directing from a HERE document (as in
# "cat << EOF") won't work, because the root is read-only.
echo
echo "fsck failed. Please repair manually and reboot. Please note"
echo "that the root filesystem is currently mounted read-only. To"
echo "remount it read-write:"
echo
echo " # mount -n -o remount,rw /"
echo
echo "CONTROL-D will exit from this shell and REBOOT the system."
echo
# Start a single user shell on the console
/sbin/sulogin $CONSOLE
reboot -f
fi
else
echo "*** ERROR! Cannot fsck root fs because it is not mounted read-only!"
echo
fi
fi
# If the root filesystem was not marked as read-only in /etc/fstab,
# remount the rootfs rw but do not try to change mtab because it
# is on a ro fs until the remount succeeded. Then clean up old mtabs
# and finally write the new mtab.
mount -n -o remount,$rootmode /
if test "$rootmode" = rw
then
ln -sf /proc/mounts /dev/mtab
fi
: exit 0
3.9 /etc/init.d/dbus-1(消息总线系统)
D-Bus是一个消息总线系统,用于应用程序进程之间的通信。如果你准备在不同的进程之间传递大量的数据,D-Bus可能不是最有效的方法,最有效的方法是使用共享内存,但是对共享内存的管理也是相当复杂的。
涉及文件:
/usr/bin/dbus-daemon;
/var/run/messagebus.pid;
/var/lib/dbus;
/etc/dbus-1/event.d;
/etc/default/dbus;
脚本内容:
#! /bin/sh
# Source function library.
. /etc/init.d/functions
DAEMON=/usr/bin/dbus-daemon
NAME=dbus
DAEMONUSER=messagebus # must match /etc/dbus-1/system.conf
PIDFILE=/var/run/messagebus.pid # must match /etc/dbus-1/system.conf
UUIDDIR=/var/lib/dbus
DESC="system message bus"
EVENTDIR=/etc/dbus-1/event.d
test -x $DAEMON || exit 0
# Source defaults file; edit that file to configure this script.
ENABLED=1
PARAMS=""
if [ -e /etc/default/dbus ]; then
. /etc/default/dbus
fi
test "$ENABLED" != "0" || exit 0
start_it_up()
{
mkdir -p "`dirname $PIDFILE`"
if [ -e $PIDFILE ]; then
PIDDIR=/proc/$(cat $PIDFILE)
if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then
echo "$DESC already started; not starting."
else
echo "Removing stale PID file $PIDFILE."
rm -f $PIDFILE
fi
fi
if [ ! -d $UUIDDIR ]; then
mkdir -p $UUIDDIR
chown $DAEMONUSER $UUIDDIR
chgrp $DAEMONUSER $UUIDDIR
fi
dbus-uuidgen --ensure
echo -n "Starting $DESC: "
start-stop-daemon -o --start --quiet --pidfile $PIDFILE
--user $DAEMONUSER --exec $DAEMON -- --system $PARAMS
echo "$NAME."
if [ -d $EVENTDIR ]; then
run-parts --arg=start $EVENTDIR
fi
}
shut_it_down()
{
if [ -d $EVENTDIR ]; then
# TODO: --reverse when busybox supports it
run-parts --arg=stop $EVENTDIR
fi
echo -n "Stopping $DESC: "
start-stop-daemon -o --stop --quiet --pidfile $PIDFILE
--user $DAEMONUSER
echo "$NAME."
rm -f $PIDFILE
}
reload_it()
{
echo -n "Reloading $DESC config: "
dbus-send --print-reply --system --type=method_call
--dest=org.freedesktop.DBus
/ org.freedesktop.DBus.ReloadConfig > /dev/null
# hopefully this is enough time for dbus to reload it's config file.
echo "done."
}
case "$1" in
start)
start_it_up
;;
stop)
shut_it_down
;;
status)
status $DAEMON
exit $?
;;
reload|force-reload)
reload_it
;;
restart)
shut_it_down
sleep 1
start_it_up
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|status|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0
3.9 /etc/init.d/devpts.sh
挂载devpts,为udev启动自动挂载设备做准备
#!/bin/sh
# Provides: devpts
# Required-Start: udev
. /etc/default/devpts
if grep -q devpts /proc/filesystems
then
test -c /dev/ptmx || mknod -m 666 /dev/ptmx c 5 2
# Mount /dev/pts if needed.
if ! grep -q devpts /proc/mounts
then
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts -ogid=${TTYGRP},mode=${TTYMODE}
fi
fi
3.10 /etc/init.d/dmesg.sh
#!/bin/sh
if [ -f /var/log/dmesg ]; then
if [ -f /usr/sbin/logrotate ]; then
logrotate -f /etc/logrotate-dmesg.conf
else
mv -f /var/log/dmesg /var/log/dmesg.old
fi
fi
dmesg -s 131072 > /var/log/dmesg
3.11 /etc/init.d/dropbear(SSH安全协议)
dropbear实现完整的SSH客户端和服务器版本2协议。
ssh(Secure Shell)安全外壳协议,SSH为建立在应用层和传输层基础上的安全协议。传统的网络服务程序,如:ftp、pop和telnet在本质上都是不安全的,因为它们在网络上用明文传送口令和数据。利用
SSH 协议可以有效防止远程管理过程中的信息泄露问题。
涉及文件:
/usr/sbin/dropbear;
/var/run/dropbear.pid;
/etc/default/dropbear;
/var/service/dropbear;
脚本内容:
#!/bin/sh
# Do not configure this file. Edit /etc/default/dropbear instead!
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/dropbear
NAME=dropbear
DESC="Dropbear SSH server"
PIDFILE=/var/run/dropbear.pid
DROPBEAR_PORT=22
DROPBEAR_EXTRA_ARGS=
NO_START=0
set -e
test ! -r /etc/default/dropbear || . /etc/default/dropbear
test "$NO_START" = "0" || exit 0
test -x "$DAEMON" || exit 0
test ! -h /var/service/dropbear || exit 0
readonly_rootfs=0
for flag in `awk '{ if ($2 == "/") { split($4,FLAGS,",") } }; END { for (f in FLAGS) print FLAGS[f] }' &2
exit 1
;;
esac
exit 0
3.12 /etc/init.d/gdbserverproxy(gdb调试)
在pc机上对在开发板上运行的程序进行调试。
pc机上的gdb向开发板上的gdbserver发出命令,而开发板上的gdbserver就会向应用程序发出信号,使应用程序停下来或者完成其他一些工作!由此知道,pc机上要运行gdb,开发板上要运行gdbserver!
脚本内容:
#!/bin/bash
GDB_DEVICE_NAME='/dev/gdbtty$i'
DSP_FIRMWARE_NAME='/lib/firmware/dra7-dsp$[$i+1]-fw.xe66'
DSP_L2_GLOBAL_OFFSET="40000000"
DSP_L2_GLOBAL_SHIFT="00800000"
case "$1" in
start)
dsp_core_l2_offset=$DSP_L2_GLOBAL_OFFSET
i=0
while [ -c "`eval echo $GDB_DEVICE_NAME`" ]
do
dsp_firmware=`eval echo $DSP_FIRMWARE_NAME`
if [ -f "`eval echo $DSP_FIRMWARE_NAME`" ]
then
eval echo "Initializing $GDB_DEVICE_NAME based on $DSP_FIRMWARE_NAME ..."
gdb_data_local=`eval readelf -s "$DSP_FIRMWARE_NAME" |
grep 'gdb_globalData' |
awk '{print $2}'`
echo "gdb_globalData (local) = $gdb_data_local"
printf "gdb_globalData (global) = %X
"
$[0x$gdb_data_local + 0x$dsp_core_l2_offset]
printf "%X
" $[0x$gdb_data_local + 0x$dsp_core_l2_offset]
>> `eval echo $GDB_DEVICE_NAME`
fi
i=$[$i + 1]
dsp_core_l2_offset=`printf "%X" $[0x$dsp_core_l2_offset + 0x$DSP_L2_GLOBAL_SHIFT]`
done
;;
stop)
# Nothing to be done.
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
3.13 /etc/init.d/gplv3-notice
GPL(GNU通用公共许可证)。
3.14 /etc/init.d/halt
执行halt命令。
脚本内容:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# See if we need to cut the power.
if test -x /etc/init.d/ups-monitor
then
/etc/init.d/ups-monitor poweroff
fi
# Don't shut down drives if we're using RAID.
hddown="-h"
if grep -qs '^md.*active' /proc/mdstat
then
hddown=""
fi
halt -d -f -p $hddown
: exit 0
3.15 /etc/init.d/hostapd(WiFi_AP)
使用hostapd让电脑上的无线网卡工作在AP模式
#!/bin/sh
DAEMON=/usr/sbin/hostapd
NAME=hostapd
DESC="HOSTAP Daemon"
ARGS="/etc/hostapd.conf -B"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon -S -x $DAEMON -- $ARGS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon -K -x $DAEMON
echo "$NAME."
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading $DESC: "
killall -HUP $(basename ${DAEMON})
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
3.16 /etc/init.d/hostname.sh
设置主机名:在/etc/hostname基础之上设置主机名
#!/bin/sh
HOSTNAME=$(/bin/hostname)
hostname -b -F /etc/hostname 2> /dev/null
if [ $? -eq 0 ]; then
exit
fi
# Busybox hostname doesn't support -b so we need implement it on our own
if [ -f /etc/hostname ];then
hostname `cat /etc/hostname`
elif [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" -o ! -z "`echo $HOSTNAME | sed -n '/^[0-9]*.[0-9].*/p'`" ] ; then
hostname localhost
fi
3.17 /etc/init.d/hwclock.sh
使用系统时钟设定与显示硬件时钟。
硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。所有Linux相关指令与函数都是读取系统时钟的设定。
涉及文件:
/sbin/hwclock
脚本内容:
#!/bin/sh
[ ! -x /sbin/hwclock ] && exit 0
[ -f /etc/default/rcS ] && . /etc/default/rcS
[ "$UTC" = "yes" ] && tz="--utc" || tz="--localtime"
case "$1" in
start)
if [ "$VERBOSE" != no ]
then
echo "System time was `date`."
echo "Setting the System Clock using the Hardware Clock as reference..."
fi
if [ "$HWCLOCKACCESS" != no ]
then
if [ -z "$TZ" ]
then
hwclock $tz --hctosys
else
TZ="$TZ" hwclock $tz --hctosys
fi
fi
if [ "$VERBOSE" != no ]
then
echo "System Clock set. System local time is now `date`."
fi
;;
stop|restart|reload|force-reload)
# Updates the Hardware Clock with the System Clock time.
# This will *override* any changes made to the Hardware Clock.
if [ "$VERBOSE" != no ]
then
echo "Saving the System Clock time to the Hardware Clock..."
fi
if [ "$HWCLOCKACCESS" != no ]
then
hwclock $tz --systohc
fi
if [ "$VERBOSE" != no ]
then
echo "Hardware Clock updated to `date`."
fi
exit 0
;;
show)
if [ "$HWCLOCKACCESS" != no ]
then
hwclock $tz --show
fi
;;
*)
echo "Usage: hwclock.sh {start|stop|show|reload|restart}" >&2
echo "start sets kernel (system) clock from hardware (RTC) clock" >&2
echo "stop and reload set hardware (RTC) clock from kernel (system) clock" >&2
exit 1
;;
esac
3.18 /etc/init.d/inetd.busybox
该脚本启动或停止inetd守护进程。
inetd介绍见文档:《am335x msp700根文件加载过程》
3.19 /etc/init.d/lighttpd(Web服务器)
该脚本启动或停止lighttpd开源的web服务器软件。
Lighttpd 是一个德国人领导的开源Web服务器软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销、cpu占用率低。Apache之所以流行,很大程度也是因为功能丰富。
Web服务器一般指网站服务器,是指驻留于因特网上某种类型计算机的程序,可以向浏览器等Web客户端提供文档,也可以放置网站文件,让网络用户浏览,可以放置数据文件,提供下载。
涉及文档:
/usr/sbin/lighttpd;
/etc/lighttpd.conf;
--- /etc/init.d/thttpd(Web服务器)
thttpd是一个非常小巧的轻量级web server,它非常非常简单,仅仅提供了HTTP/1.1和简单的CGI支持。此外,thttpd 也类似于lighttpd,对于并发请求不使用fork()来派生子进程处理,而是采用多路复用(Multiplex)技术来实现。thttpd较为引人注目的特点:基于URL的文件流量限制,这对于下载的流量控制而言是非常方便的。
涉及文档:
/usr/sbin/thttpd;
/srv/www/;
3.20 /etc/init.d/matrix-gui-2.0(应用)
该脚本启动或停止matrix-gui-2.0应用。
涉及文档:
/usr/bin/matrix_browser;
/var/run/matrix-gui-2.0.pid;
该sh文件启动了Damo板上界面显示的所有信息,应用程序在目录/usr/share/matrix-gui-2.0。
相关说明:http://processors.wiki.ti.com/index.php/Matrix_Users_Guide
3.21 /etc/init.d/modutils.sh
检测与加载驱动模块。
文档:《am335x msp700根文件加载过程》
3.22 /etc/init.d/mountall.sh
#!/bin/sh
. /etc/default/rcS
# Mount local filesystems in /etc/fstab. For some reason, people
# might want to mount "proc" several times, and mount -v complains
# about this. So we mount "proc" filesystems without -v.
test "$VERBOSE" != no && echo "Mounting local filesystems..."
mount -at nonfs,nosmbfs,noncpfs 2>/dev/null
# We might have mounted something over /dev, see if /dev/initctl is there.
if test ! -p /dev/initctl
then
rm -f /dev/initctl
mknod -m 600 /dev/initctl p
fi
kill -USR1 1
# Execute swapon command again, in case we want to swap to
# a file on a now mounted filesystem.
swapon -a 2> /dev/null
: exit 0
3.23 /etc/init.d/mountnfs.sh
挂载nfs、smbfs、mcpfs、cifs,或者还设置启动rpcbind即RPC服务。
RPC服务,主要是在nfs共享时候负责通知客户端,服务器的nfs端口号的。简单理解rpc就是一个中介服务。
--- /etc/init.d/rpcbind
涉及文档:
/usr/sbin/rpcbind;
/etc/default/rpcbind;
/etc/rpcbind.conf;
3.24 /etc/init.d/networking(???)
3.25 /etc/init.d/nfscommon
NFS服务支持。
涉及文档:
/usr/sbin/rpc.statd;
/var/run/rpc.statd.pid;
/var/lib/nfs;
3.26 /etc/init.d/ofono(工具)
启动或停止ofono应用工具。
通过bluez和ofono实现蓝牙的各种功能:蓝牙耳机、蓝牙GPS、蓝牙上网等等。
通过phonesim和ofono实现模拟电话:打电话功能。如果手上没有3G modem的话,可以装phonesim电话模拟器。配置成功就可以打电话了。
涉及文档:
/usr/sbin/ofonod;
/var/run/ofonod.pid;
/etc/default/ofono;
3.27 /etc/init.d/populate-volatile.sh(???)
3.28 /etc/init.d/psplash(进度条)
开机界面设置程序,Splash screen、U-boot Splash 、psplash 、X splash等是用在不同的阶段。
#!/bin/sh
read CMDLINE < /proc/cmdline
for x in $CMDLINE; do
case $x in
psplash=false)
echo "Boot splashscreen disabled"
exit 0;
;;
esac
done
export TMPDIR=/mnt/.psplash
mount tmpfs -t tmpfs $TMPDIR -o,size=40k
rotation=0
if [ -e /etc/rotation ]; then
read rotation < /etc/rotation
fi
/usr/bin/psplash --angle $rotation &
3.29 /etc/init.d/pvr-init
使用pvrsrvinit初始化图形驱动。
#!/bin/bash
case "$1" in
start)
echo "Initializing the graphics driver ..."
pvrsrvinit
;;
stop)
# Nothing to be done.
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
3.30 /etc/init.d/read-only-rootfs-hook.sh
#!/bin/sh
. /etc/default/rcS
[ "$ROOTFS_READ_ONLY" = "no" ] && exit 0
is_on_read_only_partition () {
DIRECTORY=$1
dir=`readlink -f $DIRECTORY`
while true; do
if [ ! -d "$dir" ]; then
echo "ERROR: $dir is not a directory"
exit 1
else
for flag in `awk -v dir=$dir '{ if ($2 == dir) { print "FOUND"; split($4,FLAGS,",") } };
END { for (f in FLAGS) print FLAGS[f] }' < /proc/mounts`; do
[ "$flag" = "FOUND" ] && partition="read-write"
[ "$flag" = "ro" ] && { partition="read-only"; break; }
done
if [ "$dir" = "/" -o -n "$partition" ]; then
break
else
dir=`dirname $dir`
fi
fi
done
[ "$partition" = "read-only" ] && echo "yes" || echo "no"
}
if [ "$1" = "start" ] ; then
if [ `is_on_read_only_partition /var/lib` = "yes" ]; then
grep -q "tmpfs /var/volatile" /proc/mounts || mount /var/volatile
mkdir -p /var/volatile/lib
cp -a /var/lib/* /var/volatile/lib
mount --bind /var/volatile/lib /var/lib
fi
fi
3.31 /etc/init.d/reboot
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
echo -n "Rebooting... "
reboot -d -f
3.32 /etc/init.d/rmnologin.sh
#!/bin/sh
if test -f /etc/nologin.boot
then
rm