zoukankan      html  css  js  c++  java
  • 18.14 构建Linux根文件系统

    18.14.1 Busybox1.7.0之init程序分析

           1.读取配置文件

           2.解析配置文件

           3.执行用户程序(根据配置文件中指定的内容)

    配置文件:

           1.指定应用程序

           2.何时执行

    busybox ->
        init.c ->init_main()
            ->parse_inittab()
                ->fopen(INITTAB, "r");//打开配置文件/etc/inittab 
                ->new_init_action()
                  new_init_action(int action, const char *command, const char *cons)
    

    eg. new_init_action(ASKFIRST, bb_default_login_shell, VC_2);

                         1.创建一个结构体,填充

                         2.把init_action放入init_action_list链表

            ->run_actions(SYSINIT);
                ->waitfor(a, 0);    //等待应用程序运行完毕
                    ->run(a);//创建一个子进程
                    ->waitpid(runpid, &status, 0);
                ->delete_init_action(a);    //在init_action_list列表里删除该进程
            ->run_actions(WAIT);
            ->run_actions(ONCE);
                ->run(a);delete_init_action(a);
            while (1) {
                run_actions(RESPAWN);
                run_actions(ASKFIRST);
                    ->if(a->pid == 0)
                        {    a->pid = run(a);}
                        print "Please press Enter to acticve this console"
                        wait Enter
                wpid = wait(NULL);/*Wait for a child process to exit*/
                while (wpid > 0) {
                            a->pid = 0;    //退出后设置pid为0
                }

    在busybox-1.7.0usybox-1.7.0examplesinittab中:

        # Format<id>:<runlevels>:<action>:<process>
        # <id>: appended to "/dev/" and used as-is.
        用作标注输入输出终端:sdtin stdout stderr printf err scanf
      //创建以下两个文件   
     
    /dev/console /dev/null # <runlevels>: The runlevels field is completely ignored. #<action>: Valid actions include:sysinit, respawn, askfirst, wait, once,restart, ctrlaltdel, and shutdown.

    从默认的配置文件中反推出默认的配置文件:

        ::ctrlaltdel:reboot
        ::shutdown:umount -a -r
        ::restart:init
        ::askfirst:/bin/sh
        /dev/tty2:askfirst:/bin/sh
        /dev/tty3:askfirst:/bin/sh
        /dev/tty4:askfirst:/bin/sh
        ::sysinit:/etc/init.d/rcS    

    最小根文件系统:

           1./dev/console /dev/null

           2.init ->busybox

           3./etc/inittab

           4.配置文件指定的应用程序

           5.应用程序需要的库(C库)

    18.14.2 移植自己修改的根文件系统执行ifconfig没反应

    在etc/init.d/rcS内增加一行代码

    01 #!/bin/sh
    02 ifconfig eth0 10.3.10.233

    第1行表示这是一个脚本文件,运行时使用/bin/sh解析;

    第2行用来配置IP地址为10.3.10.233;

    【本人学习IP如下:

      Windows IP:10.3.10.230

      U-Boot IP:10.3.10.231

      Linux主机IP(服务器):10.3.10.232

      板载Linux IP:10.3.10.233


  • 相关阅读:
    Centeos7搭建selenium+Chrome浏览器
    数据结构学习篇之栈和队列
    数据结构学习篇之线性表
    Tornado基础学习篇
    Python控制函数运行时间
    python线程实现异步任务
    Python实现几种简单的排序算法
    python爬虫遇到会话存储sessionStorage
    Python 有哪些优雅的代码实现让自己的代码更pythonic?
    Ubuntu查看端口使用情况,使用netstat命令:
  • 原文地址:https://www.cnblogs.com/baixu/p/10481329.html
Copyright © 2011-2022 走看看