๐ Diving Deep into Linux: Core Concepts Every DevOps Engineer Should Know
PART- 2
In this blog post, you'll learn how to use systemd targets to manage your Linux server's boot process. We'll explore how to check your current default target, switch between graphical and non-graphical modes, and list available targets, giving you the flexibility to customize your server's startup behavior to suit your needs.
Understanding Systemd Targets: Booting Your Server in Graphical or Non-Graphical Mode
Introduction:
In the world of Linux servers, having control over the boot process is crucial. Systemd, the modern init system, offers a flexible way to manage this by utilizing targets (previously known as runlevels). This blog post will delve into systemd targets, explaining how to configure your server to boot into either graphical mode (ideal for desktops) or non-graphical mode (perfect for headless servers or command-line environments).
What are Systemd Targets?
Imagine systemd targets as switches that determine the services to start during boot. These services play a vital role in shaping how your server operates. Traditional runlevels employed numbered designations (e.g., runlevel 3 for non-graphical mode, runlevel 5 for graphical mode), while systemd utilizes descriptive names like multi-user.target
and graphical.target
for better clarity.
Identifying the Default Target:
To discover the target your server boots into by default, use the following command in your terminal:
systemctl get-default
This retrieves the information from the /etc/systemd/system/default.target
file.
Switching Between Graphical and Non-Graphical Modes:
Listing Available Targets:
To view all available systemd targets, run this command:
systemctl list-targets
This provides a comprehensive list of targets you can use for your server.
Changing the Default Target:
Let's say you want your server to boot into non-graphical mode by default. Use the following command, replacing
<target_name>
with the desired target (e.g.,multi-user.target
):systemctl set-default <target_name>.target
This modifies the
/etc/systemd/system/default.target
file and sets the new default for future boots.
Additional Considerations:
Remember that changes made with
systemctl set-default
take effect on the next reboot.For a temporary switch to a specific target without modifying the default, use:
systemctl isolate <target_name>.target
This boots the server into the specified target for the current session only.
Why CLI over GUI?
Work more efficient
Easier for bulk operations
CLI is more powerful
Conclusion:
By understanding systemd targets, you gain control over your server's boot process. Whether you prefer a graphical desktop or a streamlined non-graphical interface, systemd targets offer a convenient way to configure the desired environment for your server.
Subscribe to my newsletter
Read articles from Rushikesh Kamble directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by