After the GRUB finds the kernel, continues the boot process with the first and most important, systemd process. Systemd takes part nearly in every activity in Linux and nothing happend without its knowledge.
Systemd consists of blocks that are called Units. The most of systemd units are service units, which activates system services, but there are also the other units, the full list looks in this way and is visible thanks to command ‘systemctl -t help‘
If we want to see the entire list of service units we run
systemctl list-units –type=service –all
if we want to check what given unit is responsible for
From booting perspective the most important are service and target units. ‘Target Unit’ groups together other system units and transists the system into different states. Systemd Targets were also known as runlevels in earlier versions of Linux.
Each target is associated with several systemd units, each unit can start or stop particular services. These units are also known as dependencies. If we want to see all dependencies for given target we use command ‘systemctl list-dependencies name.target’. For graphical target it looks :
If we want to know what is default target we run ‘systemctl get-default‘, if we want to change its ‘systemctl set-default multi-user.target‘. If we want to switch between targets we run ‘systemctl isolate [name.target]‘ command for example
systemctl isolate graphical.target
Systemd is responsible for running all services. It replaced the ‘init’ daemon and Upstart system that relies on runlevels and init scripts to run services similar to the older SysVinit. Systemd is much more efficient, whereas SysVinit were running all services at once, Systemd runs only services that are required to start the system, the others are being started on demand. It increased the speed of booting significantly. Also SysVinit starts services sequentially, systemd runs services in parallel by keeping track of all dependencies between units. We may see units dependenices that must be started before particular service (nfs): systemctl list-dependencies nfs.service
The systemd uses configuration files that are being stored in /usr/lib/systemd/system folder to run the other processes. We may also store our own customized configuration files in /etc/systemd/system.
Besides service and targets units there are also the other one :
If we want to see all active systemd units we run a command:
if we want to see weather units are enabled or disabled
SIngle target may inculde another targets. Let’s have a look on
graphical.target and what its consists of.
As we see graphical.target to work requires running multi-user.target. Firstly is being run mutli-user.target, then graphical.target activates display- manager.service (Wants). If we want to check the other services that are being run with graphical.target.wants we check
Systemd units are run and stop automatically when you switch between diferent targets, but you may also manually switch them on and off. If we look closer for example on sshd service (unit) we may conclude that the script is divided on 3 parts: Unit– description, Service– type of service, path to file with variables of the service, executive file path, Install– service is activated when multi-user.target has been run.
If we want to check the status of given service we run
systemctl status sshd.service
if we didin’t specify .service extension, that’s not a problem cause system assumes it by default so we may also run
systemctl status sshd
Regarding given service, we may use a couple of different options
systemctl [option] [service]
What, if we want to make enable any service by default, in spite of is not enabled by default in the ‘target’?
Firstly let’s find out about all services installed in the system
systemctl list-unit-files –type=service
if we want to find out if given service is enabled or disabled in given target
systemctl is-enabled sshd.service
with enable/disable options we may command to run any service during booting up
systemctl disable sshd.service
systemctl enable sshd.service
Disable options doesn’t prevent user to start the service after running the system. If we want to disable the service during a boot process and ensure that it cannot be started anymore we have to use the ‘mask’ command
systemctl mask sshd.service
of course if we want we may turn back to the previous state
systemctl umask sshd.service