linux系统启动

系统启动

  1. BIOS 加电自检
  2. BIOS 读取第0柱面、第0磁道、第一个扇区的MBR(主引导分区)。
    • MBR(512byte):包含引导程序(446byte)、分区信息(磁盘分区表DPT 64byte)、MBR结束位(2byte)
    • MBR由分区程序产生,Window的fdisk.exe,Linux的fdisk命令
    • 引导程序: RedHat,CentOS默认使用Grub作为引导程序,因Grub较大,所以一般MBR写入Grub地址
  3. 运行Grub (Grand Unified Bootloader)
    1. 根据配置文件,加载kernel镜像
    2. 运行第一个程序/sbin/init
      • 根据etc/inittab初始化工作
      • 确定系统runlevel 默认id:3:initdefault
  4. 运行/etc/rc.sysinit脚本
    • 根据/etc/inittab 定义的系统初始化配置 si::sysinit:/etc/rc.d/rc.sysinit执行/etc/rc.sysinit脚本
    • 设置 系统变量、网络配置
    • 启动 swap
    • 设定 /proc
    • 加载 用户自定义模块、内核设置
  5. 运行服务 如runlevel 3则运行/etc/rc3.d目录下所有脚本
    • 根据runlevel *运行 /etc/rc*.d
  6. 运行/etc/rc.local
  7. 生成终端或 X WINDOW
runlevel

/etc/inittab设定的runlevel (ubuntu 不用这个文件,但其他机制差不多)
0. 关机

  1. 单用户
    • 出现问题时进入维护。忘记root,进入此模式修改root秘密
  2. 多用户
    • 无网络
  3. 完全多用户
    • 默认,linux服务器最常见模式
  4. 保留未使用
  5. 窗口模式,支持多用户,支持网络
  6. 重启
$ ls -all /etc | grep "rc"
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc0.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc1.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc2.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc3.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc4.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc5.d
drwxr-xr-x   2 root root    4096 9月  27 11:33 rc6.d
drwxr-xr-x   2 root root    4096 9月   7 14:56 rcS.d

/etc/rc*.d下脚本

先运行S开头脚本(start启动服务),在运行K开头脚本(kill停止服务)

albertsnow@albertsnow-OptiPlex-5050:~$ ls  -all /etc/rc3.d
total 16
drwxr-xr-x   2 root root  4096 9月  27 11:33 .
drwxr-xr-x 132 root root 12288 11月 23 06:29 ..
lrwxrwxrwx   1 root root    15 9月   7 14:49 S01acpid -> ../init.d/acpid
lrwxrwxrwx   1 root root    17 9月   7 14:49 S01anacron -> ../init.d/anacron
lrwxrwxrwx   1 root root    16 9月   7 14:49 S01apport -> ../init.d/apport
lrwxrwxrwx   1 root root    22 9月   7 14:49 S01avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx   1 root root    19 9月   7 14:49 S01bluetooth -> ../init.d/bluetooth
lrwxrwxrwx   1 root root    26 9月   7 14:49 S01console-setup.sh -> ../init.d/console-setup.sh
lrwxrwxrwx   1 root root    14 9月   7 14:49 S01cron -> ../init.d/cron
lrwxrwxrwx   1 root root    14 9月   7 14:49 S01cups -> ../init.d/cups
lrwxrwxrwx   1 root root    22 9月   7 14:49 S01cups-browsed -> ../init.d/cups-browsed
lrwxrwxrwx   1 root root    14 9月   7 14:49 S01dbus -> ../init.d/dbus
lrwxrwxrwx   1 root root    14 9月   7 14:49 S01gdm3 -> ../init.d/gdm3
lrwxrwxrwx   1 root root    21 9月   7 14:49 S01grub-common -> ../init.d/grub-common
lrwxrwxrwx   1 root root    20 9月   7 14:49 S01irqbalance -> ../init.d/irqbalance
lrwxrwxrwx   1 root root    20 9月   7 14:49 S01kerneloops -> ../init.d/kerneloops
lrwxrwxrwx   1 root root    18 9月   7 14:49 S01plymouth -> ../init.d/plymouth
lrwxrwxrwx   1 root root    15 9月   7 14:49 S01rsync -> ../init.d/rsync
lrwxrwxrwx   1 root root    17 9月   7 14:49 S01rsyslog -> ../init.d/rsyslog
lrwxrwxrwx   1 root root    15 9月   7 14:49 S01saned -> ../init.d/saned
lrwxrwxrwx   1 root root    27 9月   7 14:49 S01speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx   1 root root    23 9月   7 14:49 S01spice-vdagent -> ../init.d/spice-vdagent
lrwxrwxrwx   1 root root    29 9月   7 14:49 S01unattended-upgrades -> ../init.d/unattended-upgrades
lrwxrwxrwx   1 root root    15 9月   7 14:49 S01uuidd -> ../init.d/uuidd
lrwxrwxrwx   1 root root    16 9月  27 11:33 S01vsftpd -> ../init.d/vsftpd
lrwxrwxrwx   1 root root    18 9月   7 14:49 S01whoopsie -> ../init.d/whoopsie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值