Understand the Linux Startup Process

Source: Internet
Author: User
Article Title: Understand the Linux Startup Process. 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.

From pressing the PC power supply to the familiar bash prompt "$" or entering the beautiful KDE/GNOME desktop, this is a necessary process for us to boot every day. So how does Linux start in just dozens of seconds? This article describes the Linux Startup Process.

Platform: PC, Ubuntu 5.10

Basic knowledge

BIOS (Basic I/O System, Basic Input/Output System)

The BIOS, in its entirety, should be a ROM-BIOS, short for the Basic Input/Output System of read-only memory, which is actually a group of programs solidified into the computer, provides the lowest-level and most direct hardware control for computers. To be precise, BIOS is a "converter" or an interface (although it is only a program) between hardware and software programs, responsible for solving real-time hardware requirements, perform the operation according to the software's hardware operation requirements.

From the functional perspective, BIOS is divided into three parts:

1. Self-check and initialization program;

2. Hardware interrupt handling;

3. program service request.

Here we mainly focus on the first part-self-check and initialization program: This part is responsible for starting the computer. There are three specific parts. The first part is used to detect the hardware part when the computer is powered on, it is also called power-on self-check (POST). The function is to check whether the computer is good, for example, whether the memory is faulty or not. The second part is initialization, including creating interrupt vectors, setting registers, initializing and detecting some external devices. A very important part is BIOS settings, these parameters are mainly set for hardware. When the computer starts, these parameters are read and compared with the actual hardware settings. If they do not match, the system starts up.

The last part is the boot program, which is used to boot DOS or other operating systems. The BIOS first reads the Boot Record from the floppy disk or the start sector of the hard disk. If no boot record is found, no boot device is displayed on the monitor. If a boot record is found, the control of the computer is transferred to the Boot Record, the Boot Record loads the operating system into the computer. After the computer is started successfully, the BIOS task is completed.

For more information about BIOS, please google this article.

Hard Disk

In terms of physical composition, a hard disk package contains multiple platters, each of which has two surfaces ). There is a head on the disk to read/write the disk. When the disk is rotated around the axis (spinder) for one week, the track that the head traveled is the track ), the same track of all disks forms the cylinder ). The track is divided into multiple sectors. The sector is the smallest disk storage unit, that is, the minimum unit for hard disk partitioning-usually kb. Channels are separated by gaps. The gap stores not data bits, but the format bits of the slice.

MBR

The Master Boot Recorder (MBR) is the most important part of the hard disk. It records the partition and Boot information of the hard disk. CU has an article about MBR.

Note that the MBR here refers to the MBR in the startup device specified in BIOS. If the disk is started, MBR is the first sector of the disk. If it is a hard disk, it is the first sector of the hard disk. What if there are multiple hard disks? This is the first sector specified in the BIOS to start the hard disk!

Run-level

Run $ less/etc/inittab

The following information is displayed:

#/Etc/init. d executes the S and K scripts upon change

# Of runlevel.

#

# Runlevel 0 is halt.

# Runlevel 1 is single-user.

# Runlevels 2-5 are multi-user.

# Runlevel 6 is reboot.

The above shows the currently available logon modes, with a total of 0 ~ Level 6. Commonly used are 3 and 5.

0: Shutdown

1: single-user mode (logon mode when the system is faulty, equivalent to WINDOWS's "security mode")

2: for Debian/Ubuntuare, 2 ~ 5 is the same-multi-user graphical interface mode. For other releases, 3 may be in multi-user text mode, 4 is reserved for the system, and 5 is in multi-user graphics mode, for specific definitions, you can view the content of the/etc/inittab file corresponding to the release.

6. Restart

In addition, there may also be "S" level, which is equivalent to a single user level of 1.

Run $ runlevel to view the current running level of the system

If you set the running level to 0 or 6, what would happen? How can this problem be solved?

When WINDOWS is started, if you press F8, the "safe mode", "normal start", "MS-DOS" mode options appear. It is equivalent to 1, 5, and 3 of Linux run-level (not applicable to Debian/Ubuntu ).

For details about run-level In Debian/Ubuntu, refer to here!

Basic Process

1. Load the BIOS hardware information and obtain the code of the first boot device.

2. Load boot loader (lilo, grub, spfdisk, etc.) boot information of MBR in the first boot device.

3. Load the Linux kernel, decompress the kernel, and drive the hardware.

4. the kernel executes the init program and obtains the run-level information;

5. Run the/etc/init. d/rcS program in init;

6. Load the kernel module)

7. Execute the script file (Scripts) corresponding to the run-level in init );

8. Run the/bin/login program and wait for the user to log on;

9. After the user logs on, the shell control system is started (if the user logs on to the GUI, the GUI is run ).

The following describes the steps in the process:

1. Load BIOS

When the system powers on, it first reads BIOS information. BIOS (Basic Input/Output System) is the underlying interface between computers and peripherals. It stores the data first loaded when the computer starts, including: CPU type, boot device sequence, hard disk size/type, chipset working status, peripherals I/O address, PnP (Plug and Play, both Plug-and-use devices) or not, memory clock, etc.

After reading the BIOS settings, the system performs Power On Self Test (POST) based On BIOS data, initializes the hardware, sets the PnP device, and specifies the start device, then read the Bootloader data from the disk MBR.

2. Load the Boot Loader

After the system completes the BIOS, it loads the first sector (MBR) of the first boot disk, and the boot loader is located in MBR. In this case, the boot baton is handed in to the boot loader.

Common boot loaders include lilo, grub, and spfdisk. grub is the most popular nowadays. In Ubuntu, the boot loader is grub. In this article, we assume that the boot loader is grub, in fact, the basic principles are the same.

Why Install boot loader in MBR? What does it do? In fact, boot loader is used to load the OS kernel. When the system starts, to read files to load the kernel, it must be able to identify the hard disk file system, but at this time the system is still starting, the file system information is unknown. Boot loader helps the system identify the file format and load the kernel. Boot loader not only recognizes the Linux kernel, but also recognizes the WINDOWS Kernel. Therefore, if you want to install a multi-system, install the boot loader that supports these system file systems in MBR.

If it is started with grub, after loading it, there will be a menu to start that OS. When you make the selection, grub will load the corresponding kernel from the sector where the selected OS is located.

[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.