Linux system startup process

Source: Internet
Author: User

First, POST (power-on self-test)

The BIOS self-test, enumerates the local devices and initializes the device to find the first "active" state in the CMOS settings (possibly a hard disk, possibly a USB flash drive, see how the BIOS is set) to read into its MBR.

Second, the first stage boot loader

1.MBR is actually composed of 3 parts: the main boot loader (Master bootloader code,446 bytes), Primary partition table (PPT), Magic Nubmer (0xaa55) composed of the main partition table has 4 records, corresponding to the primary partition 1-primary partition 4, a total of 64 Bytes. The last magic number is 2 bytes.

2. The Master boot loader searches the primary partition table, scans all 4 partition records, and ensures that only 1 are marked "active" (with Fdisk you can set a partition as the active partition). Then read into the boot sector of the partition (the first 512 bytes). The active partition is usually the first partition of the C drive or Linux.

3. The role of the master boot loader is to read into the 2nd stage of the bootloader program.

Third, second stage boot loader

1. The purpose of the 2nd Stage boot loader is to load the kernel and INITRD.

       2. If the Boot-loader is installed in the MBR, the boot process will not involve the first sector of the active partition, That is, the MBR Boot program (STAGE1) will directly load stage2 (or Stage1.5,grub have this stage), and Stage2 is stored in a partition of the file, Lilo should be boot.b, Grub is stage1.5 and stage2, and the location of these files is recorded in Stage1 when the Boot-loader is installed. In this case, even if no partition is active, the system can boot.

       3. If the Boot-loader is installed in the first sector of the active partition, the MBR will still have a small boot program to load the Boot-loader that is installed in the first sector of the active partition stage1.  Stage1 will start stage1.5 boot loader to understand the special file system format in the Linux kernel image, for example, reiserfs_stage1-5 (for loading from the Reiserf log file system) or e2fs+stage1_5 (for loading from the WXT2 or ext3 file system). When the boot loader of stage1.5 is loaded and running, Stage2 boot loader can be loaded. When Stage2 is loaded, grub can display a list of optional kernels based on the request (defined in/etc/grub.conf with a few soft symbolic links/etc/grub/menu.lst and/etc/grub.conf). You can select a kernel and modify its additional kernel parameters. At the same time, you can choose to use the shell of the command line for a more in-depth manual control of the startup process. After the second stage boot loader is present and in memory, the file system can be queried, and the default kernel image and the initialized memory disk image are also loaded into memory. After all is ready, the second stage of boot loader will invoke kernel mirroring.

Four, the kernel

1. Kernel self-extracting

2. Copy the contents of the/DEV/INITRD to/dev/ram and release the memory occupied by the/DEV/INITRD according to the INITRD address in memory provided by Bootloader.

3. Mount the/dev/ram as a virtual file system in RW mode, simulate a root system in memory, provide an executable program

4. The program executes its/LINUXRC or/init script above to load the driver module

5. In the/LINUXRC and/init scripts, there will be pivot_root () or switchroot to mount the real root filesystem device under/sysroot to/and mount the initial root filesystem to/INITRD

6./LINUXRC and/init scripts will be umount/initrd under the initial root filesystem (even if they are not completely uninstalled, they will all be uninstalled in/etc/rc.d/rc.sysinit)

7. The next step is to start the init process. In the 2.4 kernel, this step is done by the kernel. But in the 2.6 kernel, this step is done by the/init script.

In short: After the Boot loader loads kernel and INITRD, the INITRD is decompressed into a virtual root in memory, and kernel can then load the appropriate driver through LINUXRC, eventually releasing the virtual file system, and mounting the actual root filesystem, will be able to start the following normal start-up process.

V. INIT

At this point the kernel actively invokes the first process/sbin/init. Its main function is to prepare the software execution environment, including the system hostname, network settings, language processing, file system format and other services start-up and so on.

Init reads the/etc/inittab configuration file. Inittab defines the process flow for Init, which is:

1. Get runlevel that is the default execution level of the relevant level

2. Using/etc/rc.d/rc.sysinit for system initialization, the main task is to set up the environment of the whole system.

3. Confirm the boot entry level and determine the starting service options by/ETC/RC.D/RC based on the level of startup

4. Execute user-defined boot-up program/etc/rc.d/rc.local

5. Execute the terminal emulation program Mingetty to start the login process, waiting for the user to log in

Linux system startup process

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.