linux 引导流程



硬件时钟:hwclock  - - hctosys (用硬件时间同步系统时间) - - systohc
软件时钟:data
linux 引导流程 :
1.固件firmware(CMOS/BIOS)  (POST加电自检)
2.自举程序BootLoader(GRUB 配置文件在 /etc/grub.conf中 /boot/grub/grub.conf)  (载入内核 保存于MBR中)  ( windows的内核配置文件在 c盘下 ntldr文件中 boot.ini)
////////////////////////////////////////////////////////
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/sda1  
#          initrd /boot/initrd-version.img
#boot=/dev/sda
default=0//启动哪个title的系统,定义缺省启动的系统
timeout=5//缺省启动的时间
splashimage=(hd0,0)/boot/grub/splash.xpm.gz//定义启动界面图片 (hd0,0 表示第一块硬盘的第一个分区)
hiddenmenu//隐藏菜单,如果删掉则不会倒数计数而直接进入菜单
title CentOS (2.6.18-128.el5) //title可以随便更改
        root (hd0,0)//内核的存放位置
        kernel /boot/vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet//(/boot/vmlinuz-version内核的可执行文件version 2.6.18 中间位置6如果为基数则为测试版)ro表示只读
        initrd /boot/initrd-2.6.18-128.el5.img//载入镜像文件

////////////////////////////////////////////////////////


3.载入内核Kernel   (驱动硬件 内核中绝大部分都是驱动程序)
4.启动进程init  启动后读取inittab文件,执行缺省运行级别, init是第一个可以存在的进程pid恒为1,它也必须想一个更高级别的功能负责:pid为0的内核调度器(负责cpu分配,

时间片切换)
5.读取执行配置文件/etc/inittab

#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, <[email protected]>
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:运行级别
#   0 - halt (Do NOT set initdefault to this) 关机
#   1 - Single user mode 单用户模式 只有root可以登录,无图形界面
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)无法实现文件共享,较少用
#   3 - Full multiuser mode 完整多用户模式,无图形界面
#   4 - unused
#   5 - X11                             xwindow版本
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault: //缺省运行界别 会到/etc/rc.d/rcN.d读取配置

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit  //任何运行级别都会云新

l0:0:wait:/etc/rc.d/rc 0   //id:run-levels:action(指定运行状态):process(要运行的脚本)
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now//快捷键 ctrl+alt+del 关机

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1 //respawn一但process命令中止便重新运行该命令
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
///////////////////////////////////////////////
查看当前运行界别:runlevel
切换当前运行级别:init 0123456Ss



设置启动运行:
1.建立脚本文件
2.增加x权限 chmod u+x 脚本文件
3.设置软链接 ln -s 脚本文件  /etc/rc.d/rcN.d/S100msg.script

查看自启动
chkconfig - - list
chkconfig - - levels on/off/...
dmesg 查看启动的一些信息
/var/log/messages  



忘记密码的修改过程:
进入grub菜单
kernel /boot/vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet光标移到该行,进行编辑在该行后空格加上相应的运行级别即可
passwd 用户名
输入密码
 
给grub加密码:
获得密码 grub-md5-crypt
在grub.config 的title行上面
password - -md5 密码


grub出错修复:
cat /grub/grub.conf查看错误
进入grub命令行逐行输入.......

猜你喜欢

转载自snailxr.iteye.com/blog/1185991