[Reprinted] Linux Startup Process details-Section 8 of "do not worry about Linux programming" and linux Startup Process details

Source: Internet
Author: User

[Reprinted] Linux Startup Process details-Section 8 of "do not worry about Linux programming" and linux Startup Process details

This original article belongs to the "Linux greenhouse" blog, blog address for http://roclinux.cn. The author of this article is rocrocket.
To prevent negative reprinting on some websites, we recommend that you add this information before each article.

===

[Starting text]

Start Step 1 -- load BIOS

When you turn on the computer power, the computer will first load the BIOS information, BIOS information is so important that the computer must find it at the very beginning. This is because the BIOS contains CPU information, device startup sequence information, hard disk information, memory information, clock information, and PnP features. After that, the computer will be aware of which hardware device should be read.

Start Step 2 -- read MBR

As we all know, the first sector of the 0th track on the hard disk is called MBR, that is, Master Boot Record, that is, the Master Boot Record. Its size is 512 bytes, you can store the pre-start information and partition table information.

After the system finds the MBR of the hard disk specified by BIOS, it will copy it to the physical memory where the 0x7c00 address is located. In fact, the content copied to the physical memory is the Boot Loader, and to your computer, it is lilo or grub.

Step 3 -- Boot Loader

Boot Loader is a small program that runs before the operating system kernel runs. Through this small program, we can initialize hardware devices and build a map of memory space to bring the system's hardware and software environment to a suitable state, in order to make all preparations for the final call to the operating system kernel.

There are several Boot loaders, among which Grub, Lilo, and spfdisk are common loaders.

Let's take Grub as an example. After all, there are not many people using lilo and spfdisk.

The System reads grub configuration information (generally menu. lst or grub. lst) in the memory and starts different operating systems according to the configuration information.

Step 4-load the kernel

Based on the path of the kernel image set by grub, the system reads the memory image and decompress it. At this time, the screen will usually output the "Uncompressing Linux" prompt. After the kernel is decompressed, the screen outputs "OK, booting the kernel ".

The system places the decompressed kernel in the memory, and calls the start_kernel () function to start a series of initialization functions and initialize various devices to complete the establishment of the Linux core environment. So far, the Linux kernel has been established, and the Linux-based program should be able to run normally.

Step 5 -- User-layer init sets the running level based on the inittab File

After the kernel is loaded, the first program to run is/sbin/init, which reads the/etc/inittab file and initializes the file based on the file.

In fact, the main function of the/etc/inittab file is to set the Linux running level. The setting format is ": id: 5: initdefault :", this indicates that Linux needs to run on level 5. The Linux operating level is set as follows:

0: Shutdown

1: single-user mode

2: multi-user mode without network support

3: multi-user mode with network support

4: reserved, not used

5. Multi-user mode with network support and X-Window support

6. reboot the system.

There are still a lot of knowledge about the/etc/inittab file. I designed it in the post-order article and sold it as a token. Please stay tuned.

Start step 6 -- execute rc. sysinit in the init process

After the running level is set, the first user-layer file executed by Linux is/etc/rc. d/rc. the sysinit script program does a lot of work, including setting PATH, setting network configuration (/etc/sysconfig/network), starting swap partitions, and setting/proc. If you are interested, you can check the rc. sysinit file in/etc/rc. d. The script in it is enough for a few days: P

Step 7 -- start the kernel module

The kernel module is loaded Based on the/etc/modules. conf file or the file in the/etc/modules. d directory.

Start Step 8-execute script programs of different running levels

Depending on the running level, the system will run the corresponding script programs from rc0.d to rc6.d to complete the initialization and start the corresponding service.

Start Step 9 -- run/etc/rc. d/rc. local

If you open this file, there is a sentence in it. After reading it, you will see the role of this command at a Glance:

# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full Sys V style init stuff.

Rc. local is a place for users to personalize Linux after all initialization work. You can put what you want to set and start here.

Start step 10-run the/bin/login program and enter the logon status

Now, the system has entered the waiting time for the user to enter username and password. You can use your account to log on to the system. :)

===

The long start process is over, and everything is quiet...

In fact, there are more complex underlying function calls behind this, waiting for you to study... This article is worth mentioning :)

This article is made up of the following articles:

Http://bbs.chinaunix.net/thread-835918-1-1.html

Http://hi.baidu.com/fembed/blog/item/b9f0881f51145866f624e4be.html

Http://baike.baidu.com/view/9485.htm

Linux Startup Process Analysis-Huo bingquan-Department of Computer Engineering, Shandong Binzhou Vocational College

Linux Startup Process Analysis and Optimization-Master's Degree Thesis from Zhejiang University

Thanks to the author of the above article :)

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.