(Click the blue text above to quickly follow us)
Source: Vamei (@Vamei)
Link: http://www.cnblogs.com/vamei/archive/2012/09/05/2672039.html
The process of booting a computer is a mysterious one. We simply press the power button and see a progress bar or lines of output on the screen until we reach the login interface. However, the booting process is also exceptionally fragile; the login screen we eagerly anticipate may not appear, and instead, we might see a command line or an error message. Understanding the boot process can help us troubleshoot potential issues that may arise during startup.
Initial Stage
When we turn on the computer, it automatically reads the stored programs from the motherboard’s BIOS (Basic Input/Output System). This program typically knows about hardware directly connected to the motherboard (hard drives, network interfaces, keyboards, serial ports, parallel ports). Most modern BIOS versions allow you to choose a boot device from a floppy disk, CD, or hard drive.
The next step involves the computer reading the initial 512 bytes from the selected storage device (for example, the first 512 bytes of a CD if we boot from it). This 512 bytes is called the Master Boot Record (MBR). The MBR tells the computer to load the boot loader from a specific partition of that device. The boot loader contains information related to the operating system (OS), such as the OS name and the location of the operating system kernel. Common boot loaders include GRUB and LILO.
Subsequently, the boot loader helps us load the kernel. The kernel is essentially a program that operates the computer; it is the core of the operating system, primarily tasked with managing the computer’s hardware resources and acting as an interface between software and hardware. Any operation on the operating system must be communicated to the hardware through the kernel. Windows and Linux each have their own kernels. In a narrow sense, the operating system refers to the kernel, while in a broader sense, it includes the kernel and various applications built on top of it.
(Linus Torvalds is often referred to as the father of Linux, but more accurately, he is the father of the Linux kernel. He continues to oversee the development and maintenance of the Linux kernel. As for Ubuntu and Red Hat, they are based on the same kernel but encompass different applications and interfaces to form a more complete version of the operating system.)
In fact, we can install multiple boot loaders on different partitions, each corresponding to a different operating system, allowing us to choose which boot loader to start when reading the MBR. This is the principle behind multi-boot systems.
Summary: BIOS -> MBR -> Boot Loader -> Kernel
Kernel
If we load the Linux kernel, it begins its operation. The kernel first reserves the memory space it needs to run, then detects the computer’s hardware through drivers. This way, the operating system can know which hardware is available. Next, the kernel starts an init process, which is the first process in the Linux system (there is no process 0 in Linux). At this point, the kernel has completed its tasks during the computer’s startup phase and hands over control to init for management.
Summary: Kernel -> Init Process
Init Process
(Depending on the boot loader’s options, Linux can enter single-user mode at this point. In this mode, the initial scripts have not yet begun executing, allowing us to check and fix any potential errors in the computer.)
Subsequently, init runs a series of startup scripts, which are common shell scripts in Linux. These scripts perform the following functions:
Setting the computer name, time zone, checking the file system, mounting hard drives, clearing temporary files, setting up the network…
Once these startup scripts have executed, the operating system is fully prepared, but no one can log in yet. Init will present a login dialog or a graphical login interface.
Enter the username (for example, vamei) and password, DONE!
In the subsequent process, you will operate the computer as the user (user) vamei. Additionally, based on the settings made when creating the user, Linux will assign you to a specific group (group), which could be the stupid group or the vamei group.
Thus, you will be user vamei, while also being a member of the vamei group. (Note that the group vamei and user vamei are merely coincidentally named, similar to how you can be named Dell while also being the owner of Dell Inc. You can also be user vamei while being a member of the stupid group.)
Conclusion
BIOS -> MBR -> Boot Loader -> Kernel -> Init Process -> Login
User, Group.
Follow ‘Linux Enthusiasts’
See more selected Linux technical articles
↓↓↓
