CentOS 5和6的启动流程

栏目: 服务器 · 发布时间: 8年前

内容简介:CentOS 5和6的启动流程

Linux: kernel+rootfs

kernel: 进程管理、内存管理、网络管理、驱动程序、文件系统、安全功能

rootfs:

glibc

库:函数集合 , function, 调用接口

过程调用: procedure

函数调用: function

程序

内核设计流派:

单内核设计: Linux

把所有功能集成于同一个程序;

微内核设计: Windows, Solaris

每种功能使用一个单独子系统实现;

Linux 内核特点:

支持模块化: .ko

支持模块的动态装载和卸载;

组成部分:

核心文件: /boot/vmlinuz-VERSION-release

例一:内核的核心文件

[root@localhost lib]# ls /boot/
vmlinuz-3.10.0-514.el7.x86_64

ramdisk

CentOS 5: /boot/initrd-VERSION-release.img

CentOS 6: /boot/initramfs-VERSION-release.img

模块文件: /lib/modules/VERSION-release

例一:查看模块文件

[root@localhost lib]# ls /lib/modules/3.10.0-514.el7.x86_64/
build              modules.block        modules.devname      modules.softdep      vdso
extra              modules.builtin      modules.drm          modules.symbols      weak-updates
kernel             modules.builtin.bin  modules.modesetting  modules.symbols.bin
modules.alias      modules.dep          modules.networking   source
modules.alias.bin  modules.dep.bin      modules.order        updates 

CentOS 系统启动流程:  

POST :加电自检;

ROM CMOS

BIOS Basic Input and Output System

ROM+RAM

BOOT Sequence:

按次序查找各引导设备,第一个有引导程序的设备即为本次启动用到设备;

bootloader: 引导加载器,程序

windows: ntloader

Linux

LILO LInux LOader

GRUB: GRand Uniform Bootloader

GRUB 0.X: GRUB Legacy

GRUB 1.x: GRUB2

功能:提供一个菜单,允许用户选择要启动系统或不同的内核版本;把用户选定的内核装载到内存中的特定空间中,解压、展开,并把系统控制权移交给内核;

MBR:

446: bootloader

64: fat

2: 55AA

GRUB:

bootloader: 1st stage

disk: 2nd stage

kernel

自身初始化:

探测可识别到的所有硬件设备;

加载硬件驱动程序;(有可能会借助于 ramdisk 加载驱动)

以只读方式挂载根文件系统;

运行用户空间的第一个应用程序: /sbin/init 

init 程序的类型:

SysV: init, CentOS 5

配置文件: /etc/inittab 

Upstart: init, CentOS 6

配置文件: /etc/inittab, /etc/init/*.conf 

Systemd systemd, CentOS 7

配置文件: /usr/lib/systemd/system, /etc/systemd/system

例一:centos7 init 内核配置文件

[root@localhost ~]# ls /etc/systemd/system
basic.target.wants                                       display-manager.service
bluetooth.target.wants                                   getty.target.wants

例二:centos7 init 内核配置文件

[root@localhost ~]# ls /usr/lib/systemd/system
abrt-ccpp.service                        paths.target
abrtd.service                            plymouth-halt.service 

ramdisk  

内核中的特性之一:使用缓冲和缓存来回事对磁盘上的文件访问;

ramdisk –> ramfs

CentOS 5: initrd, 工具程序: mkinitrd

CentOS 6: initramfs , 工具程序: mkinitrd, dracut

系统初始化:

POST –> BootSequence (BIOS) –> Bootloader(MBR) –> kernel(ramdisk) –> rootfs( 只读 ) –> init

/sbin/init

CentOS 5:

运行级别:为了系统的运行或维护等应用目的而设定; 

0-6 7 个级别

0 :关机

1 :单用户模式 (root, 无须登录 ), single, 维护模式;

2: 多用户模式,会启动网络功能,但不会启动 NFS ;维护模式;

3 :多用户模式,正常模式;文本界面;

4 :预留级别;可同 3 级别;

5 :多用户模式,正常模式;图形界面;

6 :重启

默认级别:

3, 5

切换级别:

init #

查看级别:

runlevel

who -r

配置文件: /etc/inittab

每一行定义一种 action 以及与之对应的 process

id:runlevel:action:process

action:

wait: 切换至此级别运行一次;

respawn :此 process 终止,就重新启动之;

initdefault :设定默认运行级别; process 省略;

sysinit :设定系统初始化方式,此处一般为指定 /etc/rc.d/rc.sysinit

id:3:initdefault:

si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l6:6:wait:/etc/rc.d/rc 6

说明: rc 0 –> 意味着读取 /etc/rc.d/rc0.d/

K*: K##* ## 运行次序;数字越小,越先运行;数字越小的服务,通常为依赖到别的服务;

S*: S##* ## 运行次序;数字越小,越先运行;数字越小的服务,通常为被依赖到的服务;

for srv in /etc/rc.d/rc0.d/K*; do

$srv stop

done

for srv in /etc/rc.d/rc0.d/S*; do

$srv start

done

chkconfig 命令

查看服务在所有级别的启动或关闭设定情形:

chkconfig [–list] [name]

例一:查看所有服务

[root@localhost ~]# chkconfig --list 

例二:更改服务权限

[root@localhost ~]# chkconfig --level 3 network off

添加:

SysV 的服务脚本放置于 /etc/rc.d/init.d (/etc/init.d)

chkconfig –add name

#!/bin/bash

#

# chkconfig: LLLL nn nn

删除:

chkconfig –del name

修改指定的链接类型

chkconfig [–level levels] name <on|off|reset>

–level LLLL: 指定要设置的级别;省略时表示 2345

注意:正常级别下,最后启动一个服务 S99local 没有链接至 /etc/rc.d/init.d 一个服务脚本,而是指向了 /etc/rc.d/rc.local 脚本;因此,不便或不需写为服务脚本放置于 /etc/rc.d/init.d/ 目录,且又想开机时自动运行的命令,可直接放置于 /etc/rc.d/rc.local 文件中;

tty1:2345:respawn:/usr/sbin/mingetty tty1

tty2:2345:respawn:/usr/sbin/mingetty tty2

tty6:2345:respawn:/usr/sbin/mingetty tty6

mingetty会调用login程序

/etc/rc.d/rc.sysinit: 系统初始化脚本

(1) 设置主机名;

(2) 设置欢迎信息;

(3) 激活 udev selinux;

(4) 挂载 /etc/fstab 文件中定义的文件系统;

(5) 检测根文件系统,并以读写方式重新挂载根文件系统;

(6) 设置系统时钟;

(7) 激活 swap 设备;

(8) 根据 /etc/sysctl.conf 文件设置内核参数;

(9) 激活 lvm software raid 设备;

(10) 加载额外设备的驱动程序;

(11) 清理操作;

总结:/sbin/init –> (/etc/inittab) –> 设置默认运行级别 –> 运行系统初始脚本、完成系统初始化 –> 关闭对应下需要关闭的服务,启动需要启动服务 –> 设置登录终端

CentOS 6: 

init 程序为 : upstart, 其配置文件:

/etc/inittab, /etc/init/*.conf

注意: /etc/init/*.conf 文件语法 遵循 upstart 配置文件语法格式;

回顾:

CentOS 6启动流程:

POST –> Boot Sequence(BIOS) –> Boot Loader (MBR) –> Kernel(ramdisk) –> rootfs –> switchroot –> /sbin/init –>(/etc/inittab, /etc/init/*.conf) –> 设定默认运行级别 –> 系统初始化脚本 –> 关闭或启动对应级别下的服务 –> 启动终端


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Developing Large Web Applications

Developing Large Web Applications

Kyle Loudon / Yahoo Press / 2010-3-15 / USD 34.99

As web applications grow, so do the challenges. These applications need to live up to demanding performance requirements, and be reliable around the clock every day of the year. And they need to withs......一起来看看 《Developing Large Web Applications》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具