Targets in systemd and named run levels in sysvinit are similar in that they both serve as a way to define the state or mode in which a Linux system should operate. However, there are some key differences between the two.
In sysvinit, run levels are represented by numbers (0-6) and are used to define different system states. Each run level has a specific set of services that are started or stopped when the system transitions to that run level. For example, run level 3 is typically used for a multi-user, text-based environment, while run level 5 is often used for a multi-user graphical environment.
On the other hand, systemd introduces the concept of targets to replace run levels. A target is a more flexible and dynamic way to define the system state. Each target represents a specific system configuration, which includes a set of services that should be started or stopped. Unlike run levels, targets are not limited to a fixed set of states. Instead, they can be customized and extended to meet specific requirements.
One of the commonly used targets in systemd is the "multi-user.target". This target is similar to run level 3 in sysvinit, as it represents a multi-user, text-based environment. When the system boots into the "multi-user.target", only essential services required for a command-line interface are started. This target is often used on servers where a graphical environment is not needed, focusing on providing a stable and efficient environment for running server applications.
To illustrate the usage of targets in systemd, let's consider an example where we want to create a custom target called "webserver.target" that starts all the necessary services for hosting a web server. We can define this target by creating a new systemd unit file called "webserver.target" and specifying the services it should include. Once defined, we can set the default target to "webserver.target" to ensure that the system boots into the desired state.
Targets in systemd provide a more flexible and extensible approach to defining system states compared to named run levels in sysvinit. They allow for greater customization and adaptability, making it easier to manage complex system configurations.
Other recent questions and answers regarding EITC/IS/LSA Linux System Administration:
- How to mount a disk in Linux?
- Which Linux commands are mostly used?
- How important is Linux usage nowadays?
- How does the "conflicts" directive in systemd prevent two units from being active simultaneously?
- What is the purpose of the "requisite" directive in systemd and how is it different from "required by"?
- Why is it recommended to manage dependencies on units that you are creating or managing yourself, rather than editing system units?
- How does the "before" directive in systemd specify the execution order of units?
- What is the difference between weak dependencies and explicit ordering in systemd?
- What is the purpose of the "rescue.target" and how can it be used for troubleshooting without rebooting the system?
- What command can be used to switch between targets in systemd and how is it similar to switching between run levels in sysvinit?
View more questions and answers in EITC/IS/LSA Linux System Administration

