Linux-启动过程

    技术2022-05-20  34

    FAEporting好的linux提供,几乎都在写应用代码,空闲时间整理一下B1202系统启动的过程

    通过/boot/vm进行启动 vmlinuz

    init进程会读取    /etc/inittab/etc/inittab/etc/rc.d/rc.sysinit,再/etc/rc.d/rc3.d/ 等等 

    启动login登录界面 login

    在用户登录的时候执行sh脚本的顺序:每次登录的时候都会完全执行的

      /etc/profile.d/file

      /etc/profile

      /root/.bashrc

      /root/.profile

    1.        init

    读内核代码

    init/main.c

    -->kernel_init

     

    if (!ramdisk_execute_command)

            ramdisk_execute_command = "/init";

    B1202

    init -> bin/busybox

    init只是一个busybox的快捷方式,busybox程序中调/etc/inittab脚本,

    如果没有busybox就按照inittab走,有busybox就先运行busybox,最后会调/etc/inittab

     

    2.        /etc/inittab内容

    /etc/inittab会调用/etc/rc.d/rcS/bin/login

    # see busybox-1.00rc2/examples/inittab for more examples

    ::sysinit:/etc/rc.d/rcS

    #::respawn:-/bin/sh

    ::respawn:/bin/login

    ::ctrlaltdel:/sbin/reboot

    ::shutdown:/etc/rc.d/rcS stop

    ::shutdown:/bin/umount -a -r

    ::shutdown:/sbin/swapoff -a

    ::restart:/sbin/init

     

     

    /etc/rc.d/rc.conf

     

    cfg_services="hostname mount-proc mountrd devfsd devpts syslog networking portmap upgrade.sh nfs-kernel-server inetd start_apps"

     

    /etc/rc.d/rcS根据/etc/rc.d/rc.conf的配置

    /etc/rc.d/init.d/$i这行的意思就是逐个加载这些脚本的

    可以看到syslog这个脚本,就是打印调试用的,由busybox的提供的

    start_apps这个脚本是加载驱动,应用,防火墙,FE基本配置等等

     

    #!/bin/sh

    . /etc/rc.d/rc.conf

    mode=${1:-start}

    if [ $mode = "start" ]

    then

        services=$cfg_services

    else

        services=$cfg_services_r

    fi

    cfg_services=${2:-$services}

     

    # run the configured sequence

    for i in $cfg_services

    do

        if [ -x /etc/rc.d/init.d/$i ]

        then                                                                       

            /etc/rc.d/init.d/$i $mode

        fi                                                                          

    done

     

    if [ $# -ge 2 ]

    then

        exit 0

    fi

    if [ -x /etc/rc.d/rc.local ]

    then

        /etc/rc.d/rc.local

    fi

    /bin/login就是登陆程序

     

    3.        进程线程

    用进程还是线程,这个个人觉得按功能来分M个进程,关系紧密的N个模块起N个线程放一个进程中,M个进程之间最好通信单一,B1202就是这样来实现的

     

    4.        分块详解

     


    最新回复(0)