Chinaunix首页 | 论坛 | 博客
  • 博客访问: 354461
  • 博文数量: 83
  • 博客积分: 5322
  • 博客等级: 中校
  • 技术积分: 1057
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-11 11:27
个人简介

爱生活,爱阅读

文章分类

全部博文(83)

文章存档

2015年(1)

2013年(1)

2012年(80)

2011年(1)

分类: LINUX

2012-08-31 20:16:57

6 Stages of Linux Boot Process (Startup Sequence)

Linux 引导过程的6个阶段(启动顺序)

by RAMESH NATARAJAN on FEBRUARY 7, 2011

Press the power button on your system, and after few moments you see the Linux login prompt.

   在按下系统的电源键,经过片刻之后,你将看到Linux的登录提示。

 

Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?

你是否曾经想知道从按下电源键,直到出现Linux登录提示符之间,屏幕背后发生了什么?

The following are the 6 high level stages of a typical Linux boot process.

下面是传统Linux启动过程的6个高级阶段。

              

1. BIOS

  BIOS stands for Basic Input/Output System

BIOS代表的是基本输入/输出系统

  Performs some system integrity checks

执行一些系统完整性检验

  Searches, loads, and executes the boot loader program.

搜索,加载,并执行引导加载程序

  It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 or F2, but it depends on your system) during the BIOS startup to change the boot sequence.

它在软盘,光盘(cd-rom)或者硬盘上查找引导加载器。你可以在BIOS启动时候按下键盘(通常为F12F2,这取决于你的系统)来改变启动顺序。

  Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.

一旦发现并将引导加载程序加载到内存,BIOS将控制权交个加载程序。

  So, in simple terms BIOS loads and executes the MBR boot loader.

所以,简单而言,BIOS加载并执行MBR引导加载器。

2. MBR

  MBR stands for Master Boot Record.

MBR代表主引导记录(主引导分区)

  It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda

它位于可启动盘的第一个扇区。通常为/dev/hda,/dev/sda

  MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.

MBR区域大小为512字节,由三部分组成:446字节的主引导程序。2)接下来64字节的分区表。3)最后两字节的MBR有效性校验值。

  It contains information about GRUB (or LILO in old systems).

它包含GRUB相关的信息(或者一些较早系统中的LILO)。

  So, in simple terms MBR loads and executes the GRUB boot loader.

所以,简单而言MBR加载并执行GRUB引导加载器。

3. GRUB

  GRUB stands for .

GRUB代表Grand Unified Bootloader

  If you have multiple kernel images installed on your system, you can choose which one to be executed.

如果你的系统上拥有多个内核镜像,你可以选择执行哪一个内核。

  GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.

GRUB显示一个背景(splash)屏幕,等待几秒钟,如果你没有任何输入,它将加载grub配置文件中指定的默认内核镜像。

  GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).

GRUB可以识别文件系统(之前的Linux加载器LILO不识别文件系统)。

  Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.

Grub的配置文件是/boot/grub/grub.conf(/etc/grub.conf是该文件的一个符号连接)。下面是CentOS系统一个示例grub.conf配置:

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.18-194.el5PAE)

          root (hd0,0)

          kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/

          initrd /boot/initrd-2.6.18-194.el5PAE.img

  As you notice from the above info, it contains kernel and initrd image.

正如你看到的上面的信息,它包含内核以及initrd镜像。

  So, in simple terms GRUB just loads and executes Kernel and initrd images.

所以,简单而言GRUB仅仅加载并执行内核与initrd镜像。

4. Kernel

  Mounts the root file system as specified in the “root=” in grub.conf

按照grub.conf中指定的"root="安装根目录。

  Kernel executes the /sbin/init program

内核执行程序/sbin/init

  Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘’ and check the pid.

由于init是内核执行的第一个程序,它的pid1.使用命令“ps -ef | grep init”查看init进程id

  initrd stands for Initial RAM Disk.

Initrd代表初始RAM盘。

  initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

内核使用Initrd作为临时的根文件系统,直到内核启动成功并将真正的根目录安装完成。它同时包含一些必要的编译过的驱动程序,用于访问磁盘分区以及其它硬件。

5. Init

  Looks at the /etc/inittab file to decide the Linux run level.

查看文件/etc/inittab,该文件决定了Linux的运行级别。

  Following are the available run levels

以下是可用的运行级别

0 – halt

1 – Single user mode

2 – Multiuser, without NFS

3 – Full multiuser mode

4 – unused

5 – X11

6 – reboot

  Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.

Init进程从/etc/inittab中确定默认的运行级别,并根据该运行级别来加载合适程序。

  Execute ‘’ on your system to identify the default run level

在你的系统上执行“grep initdefault /etc/inittab”,获取默认的运行级别。

  If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.

如果你想找点麻烦的话,可以将默认的运行级别设置为06.鉴于你知道06的意义,你可能不会那样做。

  Typically you would set the default run level to either 3 or 5.

通常你会将默认的运行级别设置为35.

6. Runlevel programs

  When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.

Linux系统启动过程中,你可以看到不同的服务被启动。例如,它可能显示“Starting sendingmail…OK”。这些就是运行级别程序,他们是根据系统的运行级,通过执行对应的运行级别目录中的程序实现的。

  Depending on your default init level setting, the system will execute the programs from one of the following directories.

根据默认的init运行级别,系统将会执行下面目录中的一个所有程序。

  Run level 0 – /etc/rc.d/rc0.d/

  Run level 1 – /etc/rc.d/rc1.d/

  Run level 2 – /etc/rc.d/rc2.d/

  Run level 3 – /etc/rc.d/rc3.d/

  Run level 4 – /etc/rc.d/rc4.d/

  Run level 5 – /etc/rc.d/rc5.d/

  Run level 6 – /etc/rc.d/rc6.d/

  Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.

请注意,这些目录在/etc中均有可用的符号连接。例如,/etc/rc0.d/etc/rc.d/rc0.d的一个符号连接。

  Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.

在目录/etc/rc.d/rc*.d/下,你可以看到一些以S,K开头的程序。

  Programs starts with S are used during startup. S for startup.

S开头的程序在系统启动时候启动。S代表启动。

  Programs starts with K are used during shutdown. K for kill.

K开头的程序在系统启动时候终止。K代表终止。

  There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.

程序的名字中,在SK之后跟着数字。这些数字代表这需要启动或终止的顺序。

  For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.

例如,S12syslog是启动syslog守护进程,其启动序号为12。S80sendmail是启动sendmail守护进程,其启动序号为80。所以syslog将在sendmail之前启动。

There you have it. That is what happens during the Linux boot process.

    现在你明白了吧。这就是Linux启动过程中所发生的一切。

阅读(1271) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~