Centos7 Startup Process and systemd are described in detail.

Source: Internet
Author: User

Centos7 Startup Process and systemd are described in detail.
Start Process

POST-> boot sequence-> BOOTLOADER-> KERNEL + INITRAMFS (INITRD)-> ROOTFS->/sbin/init

POST: power-on self-check

After the power button is pressed, the computer starts to power up. The BIOS or UEFI Basic Input/Output program on the motherboard starts to check the hardware and check the memory and CPU, when an error is detected, the machine may be interrupted or cannot be started. Anyone who has performed computer maintenance knows that the memory oxidation can be exported to the machine, some other machines will not pass the self-check without a mouse or keyboard, and will not go down.

Boot sequence: select the Boot sequence

After the self-check is passed, you need to select the boot media or mode, which is started through the CD, hard disk, network, or USB flash disk. These are also set in BIOS, therefore, the first boot item is set to start from which to boot, which is familiar with WINDOWS installation.

Bootloader: Boot Loader

After determining the boot medium, start to load the boot program from the medium, such as grub2. This is a tiny program. We know that the MBR Boot Record size is 512 bytes, and the first 446 bytes are Bootloader, it is mainly used to guide users to select the system to be started or different kernel versions, load the selected kernel to a specific space in RAM, decompress, expand, and then hand over control of the system to the kernel.

Grub2 is the Bootloader program in Linux. Due to MBR record restrictions, grub2 is divided into two parts:

1. In the MBR Boot Record, the size is 446 bytes. The main function is to boot the grub main file of the media.

2. partition,/boot/grub [2], which is the subject of grub.

KERNEL + INITRAMFS (INITRD)-> ROOTFS: load the KERNEL

At this time, the kernel starts initialization, detects recognizable hardware devices, and loads the hardware Startup Program. Load the root file system in read-only mode

When the kernel is loaded in the memory, a ramdisk file is generated to simulate the system environment to perform the next operation. When it is loaded to the real root file system, it will exit ramdisk, switch to the real root file system.

Ramdisk: temporary virtual system in memory

Ramdisk (Virtual Disk, dual buffer, dual cache) ----> ramfs (Virtual File System)

Centos5: initrd

Tool: mkinitrd

Centos6, 7: initramfs

Tool: dracut, mkinitrd

/Sbin/init: run the first application in the user space.

Init:

Centos 5: SysV init configuration file:/etc/inittab

Centos 6: Upstart configuration file:/etc/inittab;/etc/init/*. conf (main)

Centos 7: systemd configuration file:/etc/systemd/system;/usr/lib/systemd/system

So far, the kernel space has been started, the kernel has been started, and the user-mode startup process starts. Systemd is a daemon and pid number is 1. All the services or processes started later are subprocesses of systemd and subprocesses Of The subprocesses.

What is the startup sequence of user mode?

Set the default allowable level-> initialization script to complete system initialization ---> close and start services at the corresponding level -----> set logon terminal -----> [start a graphical terminal]

 

New Features of Systemd:

Services are started in parallel during system guidance, with no order

Activate processes as needed

Supports system status snapshots.

Define Service Control Logic Based on dependency
Key features:

Socket-based activation mechanism: the socket is separated from the service program. The program or service is activated as needed and can be started in parallel.

Bus-based activation mechanism:

Device-based activation mechanism: a device can be activated when a hardware device becomes available.

Path-based activation mechanism

System Snapshot: saves the current status information of each unit on persistent storage devices.

Backward compatible with the sysv init script

Incompatible:

The systemctl command is fixed and cannot communicate with services not started by systemd.

Core Concept: unit

The configuration file is marked and configured. The file mainly contains the system service, monitoring socket, stored system snapshots, and other init-related information, and is saved:

/Usr/lib/systemd/system

/Run/systemd/system

/Etc/systemd/system

Unit Type

Service unit: the file extension. service does not require execution permissions. It is used to define system services.

Target unit: the file extension name is .tar get, which is used to simulate the implementation of "running level"

Device unit: the file extension is. device, which is used to define the Device recognized by the kernel.

Mount unit: Specifies the mount point of the file system. The file extension is. Mount.

Socket unit: Specifies the socket file used for inter-process communication. The file extension is. socket.

Snapshot unit: the file extension is. snapshot to manage system snapshots.

Swap unit: the file name extension is. swap, used to identify the swap device.

Automount unit: the file extension is. automount, which indicates the automatic mount point of the file system.

Path unit: the file extension is. path, which defines a file or directory in the file system.

Manage System Services

Start: systemctl start name. service

Stop: systemctl stop name. service

Restart: systemctl restart name. service

Heavy Load: systemctl reload name. service

Conditional restart: systemctl try-restart name. service

Check whether a service is running: systemctl is-active name. service

View all activated services: systemctl list-units-type service -- all

Auto Start: systemctl enable name. service

Do not start: systemctl disable name. service

View auto-start status of all services: systemctl list-unit-files -- type service

Check whether the service starts automatically: systemctl is-enabled name. service

View service dependencies: systemctl list-dependencies name. service

Disable auto start: systemctl mask name. service

Disable auto start: systemctl unmask name. service

 

Target units: (simulated operation level)

Unitconfiguration file, ending with a. tar get suffix name

Shutdown: runlevel0.target,poweroff.tar get

Rescue: runlevel1.target,rescue.tar get

User: multi-user.target

Image: graphical.tar get

Restart: reboot.tar get

Level switch: systemctl isolate name.tar get

View level: systemctl list-units -- type target systemctl get-default

Set level: systemctl set-default name.tar get

Switch to emergency rescue mode: systemctl rescue

Switch to emergency mode: systemctl emergency (the service is not loaded, the driver is not loaded, and more thorough)

Other common commands

Shutdown: systemctl halt, systemctl poweroff

Restart: systemctl reboot

Pending: systemctl suspend

Snapshot: systemctl hibernate

Snapshot and suspension: systemctl hybrid-sleep

Related Article

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.