Systemd - how it works, differences for sysvinit and commands
If you have recently started studying the Linux system, you must have come across “systemd”.
But do you know exactly what it means? Or what is the difference between it and System V, also famous on Linux?
These questions are very common and can be easily answered, helping you to get the right direction.
It was with this in mind that the Linux Certification team developed this complete article, with everything you need to know about systemd. Just continue reading. Check it out!
Init system: understand the concept
Before understanding systemd, it is necessary to understand the concept of init system. As its name suggests, the init system is responsible for the entire initialization of the system.
This means that for Linux to be activated, the init system is essential. In this regard, systemd predominates, which is a great tool to assist the startup system.
In other systems, such as Windows, this set of tools for initialization also exists, but through the “Service Control Manager”, or Service Command Manager, in a free translation.
What is a systemd?
Systemd represents the initialization of the Linux operating system. In it, there are other programs that run in the background in order to assist the development of this process.
These background add-ons are called daemon, which can be considered a child process of init.
How does a systemd work?
Simply put, as soon as the Linux kernel is activated, systemd acts, which will be responsible for activating all stages of the process.
At this moment, software responsible for the performance of hardware items such as video cards and processors is also awakened.
It is through systemd that Linux distributions, also called distros, become feasible and work correctly.
This explains how systemd works. In its structure, there are also other tools that are responsible for managing and organizing tasks to maintain good performance.
All of these functions are organized in the form of units, which are popularly referred to as units, some of which are very common in this universe are service, time, socket, path and swap.
Each of these units is essential for the entire system to function and is frequently optimized.
Comparison - system V (sysvinit) x systemd
Photo: Freepik | Is Systemd better than system v? Another very common question, after identifying the meaning of systemd, is what is the difference between it and system V.
The truth is that each one has its own singularities and functions, but both refer to the startup system.
Some of the main differences between system V and systemd are in the table below:
System V | Systemd |
---|---|
is older, remember the standard Unix | is newer, with several distros migrating to it, it |
has a slightly slower startup | provides a startup. |
The fastest initialization is through shell script files | the initialization occurs through “.service” files |
uses more memory and hardware | uses little memory |
older API | has an improved API |
may be more The complex | has a simple and efficient design |
Although System V init Daemon is a robust system used in Kernel 2.4, it has serious drawbacks, especially when compared to systemd. They are:
- it is one of the first versions of the Unix system, and therefore a bit old;
- there is a greater chance of incompatibility with distros and systems;
- in some cases, System V has become obsolete;
- monitoring the running services (daemon) is limited, generating zombie processes;
- restarting services that stopped working is problematic;
- there is a parallelism that makes everything more complicated;
Due to several limitations of init, another special system for controlling boot processes and managing program execution was created and called systemd.
For this reason, systemd is much more worthwhile compared to system V (commonly pronounced as system five).
What’s new in Systemd
The main innovation of systemd is its capacity and efficiency, with the execution of functions in an increasingly fast and lighter manner.
Thus, other processes are not affected, much less harmed.
In addition, this new system is already widely used in the most popular distributions, especially in Kernel versions greater than 2.6.
Its main advantage is that it loads the system more quickly, running services and processes in parallel.
This was possible with the arrival of the new processors equipped with multiple cores, which allow the execution of several threads in parallel.
Among the new features and advantages of Systemd, we can mention:
- activation via socket and bus (executes services on demand);
- better parallelization of processes;
- use of cgroups (control groups) instead of PIDS;
- supports the creation of memory state images to save and restore execution states.
- the group control system allows systemd to supervise processes in order to ensure that, when a service is stopped, all child processes, grandchildren, great-grandchildren, etc. are also stopped.
- with more robust management, more CPU cycles are needed to create new processes. But due to the high performance of the processors, this doesn’t seem to be a problem for systemd.
- In systemd, process load, runlevel changes, and load scripts are quite different from init.
The syntax of Systemd configuration files, called units, is inspired by the Windows .ini files. These files are found in two directories, namely:
/usr/lib/systemd/system/: Units from installed software packages;
/etc/systemd/system/: Drives installed by the administrator;
See how to handle services in systemd using the systemctl command:
How to control services using the systemctl command
Photo: Shutterstock | How do the commands in systemd work? Controlling services in systemd is not difficult. Through the systemctl command, everything becomes possible.
To start new services, for example, simply combine the systemctl command with the “start” subcommand.
At the same time, to stop a certain service, simply select the “stop” command.
1. check the status of a service in systemd
# systemctl status cron.service
cron.service - Command Scheduler
Loaded: loaded (/lib/systemd/system/cron.service; enabled)
& nbsp; Active: active (running) since Mon, May 28, 2012 18:09:57pm; 7 min ago
Main PID: 673 (cron)
CGroup: name=systemd: /system/cron.service
+ 673 /usr/sbin/cron -n
2. Stop a service in systemd
# systemctl stop cron.service
See the status of the service when stopped:
# systemctl status cron.service
cron.service - Command Scheduler
Loaded: loaded (/lib/systemd/system/cron. service; enabled)
Active: inactive (dead) since Mon, May 28, 2012 6:18:26pm | 27s ago
Main PID: 673 (code=exited, status=0/success)
& nbsp; CGroup: name=systemd: /system/cron.service
3. To start a service in systemd
# systemctl start cron.service
4. To restart a service in systemd
# systemctl restart cron.service
5. To enable a service during system load in systemd
# systemctl enable cron.service
6. To disable a service during system load on systemd
# systemctl disable cron.service
7. To change the runlevel to text mode (runlevel 3)
# systemctl isolate multi-user.target
8. To change the runlevel to graphic mode (runlevel 5)
# systemctl isolate graphical.target
9. To Change the default runlevel in systemd
1) Delete the symbolic link:
# rm /etc/systemd/system/default.target
2) To set runlevel3 as default:
# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Deepen your Linux knowledge with our online course! Enroll now!
Conclusion
Did you notice how learning about systemd is not complicated? Just search for the information in the correct source!
If you like content about Linux and this universe of the main Linux commands, we recommend that you visit the Blog Linux certification. In it, you can find several incredible content on the subject. It’s worth checking it out!