系统引导流程相关知识

来源:互联网 发布:金万维免费域名 编辑:程序博客网 时间:2024/06/05 11:13

系统引导流程

固件Firmware(CMOS或BIOS)[用于POST加电自检]->自举程序BootLoader(GRUB)[用于载入内核]->载入内核Kernel[用于驱动硬件]->启动进程init->读取执行配置文件/etc/inittab


固件设置范围与举例

范围:包含引导介质列表.引导介质的搜索顺序.启动过程细节.电源管理.安全设置

举例:date和hwclock的应用[date 系统时钟 hwclock 硬件时钟]

hwclock的用法:

用法:
hwclock [功能] [选项...]

功能:
-h, --help 显示此帮助并退出
-r, --show 读取硬件时钟并打印结果
--set 将 RTC 设置为 --date 指定的时间
-s, --hctosys 从硬件时钟设置系统时间
-w, --systohc 从当前系统时间设置硬件时钟

--systz 基于当前时区设置系统时间
--adjust 根据自上次时钟设置或调整后的系统漂移
来调整 RTC
-c, --compare 定期将系统时钟与 CMOS 时钟相比较
--getepoch 打印内核的硬件时钟纪元(epoch)值
--setepoch 将内核的硬件时钟纪元(epoch)值设置为
--epoch 选项指定的值
--predict 预测 --date 选项所指定时刻读取到的 RTC 值
-V, --version 显示版本信息并退出

选项:
-u, --utc 硬件时钟保持为 UTC 时间
--localtime 硬件时钟保持为本地时间
-f, --rtc <文件> 代替默认文件的特殊 /dev/... 文件
--directisa 直接访问 ISA 总线,而非 /dev/rtc
--badyear 忽略 RTC 年份(由于 BIOS 损坏)
--date <时间> 指定要设置的硬件时钟时间
--epoch <年> 指定作为硬件纪元(epoch)值起始的年份
--noadjfile 不访问 /etc/adjtime;需要使用 --utc 或 --localtime 选项
--adjfile <文件> 指定调整文件的路径;
默认为 /etc/adjtime
--test 不更新,只显示将进行什么操作
-D, --debug 调试模式


MBR:Master Boot Record-主引导记录的简称,包含Bootloader,PartitionTable和Magic Number三部分,Partition又分为:Partition Flag,Start CHS,Partition byte,End CHS,Start LBA和Size.


内核:

[root@localhost Desktop]# ls -l /boot/vmlinuz-2.6.32-358.el6.x86_64 
-rwxr-xr-x. 1 root root 4044560 Jan 29  2013 /boot/vmlinuz-2.6.32-358.el6.x86_64


init的工作原理:

init启动后读取inittab文件,执行缺省的运行级别,从而继续引导过程.在UNIX系统里面,init是第一个可以存在的进程,其PID恒为1,但它必须为一个更高级的PID为0的内核调度器(kernel scheduler)负责,从而获取CPU时间.

[root@localhost Desktop]# ps -le | moreF S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD4 S     0      1      0  0  80   0 -  4839 poll_s ?        00:00:01 init1 S     0      2      0  0  80   0 -     0 kthrea ?        00:00:00 kthreadd1 S     0      3      2  0 -40   - -     0 migrat ?        00:00:00 migration/0


运行级别的切换:

[root@localhost ~]# runlevel3 5
前面的3代表先前的level

后面的5代表当前的level

[root@localhost ~]# init 3

inittab文件解析:(下面是/etc/initab文件的部分内容)

------------------------------------------------------------------------

# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)

id:5:initdefault:

-------------------------------------------------------------------------
在inittab中,所有条目的格式为:

id:run-levels:action:process

id:标识符,一般为两位字母或数字

run-levels:指定运行级别,可指定多个

action:指定运行状态

process:指定要运行的脚本/命令

action常用取值:

initdefault:指定系统缺省启动的运行级别

sysinit:系统启动执行process中指定的命令

wait:执行process指定的命令,等待其结束再运行其他命令

once:执行process指定的命令,不等待其结束

ctrlaltdel:按下该组合键时执行process指定的命令

powerfail:当出现电源错误时执行process指定的命令,不等待其结束

powerokwait:当电源恢复时执行process指定的命令

respawn:一旦process指定的命令终止,重新运行该命令.

举例说明:

id:5:initdefault:

代表指定系统默认级别是5-X Window,如想启动后自动运行Full multiuser mode,将上面的5改成3即可.


启动process指定的脚本命令/etc/rc.d/rc.sysinit,完成系统的服务程序启动,如系统环境变量设置.系统时钟设置.加载字体.检查加载文件系统.生成系统信息日志文件等.


判断默认运行级别,调用/etc/rc.d/rc脚本,执行相应运行级别目录中的服务程序,完成相应运行级别的初始化设置.


[root@localhost ~]# /etc/rc.d/init.d/ntpd startStarting ntpd:                                             [  OK  ][root@localhost ~]# /etc/rc.d/init.d/ntpd stopShutting down ntpd:                                        [  OK  ][root@localhost ~]# /etc/rc.d/init.d/ntpd Usage: /etc/rc.d/init.d/ntpd {start|stop|status|restart|try-restart|force-reload}


/etc/rc.d/rc[0123456].d

分别存放对应于运行级别的服务程序脚本的符号链接,链接到init.d目录中的相应脚本.



设置自启动程序

ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)

ln [OPTION]... TARGET... DIRECTORY     (3rd form)

option: 

-s, --symbolic              make symbolic links instead of hard links

-P, --physical              make hard links directly to symbolic links


chkconfig


ntsysv


运行dmesg检查系统引导期间的错误

该命令相关解释:

NAME
dmesg - print or control the kernel ring buffer


SYNOPSIS
dmesg [-c] [-r] [-n level] [-s bufsize]


DESCRIPTION
dmesg is used to examine or control the kernel ring buffer.


The program helps users to print out their bootup messages. Instead of copying
the messages by hand, the user need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.


检查系统日志 /var/log/messages,查找可能被dmesg忽略的应用程序错误


1 0
原创粉丝点击