linux学习笔记-开机启动过程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux学习笔记-开机启动过程相关的知识,希望对你有一定的参考价值。
linux系统开机过程
第1步 加电自检
给服务器通电后,主板上的Bios芯片会对各个硬件进行检查。检查完硬件没有问题之后,才会把开机任务交给下一步。
第2步 MBR引导
BIOS自检完成之后,随即将开机任务交给MBR引导程序。MBR引导程序会去读取默认启动项硬盘的0柱面0磁道1扇区的前446字节(后面的66字节存放的是硬盘的分区表以及分区的结束标志),最终加载grub菜单。
第3步 加载GRUB引导菜单
grub菜单的实际存放路径为/boot/grub/grub.conf,里面配置了内核等基本信息
[[email protected] ~]# ls -l /etc/grub.conf #<==可以看到/etc下面的grub是一个软链接文件 lrwxrwxrwx. 1 root root 22 Jul 3 2016 /etc/grub.conf -> ../boot/grub/grub.conf [[email protected] ~]# ls -l /boot/grub/grub.conf -rw-------. 1 root root 819 Jul 3 2016 /boot/grub/grub.conf [[email protected] ~]# cat /boot/grub/grub.conf #<==查看grub的内容 # 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/mapper/VolGroup-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/sda #<==这里说明了分区所在位置 default=0 #<==菜单项0表示第一项,如果是多系统可以修改此选项 timeout=5 #<==在菜单到自动启动系统前的停留时间,单位为sec,可按需分配 splashimage=(hd0,0)/grub/splash.xpm.gz #<==启动菜单的背景图标 hiddenmenu title CentOS (2.6.32-431.el6.x86_64) #<==启动项目名称,可随意修改 root (hd0,0) #<==root所在的位置,hd0,0参考磁盘在linux下的命名与定义 kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=128M rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-431.el6.x86_64.img #<==内核的具体参数配置等
第4步 加载内核kernel
根据grub.conf里面的配置,系统会去加载内核程序。完成内核引号之后,会首先运行启动进程号为1的INIT进程
第5步 启动init进程
[[email protected] ~]# ps -ef |grep init root 1 0 0 06:14 ? 00:00:00 /sbin/init
第6步 读取inittab配置文件
1)启动init进程时,首先会读/etc/inittab配置文件
[[email protected] ~]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # 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:3:initdefault: #<==定义系统启动时的runlevel级别
2)读取/etc/rc.d/rc.sysinit脚本
配置文件定义了主机名,selinux服务,sync,device mapper....等等一系列的服务。
# /etc/rc.d/rc.sysinit - run once at boot time # # Taken in part from Miquel van Smoorenburg‘s bcheckrc.
3)读取/etc/rc.d/rc脚本
确定当前默认的开机运行级别所需运行的配置
# rc This file is responsible for starting/stopping # services when the runlevel changes.
4)运行对应运行级别下的程序/etc/rc3.d/
该目录下面的文件均为软链接文件,对应各自服务的启动脚本,和chkconfig原理相关。
[[email protected] rc3.d]# ls -lih /etc/rc3.d/ total 0 136917 lrwxrwxrwx. 1 root root 16 Aug 2 07:14 K01smartd -> ../init.d/smartd 136962 lrwxrwxrwx 1 root root 13 Sep 14 23:55 K05atd -> ../init.d/atd 136988 lrwxrwxrwx. 1 root root 16 Aug 2 07:14 K10psacct -> ../init.d/psacct 136180 lrwxrwxrwx. 1 root root 19 Aug 2 07:14 K10saslauthd -> ../init.d/saslauthd 137309 lrwxrwxrwx 1 root root 22 Sep 17 10:32 K15htcacheclean -> ../init.d/htcacheclean 137302 lrwxrwxrwx 1 root root 15 Sep 17 10:32 K15httpd -> ../init.d/httpd 136927 lrwxrwxrwx. 1 root root 18 Aug 2 07:14 K15svnserve -> ../init.d/svnserve 135882 lrwxrwxrwx 1 root root 19 Sep 14 23:55 K16abrt-ccpp -> ../init.d/abrt-ccpp 135866 lrwxrwxrwx 1 root root 15 Sep 14 23:55 K16abrtd -> ../init.d/abrtd 136200 lrwxrwxrwx 1 root root 17 Sep 14 23:55 K30postfix -> ../init.d/postfix 136095 lrwxrwxrwx. 1 root root 20 Aug 2 07:14 K50netconsole -> ../init.d/netconsole 136882 lrwxrwxrwx 1 root root 15 Sep 14 23:55 K74acpid -> ../init.d/acpid 136129 lrwxrwxrwx 1 root root 19 Sep 14 23:55 K74haldaemon -> ../init.d/haldaemon 136783 lrwxrwxrwx 1 root root 14 Sep 14 02:53 K74ntpd -> ../init.d/ntpd 136827 lrwxrwxrwx 1 root root 26 Sep 14 23:55 K75blk-availability -> ../init.d/blk-availability 136081 lrwxrwxrwx 1 root root 15 Sep 14 23:55 K75netfs -> ../init.d/netfs 136170 lrwxrwxrwx 1 root root 17 Sep 14 02:53 K75ntpdate -> ../init.d/ntpdate 136868 lrwxrwxrwx. 1 root root 19 Aug 2 07:14 K75quota_nld -> ../init.d/quota_nld 136105 lrwxrwxrwx 1 root root 19 Sep 14 23:55 K75udev-post -> ../init.d/udev-post 136805 lrwxrwxrwx 1 root root 15 Sep 14 23:55 K80kdump -> ../init.d/kdump 136140 lrwxrwxrwx 1 root root 19 Sep 14 23:55 K85mdmonitor -> ../init.d/mdmonitor 130669 lrwxrwxrwx 1 root root 20 Sep 14 23:55 K85messagebus -> ../init.d/messagebus 136442 lrwxrwxrwx 1 root root 20 Sep 14 23:55 K87irqbalance -> ../init.d/irqbalance 135928 lrwxrwxrwx. 1 root root 21 Aug 2 07:14 K87restorecond -> ../init.d/restorecond 136979 lrwxrwxrwx 1 root root 16 Sep 14 23:55 K88auditd -> ../init.d/auditd 135974 lrwxrwxrwx. 1 root root 15 Aug 2 07:14 K89rdisc -> ../init.d/rdisc 136238 lrwxrwxrwx 1 root root 19 Sep 14 23:55 K92ip6tables -> ../init.d/ip6tables 135936 lrwxrwxrwx 1 root root 18 Sep 13 04:20 K92iptables -> ../init.d/iptables 136907 lrwxrwxrwx 1 root root 18 Sep 14 23:55 K99cpuspeed -> ../init.d/cpuspeed 136820 lrwxrwxrwx 1 root root 22 Sep 14 23:55 K99lvm2-monitor -> ../init.d/lvm2-monitor 136891 lrwxrwxrwx. 1 root root 14 Aug 2 07:14 K99rngd -> ../init.d/rngd 136771 lrwxrwxrwx. 1 root root 17 Aug 2 07:14 S01sysstat -> ../init.d/sysstat 136088 lrwxrwxrwx. 1 root root 17 Aug 2 07:14 S10network -> ../init.d/network 136159 lrwxrwxrwx. 1 root root 17 Aug 2 07:14 S12rsyslog -> ../init.d/rsyslog 136855 lrwxrwxrwx 1 root root 14 Sep 14 23:56 S55sshd -> ../init.d/sshd 136229 lrwxrwxrwx. 1 root root 15 Aug 2 07:14 S90crond -> ../init.d/crond 136029 lrwxrwxrwx. 1 root root 11 Aug 2 07:14 S99local -> ../rc.local
第7步 启动mingetty进程
启动该进程之后,进入登录界面,开机过程结束。
以上是关于linux学习笔记-开机启动过程的主要内容,如果未能解决你的问题,请参考以下文章
通过chkconfig设置linux开机自启动服务- 老男孩Linux运维学习笔记1