What are the steps required for an operating system to start up completely? Today, take CentOS as an example to explore the Linux startup process;
First, the composition of the Linux system-kernel+rootfs (root file system)
Kernel: Kernel for process management, memory management, network management, drivers, file systems, security functions, etc.
Rootfs: Root file system
1. Kernel design Genre:
Single core (monolithic kernel): Linux
Integrate all functions into the same program
Microkernel (micro kernel): Windows, Solaris
Each feature is implemented using a separate subsystem
2. Linux kernel Features:
Support modularity:. KO (Kernel object)
Such as: File system, hardware driver, network protocol, etc.
Supports dynamic loading and unloading of kernel modules
Part:
Core Files: placed under the/boot/partition vmlinuz-version-release.el[567]. x86_64
Module Files: under the/lib/modules/version/kernel directory
RAMDisk: Auxiliary pseudo-root system for temporary driver when the kernel cannot drive file system;
5:/boot/initrd-2.6.18-398.el5.img
6/7:
/boot/initramfs-2.16.32-573.el6.x86_64.img
/boot/initramfs-3.10.0-327.el7.x86_64.img
Second, the start-up process detailed:
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/9D/35/wKioL1l7TDjA1jGMAACefEYEBR0544.jpg-wh_500x0-wm_ 3-wmp_4-s_2572004550.jpg "title=" 1473580231730780.jpg "alt=" Wkiol1l7tdja1jgmaacefeyebr0544.jpg-wh_50 "/>
The first part is for system initialization of kernel space:
Step1.post:power-on Self Test power-on check
So who's going to perform this test--the answer is that only the CPU can perform the operation, of course.
There is no data on the memory as soon as the power is switched on. Therefore, the ROM on the motherboard of the x86 architecture can supply such data;
The chip on the motherboard: South Bridge Chip. The contents of ROM memory can be mapped directly into memory, which allows the CPU to read and load instructions and data;
So we can say that the X86 architecture of the CPU can linearly address the physical storage space: ROM + RAM;
Step2.bootsequence: Can be understood as the boot sequence;
The first step self-test is successful and can be run normally. The system should go to find the hardware device containing the operating system, complete the system boot;
And Bootsequence's role is: decide to what kind of hardware device to load the operating system; is removable device? or hard drive, CD-ROMs? or network boot?
And the loading method is: in the specified order to find each boot device, the first to find a device with a boot program is the device used to start this time;
Bootloader: bootloader, also a program, 0 tracks 0 sectors that exist on the hard disk have a total of 512 bytes, where
446B bootloader
64B FAT Partition Table
The remaining 2 bytes 55AA is the closing tag
So, what are the bootloader?
In Windows is NTLDR, full name is NT Loader, is the system loader program;
Linux:
1.LILO (Linux Loader): An early boot program, to the current location is also a very extensive use of a bootloader. But it is not used in our computer, because it does not support large hard disk boot (no more than 1024 cylinders); Android phones are usually used for this;
2.GRUB (GRand Uniform Bootloader): The general architecture is on the server and the normal PC; it can also boot Unix or even Windows (before 8);
GRUB provides the functionality:
1. Provide a menu for the user, the menu is listed in each of the operating system can be activated kernel;
2. The core files of the user-selected kernel can be loaded into memory, decompressed and expanded, and grub transfers control of the system to the kernel;
3. Provide an interactive command-line interface;
4. Provide the menu and kernel boot security;
Step3. Initialization of the kernel itself:
1) Detect all the hardware devices that can be identified
2) load the hardware driver; You may need to use the RAMDisk
3) Mount the root file system in read-only mode
4) The first application running user space/sbin/init
Types of Step4.init Programs
CentOS 5 and before, SysV init-classic Init; config file:/etc/inittab only this one
CentOS 6:upstart init config file:/etc/inittab but almost obsolete! The only function is to set the boot level, which will be said later that the rest of the configuration files are/etc/init/*.conf
CentOS 7: Completely obsolete inittab files, but still exist, simply stating that CentOS 7 is not using this file but using a new systemd way; its configuration file/usr/lib/systemd/system/*
/etc/systemd/system/*
The second part is the opening of the user space:
Kernel after loading the first program init program, the INIT process takes over the task of the process management
STEP1: Set the operating level of the system--runlevel
Indicates the level at which the action of the process is to be run, in which multiple runlevel can be defined.
0: Shutdown
1: Represents the single user mode, in this mode, the user login does not require a password, the default NIC driver is not load, some services can not be used 2: Multi-user mode, NFS service does not open
3, indicating command-line mode
4, this mode remains unused
5, indicating graphical user mode
6, which means rebooting the system
Commonly used is 3 and 5,0 and 6 caution, 1 of single-user mode is a system and its dangerous mode, so it is only in like the root user password forgotten after the use of the mode;
Examples of CentOS 5–/etc/inittab content:
Id:3:initdefault: # Defines the default run level
Si::sysinit:/etc/rc.d/rc.sysinit # System Initialization script
L0:0:WAIT:/ETC/RC.D/RC 0 # Startup scripts for different run levels
L1:1:WAIT:/ETC/RC.D/RC 1 ...
L6:6:WAIT:/ETC/RC.D/RC 6
Ca::ctrlaltdel:/sbin/shutdown-t3-r now #定义快捷键操作
# Press the shortcut key to restart the system after 3 seconds
CentOS6, no other content has been defined, and the default boot-up process has been entered, and the following script has been switched to complete Original Execution Action
STEP2: Execute/etc/rc.d/rc.sysinit script, implement system initialization;
/etc/rc.d/rc.sysinit: Init relies on/rc.sysinit for system initialization at all RunLevel
Role:
(1) Set host name
(2) Setting welcome information
(3) Activate Udev and SELinux
(4) Mount the file system defined in the/etc/fstab file
(5) Detecting the root file system and re-mounting the root filesystem in read and write mode
(6) Setting the system clock
(7) Activate swap device
(8) Set kernel parameters according to/etc/sysctl.conf file
(9) Activating LVM and software RAID devices
(10) Loading drivers for additional devices
(11) Cleaning operation
Step3.rc Script--links to all services in the/etc/rc.d/rc$runlevel.d/directory--all services that start with K are stopped, and the service opening begins with S
Description: Rc$runlevel.d–> means reading the/etc/rc.d/rc#.d/script
(All files in the directory are soft links, the source is the corresponding script under INIT.D)
k*: k##*: # #运行次序; The smaller the number, the more it runs; the smaller the number of services, usually dependent on other services
s*: s##*: # #运行次序; The smaller the number, the more it runs; the smaller the number of services, usually the services to be relied upon
Step4. Use the Mingetty command to invoke the login program to print a login prompt for the user;
Linux system Boot process (CENTOS5/6/7 as an example)