linux系统启动
系统初始化 grub-->vmlinuz-2.6.18-194.e15--->initer-2.6.18-194.e15.img--->modules(模块)----->系统初始化完成------->默认进入runlevel
5
[root@localhost boot]# ls /boot/ config-2.6.18-194.el5 lost+found vmlinuz-2.6.18-194.el5 grub symvers-2.6.18-194.el5.gz initrd-2.6.18-194.el5.img System.map-2.6.18-194.el5
grub 所在位置
[root@localhost /]# ls /boot/grub device.map menu.lst---->grub.conf minix_stage1_5 stage2 e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5 fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5 ffs_stage1_5 stage1 xfs_stage1_5
模块所在位置
[root@localhost /]# ls /lib/modules 2.6.18-194.el5
initrd-2.6.18-194.el5.img文件展开
[root@localhost boot]# ls /boot/ #initrd-2.6.18-194.el5.img所在位置 config-2.6.18-194.el5 lost+found vmlinuz-2.6.18-194.el5 grub symvers-2.6.18-194.el5.gz initrd-2.6.18-194.el5.img System.map-2.6.18-194.el5
[root@localhost boot]# cp initrd-2.6.18-194.el5.img /opt/ #复制initrd-2.6.18-194.el5.img 到 /opt/目录下进行展开 [root@localhost boot]# cd /opt/ [root@localhost opt]# ls initrd-2.6.18-194.el5.img
[root@localhost opt]# file initrd-2.6.18-194.el5.img #查看initrd-2.6.18-194.el5.img 文件类型--->gzip压缩文件 initrd-2.6.18-194.el5.img: gzip compressed data, from Unix, last modified: Wed May 30 18:33:51 2018, max compression
[root@localhost opt]# mv initrd-2.6.18-194.el5.img initrd-2.6.18-194.el5.gz #转换为 .img---> .gz 文件类型 [root@localhost opt]# ls initrd-2.6.18-194.el5.gz [root@localhost opt]# gzip -d initrd-2.6.18-194.el5.gz #解压 .gz 文件 [root@localhost opt]# ls initrd-2.6.18-194.el5 [root@localhost opt]# file initrd-2.6.18-194.el5 initrd-2.6.18-194.el5: ASCII cpio archive (SVR4 with no CRC) [root@localhost opt]# cpio -id < initrd-2.6.18-194.el5 #cpio 命令 :存取归档包中的文件 13970 blocks [root@localhost opt]# ls bin dev etc init initrd-2.6.18-194.el5 lib proc sbin sys sysroot #类似一个小型linux文件系统 [root@localhost opt]# ls lib/ #所有命令模仿正常的linux文件系统目录体系 ata_piix.ko dm-mod.ko ext3.ko mptbase.ko scsi_mod.ko dm-log.ko dm-raid45.ko firmware mptscsih.ko scsi_transport_spi.ko dm-mem-cache.ko dm-region_hash.ko jbd.ko mptspi.ko sd_mod.ko dm-message.ko ehci-hcd.ko libata.ko ohci-hcd.ko uhci-hcd.ko
initrd-2.6.18-194.el5.img文件展开之后kernel才能读懂SATA里面的数据
kernel初始化完成之后,开始运行 /sbin/init (用户空间)程序,并读取配置文件--->/etc/inittab
/etc/inittab 配置文件解读
[root@localhost etc]# vim inittab # # inittab This file describes how the INIT process should set up # the system in a certain run-level. # # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> # 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 # 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:3:initdefault: 3 默认允许级别 # System initialization. si::sysinit:/etc/rc.d/rc.sysinit #sysinit 系统初始化脚本 l0:0:wait:/etc/rc.d/rc 0 #运行级别软连接对应报表 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 #运行级别软连接对应报表
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now #是否启用组合键来关机
# 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 #1-6个虚拟控制台 控制台脚本
2:2345:respawn:/sbin/mingetty tty2 respawn
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
#sysinit 系统初始化脚本 ----》 runlevel 5------》 /etc/rc.d/rc.local(管理员手工选择设置服务运行)
#sysinit 系统初始化脚本
#!/bin/bash # # /etc/rc.d/rc.sysinit - run once at boot time # # Taken in part from Miquel van Smoorenburg's bcheckrc. # HOSTNAME=`/bin/hostname` HOSTTYPE=`uname -m` unamer=`uname -r` set -m if [ -f /etc/sysconfig/network ]; then . /etc/sysconfig/network fi if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then HOSTNAME=localhost fi if [ ! -e /proc/mounts ]; then mount -n -t proc /proc /proc mount -n -t sysfs /sys /sys >/dev/null 2>&1 fi if [ ! -d /proc/bus/usb ]; then modprobe usbcore >/dev/null 2>&1 && mount -n -t usbfs /proc/bus/usb /proc/bus/usb else mount -n -t usbfs /proc/bus/usb /proc/bus/usb "/etc/rc.d/rc.sysinit" 980L, 27239C
id:3:initdefault: 3 默认允许级别通过软连接到对于的脚本,里面有相应开启或关闭的服务 运行级别解析:
[root@localhost etc]# ls /etc/rc.d #id 3 initdefault: 软链接到下面对于的 rc3.d脚本 init.d rc rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local
rc3.d运行级别解析 (服务是开启还是关闭): ---->下面服务运行的具体参数调用 ------> /etc/sysconfig
[root@localhost etc]# ls /etc/rc.d/rc3.d #K01dsmasq 解读: K:关闭 01:运行优先级 dnsmasq K01dnsmasq K85mdmpd S11auditd S28autofs K02avahi-dnsconfd K87multipathd S12restorecond S50hplip K02NetworkManager K88wpa_supplicant S12syslog S55sshd K05conman K89dund S13cpuspeed S56cups K05saslauthd K89netplugd S13irqbalance S56rawdevices K05wdaemon K89pand S13portmap S56xinetd K10psacct K89rdisc S14nfslock S80sendmail K20nfs K91capi S15mdmonitor S85gpm K24irda K99readahead_later S18rpcidmapd S90crond K35vncserver S00microcode_ctl S19rpcgssd S90xfs K35winbind S02lvm2-monitor S22messagebus S95anacron K50netconsole S04readahead_early S23setroubleshoot S95atd K69rpcsvcgssd S05kudzu S25bluetooth S97rhnsd K73ypbind S08ip6tables S25netfs S97yum-updatesd K74ipmi S08iptables S25pcscd S98avahi-daemon K74nscd S08mcstrans S26acpid S99firstboot K74ntpd S09isdn S26haldaemon S99local K80kdump S10network S26hidd S99smartd
/etc/rc.d/rc.local(管理员手工选择设置服务运行) /etc/rc.local ---->/etc/rc.d/tc.local 符号链接
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Stage1.5 提供开启时候菜单选择:配置文件地址: /boot/grub/menu.lst---->grub .conf 软链接:
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/sda2 # initrd /initrd-version.img #boot=/dev/sda default=0 #默认启动内核次序 timeout=5 #无操作倒计时 splashimage=(hd0,0)/grub/splash.xpm.gz #系统开机背景图片
------------------------------------------------------------》可在此处加入密码命令
# 命令生成:
#[root@localhost etc]# grub-md5-crypt
# Password:
# Retype password:
# $1$F.7Dt/$NUuam2VBuAfPzT0HBfiYw1 把此命令注析符#取消成为下面的命令脚本:
password --md5
hiddenmen #隐藏菜单 title Red Hat Enterprise Linux Server (2.6.18-194.el5) #每个title表示一个菜单选项的keinel | 下面自己DIY一个选择菜单项 root (hd0,0) (hd0 第1块硬盘 ,0 boot所在的分区) kernel /vmlinuz-2.6.18-194.el5 ro root(系统的根)=LABEL=/ 背景图片rhgb quiet 内核的路径 initrd /initrd-2.6.18-194.el5.img 虚拟文件系统路径 ~ ~ "menu.lst" 17L, 598C 1,1 全部
initrd /initrd-2.6.18-194.el5.img 虚拟文件系统路径