首页 > 系统相关 >《Shell脚本实例 —— linux rcs启动脚本添加》

《Shell脚本实例 —— linux rcs启动脚本添加》

时间:2022-11-18 15:26:15浏览次数:68  
标签:脚本 Shell lib EMMC rcs start BLK echo insmod

linuxrc(bin/busybox) --> etc/inittab --> etc/init.d/rcS --> etc/init.d/Sxx

 

linuxrc是指向busybox的软连接

 

开机自动执行脚本或命令:

1. 写一个脚本,然后放到etc/inittab

2. 写一个脚本,然后放到etc/init.d/rcS

3. 写一个Sxx开头的脚本,放到etc/init.d/

4. 直接将命令添加到etc/inittab 或 etc/init.d/rcS

 

/etc/profile和/etc/profile.d/

/etc/profile文件只在登陆用户后,才会执行。并且每个用户登陆,都会进行一次。因此,可在这里设置一些用户日常操作所需的环境变量,就省得每次开机登陆都需要设置了。那么对于想开机自启动的任务就不要放这边了,因为用户一旦没登陆,任务也就不会自动启动了。

 

实例:

1.rcS

#!/bin/sh


# 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

2.S04tb_sound

#!/bin/sh
#

case "$1" in
    start)
    {
        insmod /lib/modules/soundcore.ko
        insmod /lib/modules/snd.ko
        insmod /lib/modules/snd-timer.ko
        insmod /lib/modules/snd-pcm.ko
        insmod /lib/modules/snd-pcm-dmaengine.ko
        insmod /lib/modules/snd-soc-core.ko
        insmod /lib/modules/snd-soc-dummy-codec.ko
        insmod /lib/modules/snd-soc-es8311.ko
        insmod /lib/modules/snd-soc-rockchip-pcm.ko
        insmod /lib/modules/snd-soc-rockchip-i2s-tdm.ko
        insmod /lib/modules/snd-soc-simple-card-utils.ko
        insmod /lib/modules/snd-soc-simple-card.ko

    }&
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac

exit 0

 

3.S05NPU_init

#!/bin/sh

case "$1" in
    start)
        printf "insmod NPU modules: "
        cp /usr/lib/cl_*.h /tmp/
        insmod /lib/modules/galcore.ko contiguousSize=0x400000
        unset MAX_FREQ
        read  MAX_FREQ < /sys/class/devfreq/ffbc0000.npu/max_freq
        echo  $MAX_FREQ > /sys/class/devfreq/ffbc0000.npu/userspace/set_freq
        [ $? = 0 ] && echo "OK" || echo "FAIL"
#start_rknn.sh &
        ;;
    stop)
        ;;
    restart|reload)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
exit 0

 

4.S06Lunch

#!/bin/sh
#

lunch_start()
{
    echo "Now we are ready to start your first application" > /dev/kmsg
    run_yd_first_lunch &
}

lunch_stop()
{
    echo "All applications have been stopped"
}

case "$1" in
    start)
        lunch_start
        ;;
    stop)
        lunch_stop
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac

exit 0

 

5.S07mountall

#!/bin/sh

# Uncomment below to see more logs
#set -x

mount_start()
{
    cnt=0
    while [ 1 ]
    do
        EMMC_BLK=`find /sys/block/ -name mmcblk*boot0 | cut -d '/' -f 4 | cut -c 1-7`
        if [ ! -z $EMMC_BLK ]; then
            break
        fi
        if [ $cnt -gt 10 ]; then
            break
        fi
        let cnt+=1
        echo "EMMC_BLK is null, wait 100ms, cnt is $cnt"
        sleep .1
    done
    EMMC_PARTITIONS=`find /sys/class/block/ -name ${EMMC_BLK}"p*" | wc -l`

    for i in $(seq 1 $EMMC_PARTITIONS)
    do
        part_name=`cat /sys/class/block/${EMMC_BLK}"p"${i}/uevent | grep PARTNAME | cut -d '=' -f 2`

        if [[ ${part_name}  == "userdata" ]]; then
            {
                resize2fs /dev/${EMMC_BLK}"p"${i}
                time e2fsck -fy /dev/${EMMC_BLK}"p"${i}
                #mountret=`mount /dev/${EMMC_BLK}"p"${i} /userdata`
                mount /dev/${EMMC_BLK}"p"${i} /userdata
                mountret=$?
                echo "--------mountret:${mountret}--------------------\n"
                if [ -f "/userdata/format_flag" ] || [ $mountret -ne 0 ]; then
                    echo "start format userdata"
                    umount /userdata/
                    mkfs.ext4 -F /dev/${EMMC_BLK}"p"${i}
                    mount /dev/${EMMC_BLK}"p"${i} /userdata
                fi
                /etc/init.d/swap_test &
                /system/bin/run_yd_second_lunch &
            }&
        elif [[ ${part_name}  == "system" ]]; then
            {
                #resize2fs /dev/${EMMC_BLK}"p"${i}
                mount /dev/${EMMC_BLK}"p"${i} /system
            }&
        elif [[ ${part_name}  == "security" ]]; then
            {
                resize2fs /dev/${EMMC_BLK}"p"${i}
                mount /dev/${EMMC_BLK}"p"${i} /conf
                mount_conf_ret=$?
                echo "--------mount_conf_ret:${mount_conf_ret}-----------\n"
                if [ $mount_conf_ret -ne 0 ]; then
                    echo "start format conf"
                    umount /conf/
                    mkfs.ext4 -F /dev/${EMMC_BLK}"p"${i}
                    mount /dev/${EMMC_BLK}"p"${i} /conf
                fi
            }&
        fi
    done
}

case "$1" in
    start)
        mount_start &
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac

 

标签:脚本,Shell,lib,EMMC,rcs,start,BLK,echo,insmod
From: https://www.cnblogs.com/zhuangquan/p/16903326.html

相关文章