In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the startup process of systemd of Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the startup process of systemd of Linux system".
The startup mode of the Linux system is a bit complicated, and there is always room for optimization. The traditional startup process of Linux system is mainly handled by the famous init process (also known as SysV init startup system), while the startup system based on init is considered to be inefficient. Systemd is another startup mode of Linux system machine, which claims to make up for the shortcomings of the system based on traditional Linux SysV init. Here we will focus on the features and controversy of systemd, but to better understand it, we will also take a look at what the Linux startup process looks like with traditional SysV init-based systems. As a reminder, systemd is still in beta, and future releases of the Linux operating system are preparing to replace the current startup process with a systemd startup manager. (as of this publication, many mainstream Linux distributions have adopted systemd.)
Understand the Linux startup process
The first process we started after we turned on the Linux computer was init. The PID assigned to the init process is 1. It is the parent of all other processes in the system. When a Linux computer starts, the processor will first look for BIOS in the system storage, and then the BIOS will detect the system resources and find the first boot device, usually the hard disk, then look for the hard disk's master boot record (MBR), then load it into memory and give it control, and the subsequent startup process will be controlled by MBR.
The master boot record initializes the bootstrap (there are two famous bootstraps on the Linux, GRUB and LILO,80% 's Linux systems are using the GRUB bootstrap), and GRUB or LILO loads the kernel module. The kernel immediately looks for the "init" program under / sbin and executes it. From here on, init becomes the parent process of the Linux system. The first file init reads is / etc/inittab, through which init determines the running level of our Linux operating system. It will look up the partition table information from the file / etc/fstab and mount it accordingly. Init then starts all services / scripts at the default startup level specified in / etc/init.d. All services are initialized here via init one by one. During this process, init starts only one service at a time, and all services / daemons are executed in the background and managed by init.
The shutdown process is almost the opposite. First, init stops all services, and in the final stage, the file system is unmounted.
The startup process mentioned above has some inadequacies. The need to replace traditional init with a better way has been around for a long time. Many alternatives have also emerged. The more famous ones are Upstart,Epoch,Muda and Systemd. Systemd has received the most attention and is considered to be the best solution at present.
Understand Systemd
The main purpose of developing Systemd is to reduce system boot time and computing overhead. Systemd (system management daemon), which was originally authorized under the GNU GPL protocol, has now switched to the GNU LGPL protocol, which is the most hotly discussed boot and service manager today. If your Linux system is configured to use the Systemd bootstrapper, which replaces the traditional SysV init, the startup process will be left to systemd. One of the core features of Systemd is that it also supports post-boot startup scripts for SysV init.
Systemd introduces the concept of parallel startup, which establishes a socket for each daemon that needs to be started. These sockets are abstract to the processes that use them, so that they allow different daemons to interact with each other. Systemd creates new processes and assigns each process a control group (cgroup). Processes in different control groups can communicate with each other through the kernel. The way systemd handles the boot process is beautiful, and it is too optimized compared to traditional init-based systems. Let's look at some of the core functions of Systemd.
Compared with init, the boot process is much simpler.
Systemd supports the concurrent boot process so that it can be started faster
Track progress through control groups, not PID
Optimized ways to handle dependencies between bootstrap processes and services
Support for system snapshots and recovery
Monitor started services; also support restarting crashed services
Contains a systemd-login module to control user login
Support for loading and unloading components
Low memory usage traces and task scheduling ability
Journald module for recording events and syslogd module for recording system logs
Systemd also clearly handles the system shutdown process. It has three scripts called systemd-halt.service,systemd-poweroff.service,systemd-reboot.service in the / usr/lib/systemd/ directory. These scripts are executed when the user chooses to shut down, restart or standby. When a shutdown event is received, systemd first unmounts all file systems and stops all memory swapping devices, disconnects the storage devices, and then stops all remaining processes.
Overview of Systemd structure
Let's take a look at the structural details of the boot process of the Linux system when using systemd as the bootstrap. For simplicity, we will list the process step by step below:
1. When you turn on the power, the first thing the computer does is initialize the BIOS. BIOS reads the boot device settings, locates and transfers system control to MBR (assuming the hard drive is the first boot device).
2. MBR reads the information from the Grub or LILO bootstrapper and initializes the kernel. Next, Grub or LILO will continue to boot the system. If you specify systemd as the boot manager in the grub configuration file, the subsequent boot process will be done 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 goal that systemd executes is default.target. But default.target is actually a soft link to graphical.target. Soft links in Linux use the same shortcuts as shortcuts in 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 in the screenshot below.
4. At this stage, multi-user.target is launched and the target places its subunits in the directory "/ etc/systemd/system/multi-user.target.wants". This target sets the system environment for multi-user support. Non-root users will enable it during this stage of the boot process. Firewall-related services will also be started at this stage.
"multi-user.target" transfers control to another layer of "basic.target".
5. The "basic.target" unit is used to start general services, especially graphics management services. It uses the / etc/systemd/system/basic.target.wants directory to determine which services will be started, and basic.target then gives control to sysinit.target.
6. "sysinit.target" starts important system services such as system mount, memory swap space and devices, kernel supplement options, and so on. Sysinit.target is passed to local-fs.target during startup. The contents of this target unit are shown in the screenshot below.
7. Local-fs.target, this target unit does not start user-related services, it only deals with the underlying core services. This target will perform the relevant operations based on / etc/fstab and / etc/inittab.
System Boot performance Analysis
Systemd provides tools to identify and locate boot-related problems or performance impacts. Systemd-analyze is a built-in command that can be used to detect the boot process. You can find the unit that went wrong 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 the time it takes for the kernel and normal user space to boot.
The code is as follows:
$systemd-analyze time
Startup finished in 1440ms (kernel) + 3444ms (userspace)
Systemd-analyze blame lists all running units, sorted by the time it takes from initialization to the current time, so you know which services take longer to start during the boot process.
The code is as follows:
$systemd-analyze blame
2001ms mysqld.service
234ms httpd.service
191ms vmms.service
Systemd-analyze verify shows whether there are syntax errors in all system units.
Systemd-analyze plot can be used to write the entire boot process to an SVG format file. The whole boot process is very long and not easy to read, so with this command we can write the output to a file and then review and analyze it. That's what the next order is to do.
The code is as follows:
Systemd-analyze plot > boot.svg
The controversy of Systemd
Systemd is not lucky to be popular with everyone, and some experts and administrators disagree on the way it works and develops. According to criticism of Systemd, it is not a "Unix-like" approach because it tries to replace some system services. Some experts also don't like the idea of using binary configuration files. It is said that editing the systemd configuration is very difficult and there is no graphical tool available.
How to test Systemd on Ubuntu 14.04 and 12.04
Originally, Ubuntu decided to replace the current boot process with Systemd starting with Ubuntu 16.04 LTS. Ubuntu 16.04 is scheduled to be released in April 2016, but considering the popularity and needs of Systemd, Ubuntu 15.04 has just been released using it as the default bootstrap. In addition, users of Ubuntu 14.04 Trusty Tahr and Ubuntu 12.04 Precise Pangolin can test Systemd on their machines. The testing process is not complicated, all you have to do is include the relevant PPA into the system, update the warehouse and upgrade the system.
Disclaimer: please note that it is still in the testing and development phase of Ubuntu. Upgrading the test package may cause some unknown errors, which in the worst case may damage your system configuration. Make sure that important data has been backed up before attempting to upgrade.
Run the following command from the terminal to add PPA to your Ubuntu system:
The code is as follows:
Sudo add-apt-repository ppa:pitti/systemd
You will see warning messages because we are trying to use temporary / test PPA, which are not recommended for use on actual working machines.
Then run the following command to update the APT package management repository.
The code is as follows:
Sudo apt-get update
Run the following command to upgrade the system.
The code is as follows:
Sudo apt-get dist-upgrade
That's all. You should already be able to see the Systemd configuration files on your Ubuntu system. Open the / lib/systemd/ directory to see these files.
OK, now let's edit the grub configuration file to specify systemd as the default bootstrap. You can use the Gedit text editor to edit the grub configuration file.
The code is as follows:
Sudo gedit / etc/default/grub
Modify the GRUBCMDLINELINUX_DEFAULT entry in the file and set its parameter to "init=/lib/systemd/systemd"
In this way, your Ubuntu system no longer uses the traditional bootstrap program, but uses the Systemd manager instead. Restart your machine and check the systemd boot process.
Conclusion
There is no doubt that Systemd has taken a big step forward in improving the Linux boot process; it includes a beautiful set of libraries and daemons that work together to optimize the system boot and shutdown process. Many Linux distributions are preparing to use it as their official bootstrap. We will expect to see systemd boot up in future Linux releases. On the other hand, in order to be successful and widely used, systemd still needs to take criticism seriously.
At this point, I believe you have a deeper understanding of the "systemd startup process of the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.