linux 系統啟動以後,執行指令碼的順序
阿新 • • 發佈:2018-11-28
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