Linux Startup Process details

Source: Internet
Author: User
Article Title: Linux Startup Process details. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Linux Startup Process (/etc/inittab)

1. From BIOS to KERNEL

BIOS self-check-> MBR (GRUB)-> KERNEL self-decompression-> KERNEL initialization-> KERNEL startup

BIOS self-check

When the computer is turned on, the computer enters the BIOS. BIOS is mainly used to detect whether the computer's peripheral equipment works normally, such as the CPU type, speed, and cache.

Motherboard type

Memory speed and capacity

Hard Disk size, type, and working mode

Fan speed, etc.

The main purpose is to check whether these devices can pass the detection when they are started. If they can pass the detection, the computer can work normally.

-----------------------------------------

1. Load the Startup Program

After the BIOS self-check is completed, the BIOS will start the computer's operating system based on the boot sequence set by the user. This device is generally a hard disk.

That is, enter the MBR area (Boot Sector) of the hard disk. The size of this area is 512 bytes. The program saved in the first 446 bytes is to select the boot partition, that is, the hard disk partition used by the computer to load the boot program. In this 446-byte space, the startup program is saved, and then the applet loads the operating system stored in other locations, that is, the grub program is started.

When the boot device (hard disk) is found, the boot loader used in the first phase (stored in the boot sector) is loaded into RAM and executed. Here, the boot loader is smaller than the size of one slice, that is, 512 bytes. Its task is to load the boot loader of the second stage.

When the second-stage boot loader is in memory and executed, a pop-up screen is usually displayed, then linux and optional initialization memory disks (a temporary root file system, visit the http://likunarmstrong.bokee.com/5502266.html if you want to get a specific introduction) will be loaded into the memory. When the system image is loaded, the second-stage boot loader transfers the control to the kernel image. At the same time, the kernel starts self-extracting and initialization. In this phase, the boot loader in the second phase checks the hardware of the system, enumerates the attached hardware devices, mounts the root device, and then loads the required kernel modules. After the initialization, the first user space program (init) starts to execute and the system initialization starts at a higher level.

This is the linux Startup Process. Now, let's go further and explore more details about the linux Startup Process.

Ii. System Startup

The system startup stage depends on the hardware device on which linux is started. In an embedded system, when the system is turned on or restarted, the loading environment must be used. Examples include U-BOOT, RedBoot, and Lucent MicroMonitor. Embedded platforms are usually bound with boot monitors. These programs are located in the specific location of the flash memory on the target hardware. They provide a method to download the Linux kernel image to the flash memory and execute it in the following process. In addition to the ability to store and start linux images, these boot monitors can also perform system detection and hardware initialization to a certain extent. In an Embedded Target Board, these boot monitors typically cover the features of the first and second phases of boot loader.

/*************************************** **************************************** *****************/

TIPS: how to view your MBR content. If you want to view the specific content of your MBR, use the following command:

# Dd if =/dev/hda of = mbr. bin bs = 512 count = 1

# Od-xa mbr. bin

The dd command that needs to be run as root reads the first 512 bytes of your first integrated electronic drive or IDE drive and writes them

Mbr. bim file. The od command prints the binary file in hexadecimal and ASCII code format.

/*************************************** **************************************** *****************/

In a PC, linux starts from 0xFFFF0. The first step of BIOS is to perform power-on self-check (POST ). The job of POST is to check the hardware device. The second step of BIOS is to enumerate the local device and initialize it.

Because of the different BIOS functions, it consists of two parts: the POST code runtime service. After the POST is completed, it will be cleared from the memory, but the BIOS runtime service will be retained for the target operating system.

To start the operating system, the BIOS runtime service searches for the activated or boot-able devices, the search sequence is determined by the CMOS settings (that is, the boot sequence we usually call in BIOS ). A soft drive, an optical drive, a partition on a hard disk, a network device, or even a usb flash drive, can be used as a boot device.

Of course, linux is usually started from a hard disk. The MBR (Master boot Record) on the hard disk contains a basic boot loader, which is a 512-byte sector located in the first sector of the disk (0 head, 0 track, 1 sector ). When the MBR is loaded into RAM, the BIOS transfers the control to the MBR.

Iii. First-stage boot loader

The Master boot loader in MBR is a 512-byte image, which not only contains program code, but also contains a small partition table, as shown in figure 2. The first 446 bytes are the main boot loader, which contains executable code and error message text. The next 64 bytes is a partition table, which contains records of the four partitions (each partition occupies 16 bytes ). MBR uses a special number 0xAA55 (note: in the electronics industry, AA55 is indeed a legend. Do you want to know why? Expand it into a binary form to see what is the rule) as the end sign of two bytes. 0x55AA is also an effective validation for MBR.

The main work of the boot loader is to find and load the second boot loader. It analyzes the partition table and finds the active partition to complete this task. When it finds an active partition, it continues to scan the partitions in the remaining partition table to confirm that they are not activated. After confirmation, the activation record of the active partition is read from the device RAM and executed.

Iv. Phase 2 boot loader

It plays a secondary role, or is the second boot loader, which can be called a kernel loader. In this phase, the task is to load the Linux kernel and initialize the memory disk.

/*************************************** ****************************/

TIPS: boot loaders in GRUB stage

The/boot/grub directory contains the boot loaders of stage1, stage2 and stage1.5, and there are also many optional loaders (for example, the CD-ROM uses the iso9660_stage_1_5)

/*************************************** ****************************/

Combine the boot loaders of the first and second phases, that is, linux loader (LILO) or GRand uniied Bootloader (GRUB) on the x86 PC ). GRUB fixes some LILO defects, so let's take a look at GRUB (if you want to get more resources about GRUB, LILO, and related topics, see references below)

For GRUB, a better aspect is that it contains the knowledge of linux file systems. Unlike LILO's bare sector, GRUB can load the Linux kernel from the ext2 or ext3 file system. It converts a two-stage boot loader to a three-stage boot loader. In Stage 1 (MBR), boot loader of stage1.5 will be started to understand the special file system formats in Linux kernel images, for example, reiserfs_stage1-5 (for loading from reiserf log file systems) or e2fs + stage1_5 (used for loading from wxt2 or ext3 File System ). When the boot loader of stage1.5 is loaded and running, the boot loader of stage2 can be loaded.

When stage2 is loaded, GRUB can display a list of optional kernels (in/etc/grub. conf, and several 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 use the shell of the command line to perform more in-depth manual control over the startup process.

In the second phase, after the boot loader exists and the memory is in place, you can query the file system. At the same time, the default kernel image and the initialized memory disk image are also loaded into the memory. After all preparations are completed, the boot loader in the second stage will call the kernel image.

 

[1] [2] Next page

Related Article

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.