Linux system startup process

  
        Linux system startup process Linux system from the press of the power button to wait for the user to enter the user name, password, what happened in the middle of this, this article will briefly explain the Linux system startup process. The Linux system startup process is roughly like this: BIOS (Boot Sequence) --> MBR(GRUB,446) --> Kernel --> initrd --> (ROOTFS)/sbin/init(/etc/inittab Let's take a closer look at each of these steps.

1. BIOS
BIOS is an abbreviation of English"Basic Input Output System". After literal translation, the Chinese name is "Basic input and output system". In fact, it is a set of programs that are cured onto a ROM chip on the motherboard inside the computer. After the motherboard is powered on, the BIOS will first gain control of the system. The BIOS first checks the system hardware (POST, Power On Self Test, power-on self-test), and the self-test process is roughly as follows: power-CPU-ROM-BIOS-System Clock-DMA-64KB RAM-IRQ-graphic card. If there is a problem with a critical component, the computer will sound an alarm. After the self-test is normal, the BIOS will call some initialization code in the device's own ROM to initialize these devices, such as the graphics card. At this time, you can see some initialization information, introduce the manufacturer, chip type and so on. Finally, the BIOS will try to start in turn according to the Boot Sequence set in COMS. When the boot device is a hard disk, the BIOS will give control of the system to the bootloader in the hard disk MBR. http://baike.baidu.com/link?url=3u5SmrzMeDuUNAo9rqDc4Vxo8mN0n-7OCLMurOs4yxGXL1ffjnIh0BAsyFm5Elai4ijwxk8dQEVKEHhqWtbHoa

2. MBR
MBR is the shorthand for Master Boot Record, the master boot record. The MBR record is typically on the disk 0 track 1 sector, for a total of 512 bytes. The first 446 bytes are BootLoader. The last 4 bytes of 4*16 are the partition information. The last 2 bytes are the check information, which is usually 55AA. Most Linux systems use GRUB as the BootLoader. GRUB can boot a variety of operating systems, it can identify the format of the disk file system, so only the kernel file name and the kernel partition can load the kernel, configure this information through the /boot/grub/grub.conf style. GRUB is modular and runs through the following phases: The code for Stage 1 Stage1 is stored in the first 446 bytes of the MBR. After the MBR export to a file view # dd if = /dev /sda count = 1 of = /tmp /MBR 1 + 0 records in 1 + 0 records out 512 bytes (512 B) copied, 0.000283544 s, 1.8 MB /s # file /tmp /MBR /tmp /MBR: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x8480e, GRUB version 0.94; partition 1: ID = 0x83, active, starthead 32, startsector 2048, 1024000 sectors; partition 2: ID = 0x8e, starthead 221, startsector 1026048, 82860032 sectors, code offset 0x48 /boot /grub /stage1 stage 1 is unmodified backup code. # File /boot /grub /stage1 /boot /grub /stage1: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, GRUB version 0.94, code offset 0x48 Stage 1_5 Stage1_5 GRUB identification code allows many types of file systems, identification The code for each file system's code is stored in a file in /boot/grub/*stage1_5. # Cd /boot /grub # ls * stage1_5 e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 xfs_stage1_5 fat_stage1_5 jfs_stage1_5 ufs2_stage1_5 ffs_stage1_5 minix_stage1_5 vstafs_stage1_5 Stage 2 Stage 2 code reader /boot/grub/grub.conf file to determine how to load the kernel, Stage2 code stored in the file /boot /grub /stage2 in:. # ls -al /boot /grub /stage2 -rw-r - r-- 1 root root 125976 Jun 28 2012 /boot /grub /stage2

3. Kernel
GRUB of In the final stage, stage2 will load the kernel into memory according to the configuration in the /boot/grub/grub.conf file and give the system control to the kernel.

4. initrd
initrd is an abbreviation for "initial RAM disk", which is loaded into memory by GRUB along with the kernel and is a temporary root file system mounted during system boot. The Linux kernel belongs to a single kernel in design style. The file system, process management, and memory management all need the kernel to complete, which will inevitably cause the kernel code to be very large. In order to reduce the size of the Linux kernel, the Linux kernel is divided into kernel and kernel modules. The kernel dynamically loads kernel modules according to the platform requirements. Non-core functions are usually made into kernel modules, such as most device drivers. This is bound to create conflicts. For example, if there is no module in the Linux kernel that recognizes the ext3 file system, the ext3 module is in the ext3 file system. At this time, the Linux kernel needs to get this module to access the file system, and this module is in the file system. This will show the need to use initrd. The initramfs technology was introduced in the Linux 2.5 kernel. It works like initrd. It is executed by the kernel (initrd is /linuxrc, initramfs is /init). The difference is that /linuxrc is not executed with PID=1, because 1 this process ID is reserved for /sbin/init. After the initrd mechanism finds the real root device, it writes its device number to /proc/sys/kernel/real-root-dev, then controls the transfer to the kernel where it loads the root filesystem and starts /sbin/init. Initramfs mechanism /init is executed with PID=1, the root file system is loaded by init and exec is transferred to the real /sbin/init, which simplifies the startup process and reduces the startup time.

5.init
The /sbin/init process is the first process started by Linux, PID=1. The init process of the Linux system has undergone two major evolutions. The traditional sysvinit has faded out of the historical arena, and the new systems UpStart and systemd have their own characteristics. A main configuration file read by sysvinit is /etc/inittab. The file format reference here mainly defines the settings: 1. Define the default startup level 2. Call rc.sysinit during system initialization. 3. Call the rc script, pass in the runlevel as Parameters, start and close the corresponding level of service 4. ctrl + alt + del combination button action 5. 6 virtual terminal 7. Run level is 5 when the start window display manager and UpStart only keep sysvinit inittab file default start Level, other configurations are scattered across multiple files in /etc/init/*.conf.

<span style="font-size:14px;">[rising@centos ~]$ ls /etc/initcontrol-alt-delete.conf prefdm.conf rcS-emergency.conf readahead-disable- Services.conf tty.confinit-system-dbus.conf quit-plymouth.conf rcS-sulogin.conf serial.confkexec-disable.conf rc.conf readahead-collector.conf splash-manager.confplymouth-shutdown.conf rcS.conf readahead .conf start-ttys.conf</span> The order in which the init program (sysvinit) reads or runs is as follows: init -> inittab -> rc.sysinit -> rc -> rc.local -> mingetty Tty[1-6] -> X11/prefdm /etc/inittab tasks: 1, set the default run level; 2, run the system initialization script; 3, run the script under the specified run level directory; 4, set Ctrl+Alt+Del combination operation; 5. Define the operation performed by the UPS power supply during power failure/recovery; 6. Start the virtual terminal (level 2345); 7. Start the graphics terminal (level 5); /etc/rc The tasks completed by .d/rc.sysinit: 1. Udev and selinux; 2, according to the /etc/sysctl.conf file, to set the kernel parameters; 3, set the clock clock; 4, load the keyboard mapping; 5, enable the swap partition; 6, set the host name; 7, the root file System detection, and re-mounting in read-write mode; 8, activate RAID and LVM devices; 9, enable disk quota; 10, check and mount other file systems according to /etc/fstab; 11, clean up expired locks and PIDs File; /etc/rc.d/rc file
Copyright © Windows knowledge All Rights Reserved