Linux boot guide process and Service Control
Just getting started, are you still confused about how the system runs step by step from the moment we press the power key, knowing that we enter the user name and password to enter the system and operate the computer, today, let's write about the startup process and related service control.
1. System guiding process:
1. Power on, BIOS power on hardware self-check <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> Power-on self-check to detect hardware devices. This is because the BIOS contains CPU information, device startup sequence information, hard disk information, memory information, clock information, and PnP features.
2. Check the startup sequence, boot from the hard disk, and read MBR (446 bytes)
The first sector of the 0th track on the hard disk is called MBR, that is, the Master Boot Record, that is, the Master Boot Record. The size of the first sector is 512 bytes, the task of the primary boot program is to find and load the secondary boot program on the hard disk partition. Search for active partitions in the Partition Table and read the boot loader in the active partition to the memory for running.
3. Read GRUB boot
The main function of the next boot loader is to load the Linux kernel. The next boot loader will guide the operating system. When the machine directs its operating system, the BIOS reads the first 512 bytes (master boot record, master boot record, MBR) on the boot media ). A single MBR can only store boot records of one operating system. Therefore, when multiple operating systems are required, problems may occur, therefore, a more flexible boot loader will run in the memory. The System reads grub configuration information in the memory (generally menu. lst or grub. (lst) the GRUB graphic interface will appear, allowing users to select the kernel to be loaded and start different operating systems according to the configuration information.
To view the MBR content, run the following command: [root @ localhost ~] # Dd if =/dev/sda of = mbr. bin bs = 512 count = 1 # Here/dev/sda is your hard disk type. This time we use scsi, /dev/sda 1 + 0 records in1 + 0 records out512 bytes (512 B) copied, 0.000280189 s, 1.8 MB/s [root @ localhost ~] # Od-xa mbr. bin # The dd command must be run as root to read the first 512 bytes of your first integrated electronic drive or IDE drive and write them into mbr. bim file. the od command prints the binary file in hexadecimal and ASCII code format.
4. Load the Kernel File (under the/boot directory)
After you select the kernel to be loaded, the next boot Loader (GRUB) will be based on/boot/grub. the information set in the conf configuration file reads the Linux kernel image from the/boot/partition, loads the kernel image to the memory, and gives control to the Linux kernel.
5. Running the init process will always be the first process
A. Read the/etc/inittab configuration file.
After the kernel is loaded, the first program to run is/sbin/init (becomes a user process), which reads the/etc/inittab configuration file, init executes corresponding scripts based on the/etc/inittab configuration file for system initialization, such as setting the keyboard, Font, loading module, and network. in fact, the main function of the/etc/inittab file is to set the Linux operating level.
[Run level settings in Linux:] 0-halt (Do NOT set initdefault to this) # shutdown 1-Single user mode # Single user mode 2-Multiuser, without NFS (The same as 3, if you do not have networking) # character interface, multi-user, no Network mode 3-Full multiuser mode # character interface, multi-User Mode 4-unused # reserved, NOT used for the moment 5-X11 # graphical interface, multi-user mode 6-reboot (Do NOT set initdefault to this) # restart
The format is ": id: 3: initdefault:", indicating that Linux runs on level 3.
B. Perform system initialization/etc/rc. d/rc. sysinit
After the running level is set, the first user-layer file executed by Linux is/etc/rc. d/rc. the sysinit script program does a lot of work, including setting PATH, setting network configuration (/etc/sysconfig/network), starting swap partitions, and setting/proc.
C. Control which programs and services to start/etc/rc. d/rc. Based on the running level, execute the corresponding running script according to the current running level.
Depending on the running level, the system will run the corresponding script programs from rc0.d to rc6.d to complete the initialization and start the corresponding service.
D. Run the script/etc/rc. d/rc. local (let the Administrator customize the startup command)
Rc. the local configuration file is a place for users to personalize Linux after all initialization work. You can customize some boot loading settings, only limited to the personal settings used for the current login.
E. Run the/bin/login program and enter the logon status.
When this step is loaded, the system has been running to remind the user to enter the user name and password to log on to the system. So far, so a series of boot processes from powering on the host until you enter the user name and password to log on to the system.
Ii. Service Control and optimization:
Service Category:
Category
|
Features
|
Independent services
|
Fast response, but more system resources are occupied
|
Services that depend on the xinetd service
|
Response is slower, but resource utilization is small
|
System Service Control
1. Common Methods:
-Service name control type-/etc/rc. d/init. d service name control type [root @ localhost ~] #/Etc/init. d/vsftpd status vsftpd is stopped [root @ localhost ~] # Service vsftpd start Starting vsftpd for vsftpd: [OK]
2. Control Type
-Start: start-stop: stop-restart: restart-reload: reload-status: View service status
Linux operating level
1. view the running level
[Root @ localhost ~] # Runlevel 5 3 run the runlevel command, which is displayed as follows: 5: Run level before switchover; 3: Current run level
2. temporarily switch the running level
[Root @ localhost ~] # Init 5 [root @ localhost ~] # Runlevel 3 5 use the init command in combination with the 0-6 running level Parameters
Optimize the Startup Process
1. System Service Management Tools
A) ntsysv Tool
Features: provides an interactive and visualized window for running on character terminals to facilitate centralized management of multiple services
Usage: ntsysv -- level list [root @ localhost ~] # Ntsysv -- level 3 # Set all services with level 3
B) chkconfig Tool
Features: it does not provide interactive and visualized window management for a single service with higher efficiency
Usage: view the startup status of the system service. Format: chkconfig -- list service name [root @ localhost ~] # Chkconfig -- list vsftpd # Check whether vsftpd 0: off 1: off 2: off 3: off 4: off 5: off 6: off # The six statuses here are the running status of linux. "off" indicates that the system is not started. "---------- set the startup status format of system services: chkconfig -- level list service name on | off [root @ localhost ~] # Chkconfig -- level 3 vsftpd on [root @ localhost ~] # Chkconfig -- list vsftpd 0: off 1: off 2: off 3: on 4: off 5: off 6: off ---------- service script location:/etc/init. d ----/etc/rc. d/init. d
So far, do you know how the system starts and how to load the required configuration files at startup, for the starting process of the system, we must master the IT line. After understanding the startup process, when the system goes wrong, we can analyze and solve the problem according to the startup sequence.