CompTIA Linux+ (XK0-004)
Red Hat Enterprise Linux
Git and Github
Learn Docker and Kubernates
Tips and Tricks

Systemd

Basics of Systemd

When you boot Linux up (push the power button on your computer), BIOS (or UEFI) kicks in and then it finds the OS on the hard drive. It reaches out to the hard drive and finds the bootloader. The bootloader tells where the kernel is, and kernel starts Linux.

Earlier we used to have SysV.

systemd is an init system and system manager. It's a one monolithic program that takes the control of the whole modern initialization process. It takes care of attaching hardware, mapping network drive, firing up services, and controlling that access.

To interact with systemd, we use systemctl. This is the main command for this.

List all the services:

sudo systemctl --type=service

List all the running services:

sudo systemctl --type=service --state=running

When using systemctl, for most service management commands, you can actually leave off the .service suffix, as systemd is smart enough to know that you probably want to operate on a service when using service management commands.

Starting and Stopping Services

sudo systemctl start application.service # start service
sudo systemctl start application # start service
sudo systemctl stop application.service # stop service
sudo systemctl restart application.service # restart service
sudo systemctl reload application.service # reload service
sudo systemctl status sshd.service # service status

Enabling and Disabling Services at Boot

To start a service at boot, use the enable command:

sudo systemctl enable application.service # enable a service at boot
sudo systemctl disable application.service # disable a service at boot

Analyzing the duration of your system to boot

systemd-analyze is a command that lets you analyze how long it took your system boot from the time systemd (when kernel invokes systemd) kicks in.

systemd-analyze

Multi-user and Text-mode with Systemd

NOTE: The old run-levels are gone in systemd.

There are two types of run-levels now:

  • graphical.target (graphical and multi-user mode)

  • multi-user.target (non-graphical or text-only mode but multi-user)

And, any of them could be set to run either on boot (persistently) or temporarily.

In the below example, I changed from graphical to multi-user (text-only interface) but it doesn't take effect immediately until you boot the system.

If you want to do into the text-only mode without booting the system, you can use this command.

sudo systemctl isolate multi-user.target

Single User Mode in Systemd

Imagine your system got hacked and you want to isolate everyone and enable a single user mode so that you can do the forensics and look into the loopholes. You can go into the rescue mode (i.e. the single user mode in systemd): sudo systemctl rescue