zoukankan      html  css  js  c++  java
  • linux系统初始化——文件系统初始化步骤


    linux文件系统初始化步骤


    System V init启动过程

    概括地讲,Linux/Unix系统一般有两种不同的初始化启动方式.
    1) BSD system init
    2) System V init
    大多数发行套件的Linux使用了与System V init相仿的init也就是Sys V init,它比传统的BSD system init更容易且更加灵活。

    System V init的主要思想是定义了不同的"运行级别(runlevel)"。通过配置文件/etc/inittab定义了系统引导时的运行级别, 进入或者切换到一个运行级别时做什么。每个运行级别对应于一个子目录/etc/rc.d/rcX.d。
    每个rcX.d目录中都是一些以S或K开头的文件链接。这些链接指向的脚本都 可以接收start和stop参数,S开头的链接会传入start参数,一般是开启一项服务,K会传入stop参数,一般是停止某服务。

    以下是一个大致的System V init过程:
    (1)init 过程执行的第一个脚本是 /etc/rc.d/rc.sysinit,它主要做在各个运行级别中进行初始化工作,包括: 启动交换分区;检查磁盘;设置主机名;检查并挂载文件系统;加载并初始化硬件模块.
    (2)执行缺省的运行级别模式。 这一步的内容主要在/etc/inittab中体现, inittab文件会告诉init进程要进入什么运行级别,以及在哪里可以找到该运行级别的配置文件.
    (3)执行/etc/rc.d/rc.local脚本文件。 这也是init过程中执行的最后一个脚本文件,所以用户可以在这个文件中添加一些需要在登录之前执行的命令.
    (4)执行/bin/login程序

    注意:
    System V init只是一种模式,每个系统初始化都有差异,但大体上不会相差太多。如busybox执行的第一个启动脚本就是/etc/init.d/rcS,而且不可以改变,与上面讲的不同。

    LFS文件系统初始化示例:
    inittab文件
    由下内容可以看出,最先执行的是/etc/rc.d/init.d/rc文件,给这个文件传入的参数是一个数字,rc会由传入的数字合成rcX.d目录的路径,然后执行其中的所有脚本链接。当然这只是一部分功能。
    # Begin /etc/inittab
    id:3:initdefault:
    si::sysinit:/etc/rc.d/init.d/rc sysinit #可以设定初始化脚本
    l0:0:wait:/etc/rc.d/init.d/rc 0
    l1:S1:wait:/etc/rc.d/init.d/rc 1
    l2:2:wait:/etc/rc.d/init.d/rc 2
    ...
    ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
    su:S016:once:/sbin/sulogin
    1:2345:respawn:/sbin/agetty tty1 9600
    2:2345:respawn:/sbin/agetty tty2 9600
    ...
    # End /etc/inittab


    etc目录结构
    只是一部分,有删减。
    .
    ├── fstab
    ├── inittab
    ├── inputrc
    ├── profile
    ├── rc.d
    │ ├── init.d
    │ │ ├── checkfs
    │ │ ├── cleanfs
    ...
    │ │ ├── modules
    │ │ ├── mountfs
    │ │ ├── mountkernfs
    │ │ ├── network
    │ │ ├── rc #when boot, run.
    │ │ ├── reboot
    ...
    │ ├── rc0.d
    │ │ ├── K80network -> ../init.d/network
    │ │ ├── K90sysklogd -> ../init.d/sysklogd
    │ │ ├── S60sendsignals -> ../init.d/sendsignals
    │ │ ├── S70mountfs -> ../init.d/mountfs
    │ │ ├── S80swap -> ../init.d/swap
    │ │ ├── S90localnet -> ../init.d/localnet
    │ │ └── S99halt -> ../init.d/halt
    │ ├── rc1.d
    │ │ ├── K80network -> ../init.d/network
    │ │ └── K90sysklogd -> ../init.d/sysklogd
    │ ├── rc2.d
    │ │ ├── K80network -> ../init.d/network
    │ │ └── K90sysklogd -> ../init.d/sysklogd
    │ ├── rc3.d
    │ │ ├── S10sysklogd -> ../init.d/sysklogd
    │ │ └── S20network -> ../init.d/network
    │ ├── rc4.d
    │ │ ├── S10sysklogd -> ../init.d/sysklogd
    │ │ └── S20network -> ../init.d/network
    │ ├── rc5.d
    │ │ ├── S10sysklogd -> ../init.d/sysklogd
    │ │ └── S20network -> ../init.d/network
    │ ├── rc6.d
    │ │ ├── K80network -> ../init.d/network
    │ │ ├── K90sysklogd -> ../init.d/sysklogd
    │ │ ├── S60sendsignals -> ../init.d/sendsignals
    │ │ ├── S70mountfs -> ../init.d/mountfs
    │ │ ├── S80swap -> ../init.d/swap
    │ │ ├── S90localnet -> ../init.d/localnet
    │ │ └── S99reboot -> ../init.d/reboot
    │ └── rcsysinit.d
    │ ├── S00mountkernfs -> ../init.d/mountkernfs
    │ ├── S02consolelog -> ../init.d/consolelog
    │ ├── S05modules -> ../init.d/modules
    ...
    ├── udev
    │ ├── rules.d
    │ │ └── 55-lfs.rules
    │ └── udev.conf
    └── vimrc

    network脚本

     1 #!/bin/sh
     2 
     3 . /etc/sysconfig/rc
     4 . ${rc_functions}
     5 . /etc/sysconfig/network
     6 
     7 case "${1}" in
     8 start)
     9 # Start all network interfaces
    10 for file in ${network_devices}/ifconfig.*
    11 do
    12 interface=${file##*/ifconfig.}
    13 
    14 # skip if $file is * (because nothing was found)
    15 if [ "${interface}" = "*" ]
    16 then
    17 continue
    18 fi
    19 
    20 IN_BOOT=1 ${network_devices}/ifup ${interface}
    21 done
    22 ;;
    23 
    24 stop)
    25 # Reverse list
    26 FILES=""
    27 for file in ${network_devices}/ifconfig.*
    28 do
    29 FILES="${file} ${FILES}"
    30 done
    31 
    32 # Stop all network interfaces
    33 for file in ${FILES}
    34 do
    35 interface=${file##*/ifconfig.}
    36 
    37 # skip if $file is * (because nothing was found)
    38 if [ "${interface}" = "*" ]
    39 then
    40 continue
    41 fi
    42 
    43 IN_BOOT=1 ${network_devices}/ifdown ${interface}
    44 done
    45 ;;
    46 
    47 restart)
    48 ${0} stop
    49 sleep 1
    50 ${0} start
    51 ;;
    52 
    53 *)
    54 echo "Usage: ${0} {start|stop|restart}"
    View Code

    exit 1

    ;;
    esac

    # End /etc/rc.d/init.d/network

  • 相关阅读:
    JQuery是继prototype之后又一个优秀的Javascript库
    IAsyncResult接口
    Asynchronous Programming Patterns
    操作数据库的时候,使用自带的DbProviderFactory类 (涉及抽象工厂和工厂方法)
    8.2.4对象之间的关系
    git squash 和 git rebase
    8.2.3多态性 第8章 面向对象编程简介
    github的使用教程
    第7章 调试和错误处理 7.1.1 VS中的调试
    markdown的语法说明
  • 原文地址:https://www.cnblogs.com/sun-frederick/p/4763438.html
Copyright © 2011-2022 走看看