Linux system start-up mode a bit complicated, but there is always a need for optimization. The traditional Linux boot process consists of the famous init process (also known as SysV init boot system) process, but based on the init boot system is thought to have insufficient efficiency, systemd Linux system machine is another way to start, He claims to make up for the shortcomings of traditional Linux SysV init-based systems. Here we will focus on systemd features and controversy, but in order to understand it better, will look at the Linux boot process to the traditional SysV init system is based on what. Friendly reminder, systemd is still in the testing phase, and future releases of the operating system Linux are preparing to replace the current boot process with systemd Startup Manager (LCTT Annotation: As of this writing, the mainstream Linux distributions have a lot of uses systemd).
Understanding the Linux boot process
After we open the Linux computer's power first enabled process is init. PID is assigned to the init process 1. It is the parent of all other processes in the system. When a Linux computer starts up, the processor will first look in the system storage BIOS, then BIOS will detect the system resources and then find the first boot device, usually a hard disk, and then looks for hard disk's master boot record (MBR), then loaded into memory and transfers control to it, after the startup process is controlled by the MBR.
The master boot record is initialized boot program (there are two well-known on the Linux boot loader, GRUB and LILO, 80% of the Linux system with the GRUB boot loader), this time the GRUB or LILO will load the kernel module. The kernel will immediately look for / sbin under the "init" program and execute it. From here to become a parent process init Linux System. Init reads the first file is / etc / inittab, init will be determined by which level we run the Linux operating system. It looks for the partition table information from the file / etc / fstab Lane then mount accordingly. Then init starts /etc/init.d specified default start level in all services / scripts. All services here one by one is initialized by init. In this process, init a time to start a service, all services / processes are executed by the init daemon in the background to manage.
The shutdown process is almost the reverse process, init first stop all services, the final stage will unmount the file system.
Start the process mentioned above, there are some inadequate. But with a better way to replace the traditional init requirements already exist for a long time. Also produced a number of alternatives. The more famous are Upstart, Epoch, Muda and Systemd. The Systemd received the most attention and is considered to be the best solution.
The main purpose is to reduce the development Systemd system boot time and computational overhead. Systemd (system management daemon), beginning with GNU GPL agreement authorizing the development, is now switching to GNU LGPL agreement, it is now the most enthusiastic discussion guide and service management procedures. If your Linux system is configured to use Systemd boot program, which replace the traditional SysV init, the boot process will give systemd process. Systemd a core feature is its support SysV init script after boot.
Systemd introduced the concept of parallel starts, it creates a socket for each need to start daemons, these sockets for the use of their process is abstract, so that they can allow interaction between different daemon . Systemd creates a new process and assign a control group (cgroup) for each process. Can communicate with each other through the kernel is different between the control group processes. systemd process boot process approach is very beautiful, and traditional-based init system optimization compared too. Let's look at some of the core functions Systemd.
And init boot process is simplified compared to a lot of
Systemd support concurrent boot process which can quickly start
By controlling the group to track the process, instead of PID
Optimization of the boot process and dependence between the processing service way
Snapshots and recovery support system
Monitor has started service; also supports restarting the service has crashed
It contains login systemd-login module for controlling user
Support for loading and unloading assembly
Low memory usage traces, and task scheduling capabilities
syslogd module Journald modules and recording system log records events
Systemd also clearly addressed the system shutdown process. It has three scripts in the / usr / lib / systemd / directory, are called systemd-halt.service, systemd-poweroff.service, systemd-reboot.service. These script when the user selects shutdown, restart or execution standby. Upon receiving the shutdown event, systemd first unmount all file systems and stop all memory swap device, disconnect the storage device, and then stop all the rest of the process.
Systemd Structure Overview
Let's look at the Linux system is in use systemd as the start-up process of the structural details of the boot program. For simplicity, we will follow the steps listed in the following process:
1. When you turn on the power of the computer first thing done BIOS initialization. BIOS reads the boot device settings, positioning and transfer system control to the MBR (hard drive is assumed that the first boot device).
2. MBR reads the relevant information from Grub or LILO boot loader and the kernel is initialized. Next will continue Grub or LILO boot system. If you specify systemd in the grub configuration file as a boot manager, after the boot process will be completed systemd. Systemd using the "target" to guide the process and service management processes. These systemd in the "target" file is used to group different guide unit and start the synchronization process.
The first objective 3. systemd performing a default.target. But in fact default.target pointing graphical.target soft link. Linux soft link in with them and under the same Windows shortcuts. The actual location of the file Graphical.target is /usr/lib/systemd/system/graphical.target. In the following screenshot shows the contents graphical.target file.
4. At this stage, and this target will start multi-user.target own sub-unit in the directory "/etc/systemd/system/multi-user.target.wants" inside. The target set for the multi-user support system environments. Non-root users will be enabled in this phase of the boot process. Firewall-related services will start at this stage.
"Multi-user.target" will control to another "basic.target".
5. "basic.target" common unit used to start services, especially graphics management services. It does this by /etc/systemd/system/basic.target.wants directory to determine which services will be started after basic.target passes control to sysinit.target.
6. "sysinit.target" starts important system services such as system is mounted, device memory and swap space, the kernel added options, and more. sysinit.target during the boot process will be passed to local-fs.target. The contents of target cells as demonstrated in the screenshot below.
7. local-fs.target, the target unit does not start the user-related services, which only deal with the underlying core services. The target will be to implement the relevant operation according to / etc / fstab and / etc / inittab.
Performance Analysis System Boot
Systemd provides tools for identifying and locating boot problems or performance impact related. Systemd-analyze it is a built-in command can be used to detect the boot process. You can find the error during startup unit and track and correct the problem boot component. Below are some common systemd-analyze command.
systemd-analyze time for displaying the kernel and user space starts ordinary time spent.
$ Systemd-analyze time
Startup finished in1440ms (kernel) + 3444ms (userspace)
systemd-analyze blame lists all units running from the start of initialization according to the current time spent sorting through this way you will know what services during the boot process takes a long time to start.
$ Systemd-analyze blame
systemd-analyze verify whether there is a syntax error is displayed in all the system unit.
systemd-analyze plot can be used to guide the entire process to write a file in SVG format. The entire boot process is very inconvenient to read long, so we can write the output to a file by this command, and then later review and analysis. The following is the command to do this.
systemd-analyze plot> boot.svg
Systemd not lucky enough to get everyone's favor, some experts and administrators to develop its working methods and have different views. According to Systemd criticism, it is not a "class Unix" way because it tries to replace some system services. Some experts do not like the idea of using the binary configuration file. It is said edit systemd configuration is very difficult and does not have a graphical tool available.
How to test Systemd in Ubuntu 14.04 and 12.04
Originally, Ubuntu decided to start using Ubuntu 16.04 LTS Systemd to replace the current boot process. Ubuntu 16.04 is expected to release in April 2016, but considering Systemd popularity and demand, just released Ubuntu 15.04 uses it as the default boot loader. In addition, Ubuntu 14.04 Trusty Tahr and Ubuntu 12.04 Precise Pangolin users can test Systemd on their machines. Testing process is not complicated, you have to do it is to be included in the system related to the PPA, update and upgrade the warehouse system.
Disclaimer: Please note that it is still in the testing and development phase Ubuntu. Upgrade the test package may cause some unknown error, it is possible to damage your system configuration in the worst case. Make sure you have good backup before attempting to upgrade your important data.
In a terminal run the following command to add the PPA to your Ubuntu system:
sudo add-apt-repository ppa: pitti / systemd
You will see a warning message because we try to use the temporary / test PPA, and they are not recommended for actual operation of the machine.
Then run the following command to update APT package management warehouse.
sudo apt-get update
Run the following command to upgrade the system.
sudo apt-get dist-upgrade
These, you should already see Systemd configuration files in your Ubuntu system, and open the / lib / systemd / directory can see these documents.
Okay, now let's edit the grub configuration file specifies systemd as the default boot loader. You can use the Gedit text editor to edit the grub configuration file.
sudo gedit / etc / default / grub
Modify GRUBCMDLINELINUX_DEFAULT entry in the file, set its parameters: "init = / lib / systemd / systemd"
In this way, your Ubuntu system is no longer using the traditional boot program, and instead use Systemd Manager. Restart your machine and then view it systemd boot process.
Systemd undoubtedly improve Linux boot process a major step forward; it contains a nice library and daemon work together to optimize the system boot and shutdown procedures. Many Linux distributions are ready to use it as their official bootloader. After Linux distribution, we expect to see systemd boot. But on the other hand, in order to be successful and widely used, systemd still need to carefully deal with criticism.