SYSTEMD startup process

Source: Internet
Author: User

Understanding the Linux boot process

The first process to start is init when we turn on the power of a Linux computer. The PID assigned to the Init process is 1. It is the parent process for all other processes in the system. When a Linux computer starts, the processor looks for the BIOS in the system store, and then the BIOS detects the system resources and then finds the first boot device, usually the hard disk, then looks for the hard drive's master boot Record (MBR), loads it into memory, and gives it control. The subsequent boot process is controlled by the MBR.

The Master boot Record initializes the bootstrapper (there are two well-known boot programs on Linux, Grub and lilo,80% Linux systems are using the Grub Boot program), and grub or LILO loads the kernel modules at this time. The kernel immediately looks for the "init" program under/sbin and executes it. Starting here, Init becomes the parent process of the Linux system. The first file that Init reads is/etc/inittab, which Init will determine the runlevel of our Linux operating system. It looks for the partition table information from the file/etc/fstab and then mounts it accordingly. Init then launches all services/scripts at the default boot level specified in/ETC/INIT.D. All services are initialized here by one of the init. In this process, Init launches only one service at a time, and all service/daemon processes are executed in the background and managed by Init.

The shutdown process is almost the opposite of the process, first Init stops all services, and the final phase uninstalls the file system.

There are some deficiencies in the startup process mentioned above. The need to replace traditional init in a better way has been around for a long time. Many alternatives have also been created. Among the more famous are Upstart,epoch,muda and Systemd. The SYSTEMD has received the most attention and is considered the best solution for the present.
Understanding SYSTEMD

The main purpose of developing SYSTEMD is to reduce system boot time and computational overhead. The SYSTEMD (System Management Daemon), which was first developed under the GNU GPL license, has now been converted to the GNU LGPL Protocol, which is now the most talked-about boot and service management process. If your Linux system is configured to use the Systemd bootloader, it takes the traditional SYSV init, and the boot process is given to SYSTEMD processing. A core feature of the SYSTEMD is that it supports the SYSV init startup script at the same time.

SYSTEMD introduces the concept of parallel start, which establishes a socket for each daemon that needs to be started, which is abstract for the process that uses them, so that they can allow interaction between different daemons. SYSTEMD creates a new process and assigns a control group (Cgroup) to each process. Processes that are in different control groups can communicate with each other through the kernel. The way the boot process is handled by SYSTEMD is pretty, and it's much better than the traditional init-based system. Let's look at some of the core features of SYSTEMD.

    • The bootstrap process simplifies a lot compared to init.
      SYSTEMD supports concurrent boot process for faster boot
      Track processes through control groups, not PID
      Optimizes the way you handle the dependencies between the boot process and the service
      Support for system snapshots and restores
      Monitor services that have been started, and also support restarting crashed services
      Contains the Systemd-login module for controlling user login
      Support for loading and unloading components
      Low memory usage traces and task scheduling capabilities
      Journald module for logging events and SYSLOGD module for recording system logs

Systemd also clearly handles the system shutdown process. It has three scripts in the/usr/lib/systemd/directory, called Systemd-halt.service,systemd-poweroff.service,systemd-reboot.service, respectively. These scripts are executed when the user chooses to shut down, restart, or standby. When a shutdown event is received, SYSTEMD first uninstalls all file systems and stops all memory-swapping devices, disconnects the storage device, and then stops all remaining processes.

SYSTEMD Structure Overview

Let's look at the structural details of the boot-up process of the Linux system when using SYSTEMD as the boot program. For the sake of simplicity, we will follow the steps listed below for this process:

1. The first thing the computer does when you turn on the power is BIOS initialization. The BIOS reads the boot device settings, locates and transmits system control to the MBR (assuming the hard disk is the first boot device).

2. The MBR reads the relevant information from the grub or Lilo bootstrapper and initializes the kernel. The next step is to continue booting the system from grub or Lilo. If you specify SYSTEMD as the boot manager in the Grub configuration file, then the boot process will be completed by SYSTEMD. SYSTEMD uses "target" to handle the boot and service management processes. The "target" files in these systemd are used to group different boot units and start the synchronization process.

3. The first objective of the SYSTEMD implementation is default.target. But actually default.target is a soft link to graphical.target. Soft links in Linux are used in the same way as shortcuts under Windows. The actual location of the file Graphical.target is/usr/lib/systemd/system/graphical.target. The contents of the Graphical.target file are shown below.

4. At this stage, the Multi-user.target is started and the target places its own sub-unit in the directory "/etc/systemd/system/multi-user.target.wants". This target sets the system environment for multi-user support. Non-root users are enabled during this stage of the boot process. Firewall-related services will also start at this stage.

"Multi-user.target" will give control to another layer of "basic.target".

5. The "Basic.target" unit is used to start the General Service, especially the graphics Management Service. It uses the/etc/systemd/system/basic.target.wants directory to determine which services are to be started, and then gives control to Sysinit.target after Basic.target.

6. "Sysinit.target" will launch important system services such as system mounts, memory swap space and devices, kernel supplemental options, and so on. The sysinit.target is passed to Local-fs.target during the boot process. The contents of this target unit are shown in the following surface.

7. Local-fs.target, this target unit does not initiate user-related services, it only handles the underlying core services. This target will perform the operation according to/etc/fstab and/etc/inittab.
System Boot Performance analysis

SYSTEMD provides tools for identifying and locating boot-related issues or performance impacts. Systemd-analyze is a built-in command that can be used to detect the boot process. You can identify the unit that was faulted during startup, and then track and correct the problem with the boot component. Some common systemd-analyze commands are listed below.

Systemd-analyze time is used to show how long the kernel and normal user space are starting to take.

SYSTEMD startup process

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.