Detailed process of linux Startup

Source: Internet
Author: User

I. BIOS power-on self-check
When you press the power switch to start the computer, the computer will first start the BIOS (Basic Input and Output System), the BIOS is generally integrated on the motherboard.
BIOS work
1. Check the connected hardware, such as the video card, memory, and disk. The purpose of the detection is to provide the device information to the operating system in the future.
2. Find the boot disk. Each BIOS has a boot menu. You can set the device on which the system is started.
For example: Optical Drive, hard disk, network, etc. You can set multiple options in this menu to search for startup information on the device in the order of settings.
3. Find the boot hard disk, and then the BIOS will find the Boot Sector on the disk and find the kernel boot system.
1) first try to find the first sector, that is, the Master Boot Record MBR (Master Boot Record)
2) If no operating system exists on the first sector, search for the partition marked as BOOT.
Whether it is MBR or BOOT partition, the storage space of the operating system is only 446 bytes;
If the kernel of the operating system is not found at the position mentioned above, the BIOS cannot start up.
However, our kernel usually contains more than 446 bytes and is stored in other locations on the disk. Since 446 cannot fit the kernel, we can find the kernel in other locations smoothly,
People come up with a way to write a small program in 446 bytes. When the BIOS tries to start the operating system, it will execute this small program, then the applet loads the kernel at other locations. this small program is to start the loader (boot loader)
Ii. BOOT Loader
Linux boot loader (the small program mentioned above) has two common types: lilo grub
Because lilo has a 1024-byte cylindrical limit, and after changing the boot information file on the disk, You need to restart the system to synchronize the 446-byte content, because of lilo's defects, it has been replaced by grub. currently, most linux systems use grub for boot loader;
Grub does not have various restrictions on lilo, And it is convenient to modify the startup content of the system file to be immediately synchronized with the 446 content.
Then let's take a look at grub content which exists in/boot/grub.
GRUB has several important files: STAGE1, STAGE1.5, and STAGE2.
STAGE1: it has only 512 bytes and is usually placed in MBR. It is used to load STAGE2 at system startup and give control to it.
STAGE2: the Core of GRUB. All functions are implemented by it.
STAGE1.5: Between STAGE1 and STAGE2, It is a bridge between them. Because STAGE2 is large, it is usually placed in a file system, but STAGE1 cannot identify the file system format,
Therefore, STAGE1.5 is required to guide STAGE2 located in a file system. According to different file system formats, STAGE1.5 also requires corresponding files, such as e2fs_stage00005 and fat_stage00005, which are used to identify ext and fat file system formats respectively. It is stored between 1-63 cylinders.
The guiding sequence is as follows: STAGE1->; STAGE1.5->; STAGE2,
Grub. conf in the main configuration file
Meaning of options:
Title: an OS-induced header that allows multiple
Root: Specify the disk on which the file is stored (hd0, 0). This indicates the first hard disk and the first partition. For details, refer to/boot/grub/device. map.
Kernel: the name of the kernel file, and some parameters during kernel loading or indicate loading in read-only mode
Initrd: contains some additional drivers

Iii. kernel startup
After the kernel is started, it will query all the hardware information of the computer from the bios, and take over and manage these devices for linux
The kernel will try to drive these devices. Some drivers of these devices are included in the kernel, called static drivers, and some are stored in the file system in a module (dynamic) manner.
At this time, no file system is mounted, so you cannot use the modules in the file system. Here, you can only drive the corresponding device of the hardware driver that exists in the kernel. to drive hardware drivers not included in the kernel, You need to load the file system.
The kernel will try to mount the root file system. The root file system should contain at least five directories:/etc/bin/sbin/lib/dev.
The five of them are indispensable, and the system cannot be started.
The root file system is mounted in read-only mode, because linux is still in the startup phase and is not stable, avoiding damage to system data.
4. Start the INIT Service
After the root file system is successfully mounted, the init service will be started.
The kernel searches for the init program in the order of/sbin/init/etc/init/bin/init,
If no value is found, the kernel reports an error. The init =/bin/sh parameter exists. If this parameter is specified at startup,/bin/sh is executed.
It does not generate Kernel errors. It is also called Quick Start because it ignores a lot of startup initialization work.
The purpose of starting init is to initialize the system environment. Starting init proves that the kernel has been successfully started. Next, the init service will establish the linux environment.
What does init do? It reads the/etc/inittab file and initializes the file based on the file information.
Three scripts are executed:/etc/rc. d/rc. sysinit/etc/rc. d/rc/etc/rc. d/rc. local.
Rc. sysinit is mainly used to establish the basic environment of the system.
Start udev selinux Subsystem
Udev is responsible for generating/dev files, and selinux is responsible for enhancing system security
Set the core parameter sysctl-p to load/etc/sysctl. conf
Set system time to set hardware time to system time
Load keyboard and swap partition swapon-a-e
Set the host name, mount the file system, and remount the root to read/write.
Load dynamic Driver Module
USB device and RAID & LVM
Uninstall/initrd/directory

The rc Script sets the startup level. linux has many different startup levels. Different startup levels define different services.
Based on the specified rc parameter, the connection script file in the/etc/rc. d/rc [0-6]. d/file starts with S.
The first two scripts of rc. local are important scripts of the system. If we want to place some other programs during the startup process
The rc. local script should be used because S99local exists in rc [2-5]. d.
After the three RC scripts are executed, the virtual master console will be created to execute/bin/login, and the user login interface will be provided.
The X window logon interface is enabled if the graphic Level 5 is used.
All started
User Environment Initialization
Enter the user name and password for system verification, and then execute
/Etc/profile
/Etc/profile. d/*. sh $ HOME/. bash_profile
/Etc/bashrc
$ HOME/. bashrc

Startup level
0 Shutdown
1 single user
2 multi-user mode, but with network, but not remote login
3 unrestricted multi-user mode TUI
4 Reserved
5. graphic mode
6. Restart
View the startup level
# Runlevel
N 3
N is the last level, 3 is the current level, that is, the machine starts up to 3 levels
Switch Level
Init 5

Mount a File System
/Etc/fstab
The first is the physical location of the storage device to be mounted or the volume label.
The second item is the location of the directory to be mounted.
Item 3 specify the system format to be mounted
The status to be set during the fourth mount, read-only or defauls
Item 5 provides the DUMP function. The flag of BACKUP is required when the system DUMP is enabled, and its inner position is 0.
Item 6 check the file system at startup
Except for the root file system, the required check is 1. The default value is 0.
LABEL =/boot ext3 defaults 1 2


Author "xudeqiang"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.