CentOS System Startup Process
CentOS System Startup Process
POST: power-on self-check;
ROM: CMOS
BIOS: Basic Input and Output System
ROM + RAM
BOOT Sequence:
Find the boot devices in order. The first device with a boot program is used for this start;
Bootloader: Boot Loader, Program
Windows: ntloader
Linux:
LILO: LInux LOader
GRUB: GRand Uniform Bootloader
GRUB 0.X: GRUB Legacy
GRUB 1.x: GRUB2
Function: provides a menu that allows you to select the system to start or different kernel versions. It loads the selected kernel to a specific space in the memory, decompress and expand it, and hand over control of the system to the kernel;
MBR:
446: bootloader
64: fat
2: 55AA
GRUB:
Bootloader: 1st stage
Disk: 2nd stage
Kernel:
Self-initialization:
Detects all recognizable hardware devices;
Load the hardware driver. (The driver may be loaded by using ramdisk)
Mount the root file system in read-only mode;
Run the first application of the user space:/sbin/init
Init program type:
SysV: init, CentOS 5
Configuration File:/etc/inittab
Upstart: init, CentOS 6
Configuration File:/etc/inittab,/etc/init/*. conf
Systemd: systemd, CentOS 7
Configuration File:/usr/lib/systemd/system,/etc/systemd/system
Ramdisk:
One of the features in the kernel: use buffering and caching to access files on the disk;
Ramdisk --> ramfs
CentOS 5: initrd, tool program: mkinitrd
CentOS 6: initramfs, tool program: mkinitrd, dracut
System initialization:
POST --> BootSequence (BIOS) --> Bootloader (MBR) --> kernel (ramdisk) --> rootfs (read-only) --> init
/Sbin/init
CentOS 5:
Running level: set for the purpose of running or maintaining the system;
0-
0: Shutdown
1: single user mode (root, No Logon required), single, maintenance mode;
2: in multi-user mode, network functions are enabled, but NFS is not enabled. In maintenance mode;
3: multi-user mode, normal mode; text interface;
4: Reserved level; can be at the same level as 3;
5: multi-user mode, normal mode; GUI;
6: restart
Default level:
3, 5
Switch Level:
Init #
View level:
Runlevel
Who-r
Configuration File:/etc/inittab
Each row defines an action and the corresponding process
Id: runlevel: action: process
Action:
Wait: switch to this level to run once;
Respawn: Terminate the process and restart it;
Initdefault: sets the default running level; process is omitted;
Sysinit: sets the system initialization method. In this example, the/etc/rc. d/rc. sysinit parameter is specified;
...
[Root @ slave ~] # Ll/etc/rc. d/
Total 60
Drwxr-xr-x. 2 root 4096 Jan 29 2015 init. d
-Rwxr-xr-x. 1 root 2617 Oct 16 2014 rc
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc0.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc1.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc2.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc3.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc4.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc5.d
Drwxr-xr-x. 2 root 4096 Jan 31 2015 rc6.d
-Rwxr-xr-x. 1 root 259 Jul 31 00:53 rc. local
-Rwxr-xr-x. 1 root 19914 Oct 16 2014 rc. sysinit
Id: 3: initdefault:
Si: sysinit:/etc/rc. d/rc. sysinit
L0: 0: wait:/etc/rc. d/rc 0
L1: 1: wait:/etc/rc. d/rc 1
...
L6: 6: wait:/etc/rc. d/rc 6
Note: rc 0 --> means reading/etc/rc. d/rc0.d/
K *: K ###*: # running sequence; smaller numbers, the more advanced the running; services with smaller numbers are usually dependent on other services;
S *: S ###### running sequence; smaller numbers, the more advanced the running; services with smaller numbers are usually dependent on;
For srv in/etc/rc. d/rc0.d/K *; do
$ Srv stop
Done
For srv in/etc/rc. d/rc0.d/S *; do
$ Srv start
Done
[Root @ slave ~] # Ll/etc/rc. d/init. d/
Total 356
-Rwxr-xr-x. 1 root 1288 Oct 16 2014 abrt-ccpp
-Rwxr-xr-x. 1 root 1628 Oct 16 2014 abrtd
-Rwxr-xr-x. 1 root 1642 Oct 16 2014 abrt-oops
-Rwxr-xr-x. 1 root 1725 Aug 18 2010 acpid
-Rwxr-xr-x. 1 root 2062 Jan 30 2012 atd
-Rwxr-xr-x. 1 root 3580 Oct 15 2014 auditd
-R-xr-x. 1 root 1340 Oct 15 2014 blk-availability
-Rwxr-xr-x. 1 root 710 Nov 10 2010 bluetooth
-Rwxr-xr-x. 1 root 11355 Aug 13 2013 cpuspeed
-Rwxr-xr-x. 1 root 2826 Nov 23 2013 crond
-Rwxr-xr-x. 1 root 3034 Oct 15 2014 cups
-Rwxr-xr-x. 1 root 1734 Jun 16 2014 dnsmasq
-Rwxr-xr-x. 1 root 3245 Jul 9 2013 firstboot
-Rw-r --. 1 root 19295 Jul 22 2014 functions
-Rwxr-xr-x. 1 root 1801 Oct 15 2014 haldaemon
-Rwxr-xr-x. 1 root 5866 Jul 22 2014 halt
-Rwxr-xr-x. 1 root 2001 Oct 16 2014 htcacheclean
-Rwxr-xr-x. 1 root 3371 Oct 16 2014 httpd
-Rwxr-xr-x. 1 root 10804 Oct 15 2014 ip6tables
-Rwxr-xr-x. 1 root 10688 Oct 15 2014 iptables
-Rwxr-xr-x. 1 root 1938 Jun 2 2014 irqbalance
-Rwxr-xr-x 1 root 9980 Dec 18 2014 jexec
-Rwxr-xr-x. 1 root 19476 Oct 15 2014 kdump
-Rwxr-xr-x. 1 root 652 Jul 22 2014 killall
-R-xr-x. 1 root 2134 Oct 15 2014 lvm2-lvmetad
-R-xr-x. 1 root 2757 Oct 15 2014 lvm2-monitor
-Rwxr-xr-x. 1 root 2571 Sep 4 2014 mdmonitor
-Rwxr-xr-x. 1 root 2200 Sep 13 2012 messagebus
-Rwxr-xr-x. 1 root 2989 Jul 22 2014 netconsole
-Rwxr-xr-x. 1 root 6064 Jul 22 2014 netfs
-Rwxr-xr-x. 1 root 6334 Jul 22 2014 network
-Rwxr-xr-x. 1 root 2205 Oct 15 2014 NetworkManager
-Rwxr-xr-x. 1 root 1923 Jul 15 2013 ntpd
-Rwxr-xr-x. 1 root 2043 Jul 15 2013 ntpdate
-Rwxr-xr-x. 1 root 2023 Apr 3 2012 portreserve
-Rwxr-xr-x. 1 root 3912 Feb 20 2014 postfix
-Rwxr-xr-x. 1 root 1556 Jul 17 2012 psacct
-Rwxr-xr-x. 1 root 2034 Mar 5 2014 quota_nld
-Rwxr-xr-x. 1 root 1513 Sep 17 2013 rdisc
-Rwxr-xr-x. 1 root 1822 Oct 15 2014 restorecond
-Rwxr-xr-x. 1 root 1808 Dec 17 2011 rngd
-Rwxr-xr-x. 1 root 2011 Aug 15 2013 rsyslog
-Rwxr-xr-x. 1 root 1698 Oct 15 2014 sandbox
-Rwxr-xr-x. 1 root 2056 Jun 23 2014 saslauthd
-Rwxr-xr-x. 1 root 647 Jul 22 2014 single
-Rwxr-xr-x. 1 root 3002 Feb 21 2013 smartd
-Rwxr-xr-x. 1 root 2162 Sep 14 2014 snmpd
-Rwxr-xr-x. 1 root 1738 Sep 14 2014 snmptrapd
-Rwxr-xr-x. 1 root 2472 Oct 15 2014 spice-vdagentd
-Rwxr-xr-x. 1 root 4621 Oct 15 2014 sshd
-Rwxr-xr-x. 1 root 1144 Oct 16 2014 sysstat
-Rwxr-xr-x. 1 root 2294 Oct 15 2014 udev-post
-Rwxr-xr-x. 1 root 39800 Jan 27 2015 vmware-tools
-Rwxr-xr-x. 1 root 15208 Jan 27 2015 vmware-tools-thinprint
-Rwxr-xr-x. 1 root 1674 Feb 21 2013 wdaemon
-Rwxr-xr-x. 1 root 1608 Oct 15 2014 winbind
-Rwxr-xr-x. 1 root 1866 Feb 4 2013 wpa_supplicant
Chkconfig command
View the startup or shutdown settings of a service at all levels:
Chkconfig [-- list] [name]
[Root @ slave ~] # Chkconfig -- level 3 NetworkManager on
[Root @ slave ~] # Chkconfig -- list
[Root @ slave ~] # Chkconfig -- level 3 NetworkManager off
Add:
SysV service scripts are stored in/etc/rc. d/init. d (/etc/init. d)
Chkconfig -- add name
#! /Bin/bash
#
# Chkconfig: LLLL nn
Chkconfig: 2345 10 90
Delete:
Chkconfig -- del name
Modify the specified link type
Chkconfig [-- level levels] name <on | off | reset>
-- Level LLLL: Specifies the level to be set. If this parameter is omitted, the value 2345 is used;
Note: At the normal level, the last service S99local started is not linked to/etc/rc. d/init. d. A service script pointing to/etc/rc. d/rc. therefore, it is inconvenient or unnecessary to write the service script to/etc/rc. d/init. d/directory, and want to automatically run the command at startup, can be placed directly in/etc/rc. d/rc. local file;
[Root @ slave ~] # Ll/etc/rc. local
Lrwxrwxrwx. 1 root 13 Jan 27 2015/etc/rc. local-> rc. d/rc. local
Tty1: 2345: respawn:/usr/sbin/mingetty tty1
Tty2: 2345: respawn:/usr/sbin/mingetty tty2
...
Tty6: 2345: respawn:/usr/sbin/mingetty tty6
Mingetty will call the login program
/Etc/rc. d/rc. sysinit: system initialization script
(1) set the host name;
(2) set the welcome information;
(3) Activate udev and selinux;
(4) mount the file system defined in the/etc/fstab file;
(5) Check the root file system and remount the root file system in read/write mode;
(6) set the system clock;
(7) activate the swap device;
(8) set kernel parameters according to the/etc/sysctl. conf file;
(9) Activate lvm and software raid devices;
(10) load the driver of the additional device;
(11) Cleanup operations;
Conclusion:/sbin/init --> (/etc/inittab) --> set the default running level --> run the system initial script, complete system initialization --> close the services to be closed, start the service. --> set the logon terminal.