Linux boot-up process:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/02/wKiom1fRFGORQGWiAACCp6aQIlY198.jpg "title=" Boot up. jpg "alt=" wkiom1frfgorqgwiaaccp6aqily198.jpg "/>
First, the BIOS power-on self-test
When you press the power switch to boot, the computer will first go to the BIOS (basic input and output system), the BIOS is generally integrated on the motherboard.
The work of the BIOS
1. Detect the connection hardware, such as video card, memory, disk and so on, the purpose of detection is to provide these device information to the operating system later
2. Look for the boot disk, each BIOS will have a boot menu, you can set the menu on which device to boot the system
For example: optical drive, hard disk, network, etc., this menu can set multiple options, in accordance with the set order on the device to find the boot information
3. The boot drive is found, and then the BIOS will look for the boot sector on the disk to locate the kernel boot system.
1) First try to find the first sector, that is, the master boot record MBR (Master boot recording)
2) If no operating system exists on the first sector, then look for the partition labeled boot.
The storage operating system has only 446 bytes of space, whether it is an MBR or a boot partition;
If the kernel of the operating system is not found in the location mentioned above, then the BIOS will not be able to continue the boot operation.
And our kernel will tend to be larger than 446 bytes, stored in other locations on the disk, since 446 can not install the kernel, and in order to successfully find the kernel placed in other locations,
People came up with a way to write a small program in 446 bytes, and when the BIOS tries to start the operating system, it executes the applet, and then the applet loads the kernel in the other location. This applet is the boot loader (boot loader)
Second, BOOT Loader
Linux boot loader (the applet mentioned above) is common in two ways: Lilo Grub
Because Lilo has a 1024-cylinder limit and changes the boot information file on the disk, the system needs to be restarted to synchronize 446 bytes of content because Lilo's flaw has been superseded by GRUB. Most Linux-based systems now use grub as boot Loader
Grub does not have the LILO restrictions, and it is easy to modify the system files to start content can be immediately synchronized with 446 of content.
So let's just look at the grub content, which exists in/boot/grub.
Grub has several important files, STAGE1, STAGE1.5, STAGE2
STAGE1: It is only 512 bytes, usually placed in the MBR, it is very simple to use when the system is started to load STAGE2 and give control to it.
The core of Stage2:grub, all functions are implemented by it.
STAGE1.5: Between STAGE1 and STAGE2, is their bridge, because STAGE2 is larger, usually placed in a file system, but STAGE1 does not recognize the file system format,
That's why STAGE1.5 is needed to guide STAGE2 in a file system. Depending on the file system format, STAGE1.5 also requires corresponding files, such as: e2fs_stage1_5,fat_stage1_5, to identify the file system format of ext and fat, respectively. It is stored between 1-63 cylinders.
The boot order is as follows:stage1->; stage1.5->; STAGE2,
Primary configuration file when grub.conf
Inside option Meaning:
Title: An operating system-invocation header that enables multiple
Root: Indicates to which disk the required file exists on which partition (hd0,0) represents the first hard disk, the first partition, which can be referenced/boot/grub/device.map
Kernel: The name of the kernel file, and there will be some parameters when loading the kernel or representing read-only loading
INITRD: contains some additional drivers
Third, kernel boot
After the kernel starts, it queries the BIOS for all of the computer's hardware information, and then manages the devices themselves to provide Linux with
The kernel will try to drive these devices, some of which are part of the kernel, called static drivers, and part of the file system in the form of a module (dynamic),
No file system is mounted at this time, so it is not possible to use the modules in the file system, which can only drive the corresponding device for the hardware drivers that exist in the kernel. The file system needs to be loaded to drive hardware that is not included in the kernel.
The kernel tries to mount the root filesystem, and the root filesystem contains at least/etc/bin/sbin/lib/dev 5 large directories
5 of them are indispensable. will cause the system to fail to start
The root file system mount is mounted in read-only mode, because Linux is still in the startup phase and is not stable to avoid damaging system data
Iv. Starting the Init service
After the root file system is mounted successfully, the INIT service is started
The kernel will look for the INIT program in/sbin/init/etc/init/bin/init order.
If you can't find the kernel error, there is a parameter init=/bin/sh the last execution if specified at startup/bin/sh
Without generating a kernel error. Also known as fast start, because it ignores a lot of startup initialization work.
Init is started in order to initialize the system environment, Init is started to prove that the kernel has been successfully started, and then by the Init service to establish the Linux usage environment
What did Init do? It reads the/etc/inittab file and initializes it based on the information in the file.
Will execute three scripts/etc/rc.d/rc.sysinit/etc/rc.d/rc/etc/rc.d/rc.local
Rc.sysinit main functions used to establish the basic environment of the system
Start Udev SELinux Subsystem
Udev is responsible for generating files in/dev and SELinux is responsible for enhancing the security of the system
Set core parameters Sysctl-p load/etc/sysctl.conf
Set the system time to set the hardware time to system time
Load keyboard and swap partition Swapon-a-E
Set the host name, mount the file system, and re-mount the root as read-write.
Load Dynamic Driver Module
USB devices with raid & LVM
Uninstalling the/initrd/directory
rc script Set start level linux There are many different boot levels, different boot levels will be different for the service according to the specified RC parameters will correspond to execute /etc/rc.d/rc[0-6].d/ connection script file Start with S rc.local the first two scripts are system-critical scripts, and if we want to place some other program in the boot process should use the Rc.local script because s99local exists in rc[2-5]. When the three RC scripts in D are executed, the virtual main console execution /bin/login is provided with the user login interface. If it is a graphics l5 level, it will start x Window Login interface All the boot is finished. User environment initializes the user name and password system validation, and then executes the     /ETC/PROFILE    /ETC /profile.d/*.sh $HOME/.bash_profile /etc/bashrc $HOME/. BASHRC
Start level
0 Turn off the machine
1 Single User
2 Multi-user mode but with network but not telnet
3 Unrestricted Multi-user mode TUI
4 reserved
5 Graphics Mode
6 restart
Viewing the startup level
# RunLevel or Who-r
N 3
n is the last level, 3 is the current level, which means that the machine is booting up to level 3.
Toggle Level
Init 5
Set up automatic write service
1 Put the script you wrote into/ETC/INIT.D and add the script to execute permissions chmod +x
[Email protected] rc.d]# LL-HI/ETC/INIT.D
1179741 lrwxrwxrwx. 1 root root 13:35/etc/init.d-RC.D/INIT.D
[Email protected] etc]# ll-di/etc/rc.d/init.d/
1179742 Drwxr-xr-x. 2 root root 4096 06:21/etc/rc.d/init.d/
2 write in script
#! /bin/bash
#chkconfig: #35表示在级别3和级别5下开启此程序
#88表示开机时运行的优先级
#22表示关机时运行的优先级
#description: Testsrv Script
3 Execute chkconfig--add script name, at this time in the/etc/rc.d/directory of RC3.D and RC5.D to create a script connection, K for shutdown sequence, s for boot start sequence
Chkconfig command:
To view the startup or shutdown settings for a service at all levels:
Chkconfig[--list] [name]
Add to:
SYSV service scripts are placed in/ETC/RC.D/INIT.D (/ETC/INIT.D)
Chkconfig--add Name
#!/bin/bash
#LLLL indicates the initial level at which to start,-indicates that neither is started
# chkconfig:llll nnnn
Delete:
Chkconfig--del Name
Modify the specified link type
Chkconfig[--level levels] Name <on|off|reset>
--level llll: Specifies the level to be set; 2345 is omitted
This article is from the "zebra930" blog, make sure to keep this source http://zebra930.blog.51cto.com/11736340/1850841
Linux boot-up process