fbpx Systemd on Linux: How It Works, systemctl and Units | Certificação Linux

Systemd: How It Works, Differences from SysVinit, and Commands

📅 02/18/2022 ⏱ 7 min ✍️ Uira Ribeiro
Linuxcommandshow-to
Systemd: How It Works, Differences from SysVinit, and Commands
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

If you recently started studying about the Linux system, without a doubt 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 in Linux? 

These doubts are very common and can be easily answered, helping you get the right guidance. 

That's why the Certificação Linux team developed this complete article, with everything you need to know about systemd. Just keep reading. Check it out!

Init system: understanding the concept

Before understanding systemd, it is necessary to understand the concept of init system. As the name suggests, the init system is responsible for the entire system initialization. 

This means that for Linux to be activated, the init system is essential. In this aspect, systemd predominates, which is a great tool to assist the initialization system. 

In other systems, such as Windows, this set of tools for initialization also exists, but through the "Service Control Manager". 

What is systemd?

Systemd represents the initialization of the Linux operating system. Within it, there are other programs that run in the background, in order to assist the development of this process. 

These background complements are called daemon, which can be considered a child process of init.

How does systemd work?

In simple terms, as soon as the Linux kernel is activated, systemd takes action, 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 are also awakened. 

It is through systemd that Linux distributions, also called distros, become viable 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 these functions are organized in the form of units, which are popularly called units, and some 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 be frequently optimized.

Comparison - System V (sysvinit) vs systemd

linux systemd or systemv
Photo: Freepik | Is systemd better than system v?

Another very common doubt, 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 particularities and functions, but both refer to the initialization system. 

Some of the main differences between System V and systemd are in the table below:

System VSystemd
is older, resembling standard Unixis more recent, with several distros migrating to it
has a slightly slower bootprovides faster boot
boot is through shell script filesboot occurs through ".service" files
uses more memory and hardwareuses little memory
older APIhas an improved API
can be more complexhas a simple and efficient design

Disadvantages of System V

Although System V init Daemon is a robust system used in Kernel 2.4, it has serious disadvantages, 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 of running services (daemon) is limited, generating zombie processes;
  • restarting services that have 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.

Therefore, systemd is much more worthwhile, compared to System V (commonly pronounced as system five).

What's new in systemd

The main novelty of systemd is its capacity and efficiency, with the execution of functions in an increasingly faster and lighter way. 

Thus, other processes are not affected, much less harmed. 

Furthermore, this new system is already widely used in the most well-known distributions, especially in Kernel versions higher than 2.6. 

Its main advantage is loading the system faster, executing services and processes in parallel.

This was made possible with the arrival of new processors with multiple cores, which allow the execution of several threads in parallel.

As novelties 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 creation of memory state images to save and restore execution states.
  • the group control system allows systemd to supervise processes, in order to guarantee that when a service is stopped, all child processes, grandchildren, great-grandchildren, etc. are also stopped.
  • with more robust management, more CPU cycles are required for creating new processes. But due to the high performance of processors, this does not seem to be a problem for systemd.
  • in systemd, process loading, runlevel changes and load scripts are quite different from init.

The syntax of systemd configuration files, called units, is inspired by Windows .ini files. These files are found in two directories, namely:

/usr/lib/systemd/system/: Units coming from installed software packages;

/etc/systemd/system/: Units installed by the administrator;

See how to handle services in systemd using the systemctl command:

How to control services using the systemctl command

linux systemd commands
Photo: Shutterstock | How do systemd commands work?

Controlling services in systemd is not difficult. Through the systemctl command, everything becomes possible. 

To start new services, for example, you just need to combine the systemctl command with the "start" subcommand. 

At the same time, to stop a given service, you just need to 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)

               Active: active (running) since Mon, 28 May 2012 18:09:57 -0300; 7min 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 service status when stopped:

# systemctl status cron.service

cron.service - Command Scheduler

               Loaded: loaded (/lib/systemd/system/cron.service; enabled)

               Active: inactive (dead) since Mon, 28 May 2012 18:18:26 -0300; 27s ago

             Main PID: 673 (code=exited, status=0/SUCCESS)

               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 boot in systemd

# systemctl enable cron.service

6. To disable a service during system boot in 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 graphical 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 runlevel 3 as default:

# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

Deepen your knowledge in Linux with our online course! Enroll now!

Conclusion

Did you see how learning about systemd is not complicated? You just need to search for information from the right source!

If you like content about Linux and this universe of main Linux commands, we recommend that you visit the Linux Certification Blog. There you will find several amazing contents on the topic. It's worth checking out!

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp