Linux system startup process

Source: Internet
Author: User

Linux system Boot Process  linux system from pressing the power button to wait for the user to enter the user name, password, what happened in the middle, this article will briefly explain the Linux system startup process. The  linux system boot process is roughly like this:  bios (boot Sequence)---MBR (GRUB)---Kernel----INITRD Init (/etc/inittab)   Here's a detailed look at each of these steps.  1. Bios bios is the abbreviation for "Basic Input Output system" in English, and the Chinese name is "basic import and export" after translation. In fact, it is a set of programs that solidify onto a ROM chip on the motherboard of a computer. Once the motherboard is plugged in, the BIOS will be the first to gain control of the system. The BIOS will first detect the system hardware (POST, power on self test, power-on from the test), the self-detection process is roughly: Power-cpu-rom-bios-system clock-dma-64kb ram-irq-graphics card and so on. If there is a problem with the critical part, the computer emits an alarm sound. Self-Test after everything is OK, the BIOS invokes some initialization code in the device's own ROM to initialize the devices, such as a video card. At this point you can see some initialization information, introduction of manufacturers, chip types and other content. Finally, the BIOS will attempt to start in turn based on the boot sequence set in COMs (boot Sequence). When the boot device is a hard disk, the BIOS will give the system control to the bootloader in the hard disk MBR.  2. MBRMBR is the shorthand for the master boot record, which is the master boot recording. MBR records generally in Disk 0 tracks 1 sectors, a total of 512 bytes. The first 446 bytes are bootloader (boot program), after 4*16 64 bytes is the storage partition information, the last 2 bytes is the checksum information, generally 55AA. Most Linux systems use grub as a bootloader. Grub can boot a variety of operating systems, it can recognize the format of the disk file system, so only the kernel file name and the kernel partition to load the kernel, through the/boot/grub/grub.conf style to configure the information. Grub is modular and runs through the following stages:  stage 1    STAGE1 code is saved in the first 446 bytes of the MBR. The MBR guidePost-File View   [Plain]View PlainCopy
  1. # dd IF=/DEV/SDA count=1 OF=/TMP/MBR
  2. 1+0 Records in
  3. 1+0 Records out
  4. Bytes (+ B) copied, 0.000283544 s, 1.8 MB/s
  5. # FILE/TMP/MBR
  6. /tmp/mbr:x86 boot sector; GRand Unified Bootloader, stage1 version 0x3,
  7. Boot drive 0x80, 1st sector Stage2 0x8480e, GRUB version 0.94;
  8. Partition 1:id=0x83, active, Starthead, startsector 2048, 1024000 sectors;
  9. Partition 2:id=0x8e, Starthead 221, Startsector 1026048, 82860032 sectors,
  10. Code offset 0x48
/boot/grub/stage1 is a code backup that is not modified on stage 1. [Plain]View PlainCopy
    1. # File/boot/grub/stage1
    2. /boot/grub/stage1:x86 boot sector; GRand Unified Bootloader, stage1 version 0x3,
    3. GRUB version 0.94, code offset 0x48
The code for Stage 1_5 Stage1_5 allows grub to recognize multiple types of file systems, and the code that identifies each file system is saved in the/boot/grub/*stage1_5 file. [Plain]View PlainCopy
    1. # Cd/boot/grub
    2. # ls *stage1_5
    3. E2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 xfs_stage1_5
    4. Fat_stage1_5 jfs_stage1_5 ufs2_stage1_5
    5. Ffs_stage1_5 minix_stage1_5 vstafs_stage1_5
Stage 2 Stage 2 code reads the/boot/grub/grub.conf file, determines how to load the kernel, Stage2 code is saved in the file/boot/grub/stage2: [Plain]View PlainCopy
    1. # LS -AL /BOOT/GRUB/STAGE2  
    2. -rw-r--r--.  1  root root 125976 jun 28  2012 /boot/grub/stage2  
3. The final phase of the Kernelgrub stage2 will load kernel into memory based on the configuration in the/boot/grub/grub.conf file and give the system control to kernel.  4. INITRDINITRD is the abbreviation for "Initial RAM disk", which is loaded into memory by grub with kernel and a temporary root filesystem mounted during system boot.  linux kernel is a single core in design style, file system, process management, memory management all need the kernel to complete, this will inevitably cause the kernel code is very large. To reduce the size of the Linux kernel, the Linux kernel is partitioned into kernel and kernel modules, and the kernel dynamically loads the kernel modules according to the platform, and non-core functions are usually made into kernel modules, such as most device drivers. This is bound to create contradictions, for example, if the Linux kernel does not have integrated modules to identify the Ext3 file system, while the Ext3 module is in the Ext3 file system. At this point, the Linux kernel accesses the file system to get the module, and this module is in the file system. This will see the need to use INITRD.   started introducing INITRAMFS technology in the Linux 2.5 kernel, similar to INITRD, which is a program on which   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. The INITRD mechanism locates the real root device and writes its device number to/proc/sys/kernel/real-root-dev, then controls the transfer to the kernel, which mounts the root filesystem and initiates/sbin/init. In the INITRAMFS mechanism,/init is executed with pid=1, the root filesystem is loaded by init, and exec goes to the real/sbin/init, which simplifies the startup process and reduces startup time. The  5.init/sbin/init process is the first process that Linux starts, pid=1. The init process of the Linux system has undergone two major evolutions, the traditional sysvinit has faded out of the historical stage, and the new system is widely used  upstart and systemd.  sysvinit read a master profile is/etc/inittab, file format reference here, Inittab files are mainly completed with the configuration:    1. Define the default startup level     2. System initialization Phase Call Rc.sysinit    3. Call the RC script, pass in RunLevel as parameters, start and close the corresponding level of service     4. Ctrl+alt+del Combo button action     5. 6 Virtual terminals     7. When the run level is 5, Startup window display manager   Upstart only retains the default boot level in the Sysvinit Inittab file, and other configurations are scattered across/etc/init/*.conf files.   [Plain]View PlainCopy
  1. [Email protected] ~]$ Ls/etc/init
  2. control-alt-delete.conf prefdm.conf rcs-emergency.conf readahead-disable-services.conf tty.conf
  3. init-system-dbus.conf quit-plymouth.conf rcs-sulogin.conf serial.conf
  4. kexec-disable.conf rc.conf readahead-collector.conf splash-manager.conf
  5. plymouth-shutdown.conf rcs.conf readahead.conf start-ttys.conf

The sequence of files read or run by the INIT program (SYSVINIT) is as follows: Mingetty tty[1-6, RC, rc.local, Rc.sysinit, Inittab, Init, and so on /prefdm/etc/inittab's Mission:
1, set the default operating level;
2, run the system initialization script;
3. Run the script in the directory corresponding to the specified run level;
4, set the operation of Ctrl+alt+del combination key;
5, define the UPS power supply in the power failure/recovery operation performed;
6, start the virtual terminal (2,345 level);
7, start the graphics terminal (5 level);/etc/rc.d/rc.sysinit Completed tasks:
1. Activate Udev and SELinux;
2, according to the/etc/sysctl.conf file, to set the kernel parameters;
3, set the clock clock;
4, loading keyboard mapping;
5, enable the swap partition;
6, set the host name;
7, the root file system detection, and read-write mode to re-mount;
8. Activate RAID and LVM devices;
9, enable disk quotas;
10, according to/etc/fstab, check and mount other file system;
11, clean up the expired lock and PID file;/ETC/RC.D/RC file
Like the shell code below, is responsible for running the specified run level corresponding to the directory of the script, accept a parameter as the runlevel for I in/etc/rc$1.d/k*; Do
$I stop
Done

For I in/etc/rc$1.d/s*; Do
$I start
Done

Priority of closing or starting, the smaller the data, the higher the priority is selected
Turn off the service starting with K and start the service starting with S;/etc/rc.d/rc.local:
A script that was last executed by the system. It is generally linked to s99local, and is executed by/ETC/RC.D/RC footsteps. The Mingetty inittab file defines the programs that run on multiple virtual terminals. Mingetty will start the login program for authentication. Copyright NOTICE: This article for Bo Master toormi original article, reprint need to indicate the source. 47957567

Linux system startup process

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.