Linux boot process

Step1. Post

When power is turned on, POST (Power-On Self-Test) is the diagnostic testing sequence that a computer's basic input/output system (or "starting program") runs to determine if the computer keyboard, random access memory, disk drives, and other hardware are working correctly.

Bios

•  If the necessary hardware is detected and found to be operating properly, the computer begins to boot.

  If the hardware is not detected or is found not to be operating properly, the BIOS issues an error message which may be text on the display screen and/or a series of coded beeps, depending on the nature of the problem.

  Since POST runs before the computer's video card is activated, it may not be possible to progress to the display screen.

  The pattern of beeps may be a variable numbers of short beeps or a mixture of long and short beeps, depending on what type of BIOS is installed.

Step2. MBR

The Master Boot Record (MBR) is the information in the first sector of any hard disk or diskette that identifies how and where an operating system is located so that it can be boot (loaded) into the computer's main storage or random access memory.

  The Master Boot Record is also sometimes called the "partition sector" or the "master partition table" because it includes a table that locates each partition that the hard disk has been formatted into.

  In addition to this table, the MBR also includes a program that reads the boot sector record of the partition containing the operating system to be booted into RAM.

  In turn, that record contains a program that loads the rest of the operating system into RAM.

  MBR is stored in the disk header,it`s size is 512 bytes.446 bytes is using BootLoader process and the other 64 bytes is stored partition table.The last 2bytes is stored MBR validity check.

Step3. GRUB

GNU GRUB is a Multiboot boot loader. It was derived from GRUB, the GRand Unified Bootloader, which was originally designed and implemented by Erich Stefan Boleyn.

  Briefly, a boot loader is the first software program that runs when a computer starts.

  It is responsible for loading and transferring control to the operating system kernel software (Linux). The kernel, in turn, initializes the rest of the operating system

•Three parts:

•  Stage1:search and load Bootloader(stage2),but when the system is not boot,MBR can not found the stage2,So we need to stage1.5

•  Stage1_5:distinguish file system

•  Stage2:GRUB process will according to /boot/grub/grub.conf to find Kernel information and load Kernel image. Kernel process load into memory ,and then Kernel process will get control power.

Step4. Kernel

Kernel

  The Linux kernel is an operating system (OS) kernel defined as Unix-like in nature. It used in different operating systems, mostly in the form of different Linux distributions. 

 

•GRUB will load Kernel and decompress it into memory.  

•Initrd(Initial RAM Disk),it will be copy to memory in stage2,a tmp root file system(rootfs).

•In order to make the kernel more simplify, only the most basic modules are kept.

  Initrd is to drive root fs, so to drive root fs, the corresponding driver compiled into vmlinux is no problem. But the problem is that when compiling vmlinux, you don't know what driver root fs needs, so you need to compile all the drivers into vmlinux, and then the kernel will become very big. However, for a certain hardware, you can only compile the drivers you need into vmlinux, and there will be no big kernel problems.

Step5. •Init

Sysvinit: /etc/inittab

Systemd: /lib/systemd/system/multi-user.target

•   1、activate udev and selinux

•        2、according to /etc/sysctl.conf setting kernel parameters

•        3、set system clock

•        4、map hard disk

•        5、activate swap space

•        6、set host name

•        7、root file system check,remount root file system

•        8、activate RAID and LVM device

•        9、disk quote

•       10、according to /etc/fstab mount file system and check it

•       11、clean out date lock and PID file

•  At last,according to the run level execute /etc/rc.d/rc.local

Step6 Run level

•Run level,difference level will start the difference service.init will according to the run level to execute the script.

•Linux run level:

•  0:shutdown

•  1:single(administrator)

•  2:multiples (no nfs)

•  3:multiples (command)

•  4:reserve

•  5:multiples user (graph)

•  6:reboot

Step7. create console

•Init will open six console process

•vi /etc/inittab

•# Format:

•#  <id>:<runlevels>:<action>:<process>

•#

•# Note that on most Debian systems tty7 is used by the X Window System,

•# so if you want to add more getty's go ahead but skip tty7 if you run X.

•1:2345:respawn:/sbin/getty 38400 tty1

•2:23:respawn:/sbin/getty 38400 tty2

•3:23:respawn:/sbin/getty 38400 tty3

•4:23:respawn:/sbin/getty 38400 tty4

•5:23:respawn:/sbin/getty 38400 tty5

•6:23:respawn:/sbin/getty 38400 tty6

Step8. Login

•there are three ways for users to log in:

•(1) command line login

•(2) SSH login

•(3) graphical interface login

•Use Ctrl+Alt+F1~F6 switch to another console

 

相关文章: