CentOS 6 startup process:
POST --> Boot Sequence(BIOS) --> Boot Loader (MBR) --> Kernel(ramdisk) --> rootfs(readonly) –> switchroot --> /sbin/init -->(/etc/inittab, /etc/init/*.conf) --> Set the default run level --> Run the system initialization script to complete the system initialization --> Turn off the services that need to be stopped under the corresponding level, and start the services that need to be turned on under the corresponding level-- > Start the terminal and print the login prompt [–> start the graphical terminal]
(1) POST: Power On and Self Testing
The POST program is stored in the BIOS (Basic Input and Output System) of the ROM chip, which is a CMOS (Complementary Metal Oxide) chip.
ROM+RAM is the storage space accessible by CPU, ROM and physical memory RAM
(2) Boot Sequence
Find each boot device in order, the first device with boot program is the device to be used for this startup.
(3) bootloader: boot loader, is a boot program, bootloader in Windows and Linux:
Windows:ntloader
Linux:
LILO:LInux LOader
GRUB: Grand Uniform Bootloader (Unified Bootloader)
GRUB 0.X:Grub Legacy
GRUB 1.X:Grub2
Bootloader function: Provides a menu that allows users to select the system to be started or a different kernel version, load the kernel selected by the user into a specific space in RAM, decompress and expand, and then transfer system control to the kernel.
(4) MBR: Master Boot Record, master boot record
The MBR is located in the first 512 bytes of the memory. The first 446bytes is the bootloader, the middle 64bytes is the partition table, and the second 2bytes is 55AA. 55AA means the MBR is valid, and non-55AA means the MBR is invalid.
(5)GRUB
GRUB is divided into two stages, as follows:
1 ) The first stage: loading bootloader;
2 ) Stage 1.5: Start the filesystem driver;
3 ) Phase 2: According to the /boot/grub/grub.conf configuration file, partition the disk.
(6) Kernel startup
1 ) Self-initialization
1 Detect all hardware devices that can be identified;
2 Load the hardware driver (may use ramdisk to load the driver);
3 Mount the root file system in read-only mode, and when there is no problem in booting, change to read-write mount to prevent kernel problems and data loss;
4 Run the first application in user space: /sbin/init
(7) Type of init program:
Before CentOS 5-system, it was called SysV init, and the configuration file was /etc/inittab;
The CentOS 6 system is called Upstart, which was developed by Ubuntu. The configuration files: /etc/inittab and /etc/init/ .conf;
The CentOS 7 system is called Systemd, and the configuration files are: /usr/lib/systemd/system/ and /etc/systemd/system/.
(8)ramdisk
One of the characteristics of the Linux kernel: the use of buffers and caches to accelerate access to files on the disk.
The ramdisk of CentOS 5 is called initrd, the tool program is mkinitrd, CentOS 6, CentOS 7 changes the ramdisk to ramfs, their ramdisk is called initramfs, the tool program is dracut and mkinitrd, mkinitrd is a encapsulated SHELL script, or created by dracut .
(9)/sbin/init
CentOS 5: SysV init
Operation level: a mechanism set for the operation or maintenance of the system;
0- 6 : 7 levels;
0 : Shutdown, shutdown or init 0;
1 :Single user mode (single user), root user, no authentication required; maintenance mode; safe mode;
2 :Multi-user mode (multi user), will start network function, but will not start NFS; maintenance mode, safe mode with network function;
3 : Multi-user mode (mutli user), fully functional mode; text interface; normal mode;
4 : Reserved level: There is no special purpose for use at present, but it is used to use the same 3 level functions;
5 : Multi-user mode (multi user), fully functional mode, graphical interface; normal mode;
6 : Restart, reboot
Default level: 3, 5;
Level switching: init #
Level view: who -r
, runlevel
Configuration file: /etc/inittab
Applicable to CentOS 5 system:
Each line defines an action and its corresponding process
id:runlevels:action:process
id: the identifier of a task;
runlevels: at which level to start this task, #, ###, or empty, means all levels;
action: under what conditions start this task;
process: task;
action: define when and how the task starts
wait: Execute once when waiting to switch to the level of this task;
respawn: Once this task is terminated, it will be restarted automatically;
initdefault: set the default run level; at this time, process is omitted;
sysinit: Set the system initialization mode, here is generally designated /etc/rc.d/rc.sysinit script;
For example: /etc/inittab file:
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0 Pass parameter 0
l1:1:wait:/etc/rc.d/rc 1
…………
l6:6:wait:/etc/rc.d/rc 6
It means to start or close the service controlled by the service script in the /etc/rc.d/rc3.d/ directory;
K: The service to be stopped; K##, the priority, the smaller the number, the more priority it is to close; the dependent services are closed first, and then the dependent services are closed;
S: The service to be started; S##*, the priority, the smaller the number, the more priority it is to start; the dependent service is started first, and the dependent service is started later;
For the same service, the number of shutdowns is larger, the number of startups is smaller.
rc script: accept a run level number as a parameter;
Script framework:
for srv in/etc/rc.d/rc#.d/K*;do
$srv stop
done
for srv in/etc/rc.d/rc#.d/S*;do
$srv start
done
/etc/init.d/* (/etc/rc.d/init.d/*) (two directories are links) script execution mode:
# /etc/init.d/SRV_SCRIPT {start|stop|restart|status}``# service SRV_SCRIPT {start|stop|restart|status}
chkconfig command: control the startup or shutdown status of each service script at each level of /etc/init.d/.
View: chkconfig --list [name]
Add: chkconfig --add name
One of the script definition formats of services that can be added:
#! /bin/bash
#
# chkconfig:LLL NN NN runlevel Start priority Shutdown priority
# description:
Delete: chkconfig --del name
Modify the specified link type:
chkconfig [--level LEVELS] name <on|off|reset>
-Level LEVELS: Specify the level to be controlled; the default is 2345;
Note: In the normal level, the last service S99local started is not linked to a script under /etc/init.d, but is linked to the /etc/rc.d/rc.local (/etc/rc.local) script Therefore, programs that are inconvenient or do not need to be written as service scripts can be directly placed in this script file when they are expected to be automatically run on startup.
tty1:2345:respawn:/usr/sbin/mingetty tty1
......
tty6:2345:respawn:/usr/sbin/mingetty tty6
tty7:5:respawn:/etc/X11/
mingetty will call the login program; login is a program used to log in. In addition to mingetty, there are programs such as getty that open virtual terminals.
# systemctl {start|stop|restart|status} name[.service]
Recommended Posts