linux 系统启动以后,执行脚本的顺序

1 首先是 rcS

#! /bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:.

# 挂载虚拟文件系统
echo "Mounting virtual filesystems"
mkdir -p /sys /proc /dev
mount -t proc proc /proc
mount -t sysfs sys /sys
if grep -qs debugfs /proc/filesystems; then
	mount -t debugfs debugfs /sys/kernel/debug
fi
if grep -qs configfs /proc/filesystems; then
	mount -t configfs none /sys/kernel/config
fi
grep -q devtmpfs /proc/mounts || mount -t devtmpfs none /dev
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mount -t tmpfs -o mode=01777 tmpfs /tmp
mkdir -p /dev/shm
mount -t tmpfs -o noexec,nosuid,nodev,mode=1777 shm /dev/shm

# 执行系统参数配置(网络参数设置,就是写到了这个文件里面)
if [ -e /etc/sysctl.conf ]; then
	for conf in /etc/sysctl.conf /etc/sysctl.d/*.conf; do
		if [ -r "$conf" ]; then
			sysctl -p "$conf" > /dev/null
		fi
	done
fi

echo "/sbin/stbhotplug" > /proc/sys/kernel/hotplug

if [ ! -z "$BASH_VERSION" ]; then
	# Recovery from missing /dev/console (works on bash but not ash)
	exec < /dev/console >& /dev/console
fi

# Don't let SCHED_FIFO / SCHED_RR realtime threads get preempted
echo -1 > /proc/sys/kernel/sched_rt_runtime_us

# By default, switch to conservative governor on SoCs with AVS CPUfreq only
cpufreq-info -d | grep 'brcm.*avs' >/dev/null
if [ $? = 0 ]; then
	# Check if system supports the conservative governor and enable it
	cpufreq-info -g | grep conservative >/dev/null
	if [ $? = 0 ]; then
		echo "Switching to conservative governor"
		cpufreq-set -g conservative
	fi
fi

# GPLv3 warning
if [ -e /bin/gdbserver -o -e /bin/gdb ]; then
	echo "* WARNING: THIS STB CONTAINS GPLv3 SOFTWARE"
	echo "* GPLv3 programs must be removed in order to enable security."
	echo "* See: http://www.gnu.org/licenses/gpl-faq.html#Tivoization"
fi

# -small configuration: do not start any other services automatically
if [ ! -e /bin/login ]; then
	[ -f /root/rc.user ] && sh /root/rc.user
	exit 0
fi

# Set up MoCA link, if present
[ -e /dev/bmoca0 ] && mocacfg boot &

cmdline=`cat /proc/cmdline`

if [[ "$cmdline" != *nfsroot=* ]]; then
	# Make sure ethX appear(s) first, which is relevant for DSA enabled
	# systems where ethX (conduit interface) needs to be brought up first
	# before all other DSA created network interfaces
	ifaces="$(ls /sys/class/net | grep eth) $(ls /sys/class/net | grep -v eth)"
	for x in $ifaces; do
	if [[ "$x" =~ ^eth* ]] || [[ $x =~ ^ra* ]] || [[ "$x" =~ ^wlan* ]] || [[ "$x" =~ ^lo* ]];then
		echo "Configuring $x interface"
		/sbin/ifup $x
        fi
	done
else
	# just configure loopback
	/sbin/ifup lo
fi

# Set up WLAN, if present
if [ -e /etc/wl/rtecdc.trx -a -x /bin/bcmdl ]; then
	bcmdl /etc/wl/rtecdc.trx
fi
[ -e /lib/modules/wl.ko ] && insmod /lib/modules/wl.ko

# rootfs on SATA hard disk (but not sda4-less thumbdrive)
if [ -e /dev/root -a "`readlink /dev/root`" = "sda1" -a -e /dev/sda4 ]; then
	mount -o remount,noatime,commit=1 /
	mount -a
	swapon -a
fi

echo "Starting network services"
portmap &

# 执行rc.user脚本
if [ -f /root/rc.user ]; then
	echo "Starting user services"
	/bin/sh /root/rc.user
fi

2 第二个脚本 /root/rc.user 

#! /bin/sh

# 创建这些目录
grep -q "tmpfs /var" /proc/mounts || mount -t tmpfs -o size=4M,mode=01777 tmpfs /var
mkdir -p /var/log
mkdir -p /var/run
mkdir -p /var/tmp
grep -q "tmpfs /mnt" /proc/mounts || mount -t tmpfs -o size=64k,mode=01777 tmpfs /mnt
mkdir -p /mnt/tnfs
mkdir -p /mnt/nfs

# 新建链接
# create the symlinks of flash partition layout
FLASH_PARTS_NAME=(partsinfo partsinfobak manufactory bootparam bootparambak nvram security securitybak splash fsikernel fsirootfs ssikernel ssirootfs hwcfg tnfs rwfs bsu boot system bootloader userdata)
FLASH_PARTS_NUM=${#FLASH_PARTS_NAME[*]}

mkdir -p /dev/block/by-name
for((i=0;i<${FLASH_PARTS_NUM};i=${i}+1))
do
    if [ -b "/dev/mmcblk0p$((i+1))" -a ! -e "/dev/block/by-name/${FLASH_PARTS_NAME[${i}]}" ]; then
        ln -s /dev/mmcblk0p$((i+1)) /dev/block/by-name/${FLASH_PARTS_NAME[${i}]}
    fi
done

# 执行env.sh
if [ -f "/etc/init.d/env.sh" ]; then
    source /etc/init.d/env.sh
fi

# 执行"S开头"的脚本
# 命令set的用法
# set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]
# 此处的 set start,是指 set [arg ...]
# The remaining n ARGs are positional parameters and are assigned, in order, to $1, $2, 
# .. $n.  If no ARGs are given, all shell variables are printed.(from man page)
#
#
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
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
	    )
	    ;;
	*)
	    # No sh extension, so fork subprocess.
	    $i start
	    ;;
    esac
done

3 env.sh 设置环境变量

# 设置环境变量
export PATH=$PATH:.:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/bin/wireless:/usr/local/bin/tcpdump:/usr/local/bin/curl:/usr/local/bin/dbus:/nano-lamp/usr/bin:/nano-lamp/usr/sbin:/usr/local/bin/netflix
export LD_LIBRARY_PATH=.:/usr/local/lib:$LD_LIBRARY_PATH

export SSH_ENABLE=Enable
export FTP_ENABLE=Enable
export IPTABLE_ENABLE=Disable
export TNODVB_ENABLE=Disable
export A42TK_ENABLE=Disable

export TNENV_APP_IFRAME_URL=/root/iframe/iframe.jpg
export TNENV_IMAGE_SIZE=1800
export dfb_evdev_rep_delay=1800
export dfb_evdev_rep_period=110

if [ -e "/usr/local/bin/sage/sage_bl.bin" ]; then 
    export SAGEBIN_PATH=/usr/local/bin/sage
fi

if [ -e /etc/settings/tv2next/3DTV.finger ]; then
    export TNENV_APP_3DTV_ENABLE=1
fi


export B_REFSW_BOXMODE=5


#QT4 settings
export QT_VERSION=4
export QWS_DISPLAY=directfb:width=1280:height=720:forcepremultiplied
export QT_PLUGIN_PATH=/usr/local/bin/Qt/plugins

if [ -e /root/fonts/qt/wqy-microhei.ttc ]; then
export QT_QWS_FONTDIR=/root/fonts/qt
export QT_QWS_FONTDIR=/root/fonts/qt
elif [ -e /webkit/fonts/wqy-microhei.ttc ]; then
export QT_QWS_FONTDIR=/webkit/fonts
else
export QT_QWS_FONTDIR=/opera/fonts
fi

export TNENV_APP_HDCP_RETRY_STATUS=1

export BLUETOOTH_ENABLE=Enable


export RF4CE_ENABLE=Enable
export RF4CE_EVAL_ENABLE=Enable
export RF_CHIP_NAME=GP502

4 执行 /etc/init.d 目录下的S*.sh脚本,以数字的大小顺序执行。

例如: 

S50_start_system_services.sh  

S60_start_nano_lamp.sh

猜你喜欢

转载自blog.csdn.net/yinming4u/article/details/84554260
今日推荐