Article Title: Linux server startup process details. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems and open source, and other basic categories (1) From BIOS to Kernel
BIOS self-check
After the computer is powered On, the BIOS first conducts Self-check, that is, the so-called POST (Power On Self)
Test), and then read the boot block from the hard disk, floppy disk, or CDROM according to the boot sequence set in the BIOS ". In PC, boot Linux starts from the BIOS address 0xFFFF0. The first step of BIOS is power-on self-check (POST ). POST checks the hardware. The second step of BIOS is to enumerate and initialize the local device. Given the different usage of BIOS functions, BIOS consists of two parts: POST code and runtime service. After the POST is completed, it is cleared from the memory, but the service is still kept in the memory during the BIOS runtime, which can be used by the target operating system.
To Boot an operating system, the BIOS searches active and bootable devices in the order defined by the CMOS settings during runtime. The boot device can be a floppy disk, a CD-ROM, a partition on the hard disk, a device on the network, or even a USB flash memory. Generally, Linux boot is from the hard disk. The primary Boot Record (MBR) contains the primary boot loader. MBR is a 512-byte sector located in the first sector of the disk (0-way, 0-way, 1-sector ). When the MBR is loaded into RAM, the BIOS will hand over the control to the MBR.
Extract MBR Information
To view the MBR content, run the following command:
# Dd if =/dev/hda of = mbr. bin bs = 512 count = 1 # od-xa mbr. bin
This dd Command needs to be run as the root user. It reads the content of the first 512 bytes from/dev/hda (the first IDE disk) and writes it to mbr. bin file. The od command prints the contents of the binary file in hexadecimal format and ASCII format.
(2) Start GRUB/LILO
GRUB and LILO are both boot loaders. In the simplest way, the boot loader will guide the operating system. When the machine directs its operating system, the BIOS reads the first 512 bytes (known as the master boot record (MBR) on the boot media )). In a single MBR, only one operating system boot record can be stored. Therefore, when multiple operating systems are required, problems may occur. Therefore, more flexible boot loader is required.
Comparison between GRUB and LILO
As described at the beginning of this article, all boot loaders work in a similar way to achieve a common purpose. However, there are many differences between LILO and GRUB:
- LILO does not have an interactive command interface, but GRUB does.
- LILO does not support network boot, but GRUB does.
- LILO physically stores information about the bootable operating system location in MBR. If you have modified the LILO configuration file, you must rewrite the first-stage boot loader of LILO to MBR. Compared with GRUB, this is a more dangerous option, because wrong configuration of MBR may make the system unable to boot. If GRUB is used, if the configuration file is incorrectly configured, it is only forwarded to the GRUB command line interface by default.
Security tips:
For security, anyone who can access the boot disk/CD can bypass all the security measures mentioned in this article by using grub. conf or lilo. conf without security settings. Especially when GRUB is used, it is a serious security vulnerability because it can be guided to the single-user mode. One easy way to solve this problem is to disable boot through CD and floppy disk in the BIOS of the machine, and ensure that a password is set for the BIOS so that others cannot modify these settings.
(3) load the kernel
After the kernel image is loaded into the memory, the kernel stage begins. The kernel image is not an executable kernel, but a compressed kernel image. Generally, it is a zImage (compressed image, smaller than KB) or a bzImage (larger compressed image, larger than KB). It is compressed using zlib in advance. In front of this kernel image is a routine that implements a small amount of hardware settings, decompress the kernel contained in the kernel image, and then put it into the high-end memory, if an initial RAM disk image exists, it will be moved to the memory and marked for future use. The routine then calls the kernel and starts the kernel boot process.
Manual guidance in GRUB
In the GRUB command line, we can use the initrd image to boot a specific kernel. The method is as follows:
Grub> kernel/bzImage-2.6.14.2
[Linux-bzImage, set = 0x1400, size = 0x29672e]
Grub> initrd/initrd-2.6.14.2.img
[Linux-initrd @ 0x5f13000, 0xcc199 bytes]
Grub> boot
Uncompressing Linux... OK, booting the kernel.
If you do not know the name of the kernel to boot, you only need to use the slash (/) and press the Tab key. GRUB displays the list of kernel and initrd images.
(4) execute the init process
The init process is the starting point of all processes in the system. After the kernel completes the kernel boot, it loads the init program in the current thread (process) space. Its Process number is 1. The init process is the initiator and controller of all processes. In any Unix-based system (such as Linux), The init Process ID (PID) is always 1. If there is a problem with init, the rest of the system will collapse.
The init process has two functions. The first role is to play the role of ending the parent process. Because the init process will never be terminated, the system can always be sure of its existence and take it as a parameter when necessary. If a process is terminated before the end of all its child processes, the init must be used as a reference. At this time, all child processes that have lost their parent processes will use init as their parent processes. Run the ps-af command to list the processes whose Parent Process ID (PPID) is 1.
The second role of init is to run the corresponding program when entering a specific Runlevel to manage various running levels. This function is defined by the/etc/inittab file.
[1] [2] Next page