Welcome to this fascinating journey through Linux system administration. If you have ever wondered how to manage a Linux system efficiently, this article is designed especially for you. Join us as we unravel the mysteries of systemd and sysvinit and provide the essential tools for mastering Linux administration.
We have already discussed managing ZFS partitions, LVM, using SSH on Linux, networking, and using nano for people encountering a terminal for the first time. This time, we will discuss how to gain broader control over a Linux system.
Understanding Linux Administration with Systemd and Sysvinit
Imagine having complete control over your Linux operating system and being able to optimize every aspect according to your needs. Would you like to learn the secrets behind systemd and sysvinit? Keep reading to discover how these init systems can improve your Linux experience.
Systemd vs. Sysvinit: An Important Choice
In the Linux world, system administration begins with choosing between systemd and sysvinit as init systems. Here we will explain the fundamental differences and how they affect performance and service management on your system.
Simplifying System Administration
Systemd has revolutionized service administration on Linux. Each line of its configuration has a specific purpose. For example, a systemd unit file defines how a service starts. Let us look at an example using the nginx service:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
Restart=always
[Install]
WantedBy=multi-user.target
In this example, ExecStart specifies the command used to start the service, while Restart ensures that the service is restarted automatically if it fails.
Sysvinit: The Classic Alternative
Although older, sysvinit is still used on many Linux systems. Its script-based approach requires understanding the /etc/init.d/ and /etc/rc.d/ directories. Here is a simple example for the apache2 service:
#!/bin/bash
# chkconfig: 345 99 10
# description: Apache web server
case "$1" in
start)
/etc/init.d/httpd start
;;
stop)
/etc/init.d/httpd stop
;;
restart)
/etc/init.d/httpd restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
Starting, Restarting, and Stopping Services with Systemd
Now that we have explored the basics of systemd, it is crucial to understand how to start, restart, and stop services. Each action plays an important role in efficient Linux system management.
Starting a Service with Systemd: To start a service with systemd, use the systemctl start command. For example, to start nginx:
sudo systemctl start nginx
Starting a Service with Sysvinit: With sysvinit, the process involves running the corresponding init script. To start nginx, you could use:
sudo /etc/init.d/nginx start
Restarting a Service with Systemd: Restarting is useful for applying changes or solving problems. Use systemctl restart followed by the service name. To restart nginx:
sudo systemctl restart nginx
Restarting a Service with Sysvinit: With sysvinit, restarting means stopping and then starting the service. For example, to restart nginx:
sudo /etc/init.d/nginx restart
Stopping a Service with Systemd: To stop a running service, use systemctl stop. For example, to stop nginx:
sudo systemctl stop nginx
Stopping a Service with Sysvinit: With sysvinit, stopping a service is as simple as running the corresponding stop script. To stop nginx:
sudo /etc/init.d/nginx stop
Changing a Target in Systemd and Sysvinit
Now, in both systems, we will explore how to change a target, which is useful for adapting your system to different scenarios, such as command-line-only mode or a friendlier graphical mode.
Changing a Target with Systemd: In systemd, change a target with systemctl isolate. For example, to switch from multi-user.target to graphical.target:
sudo systemctl isolate graphical.target
Changing a Target with Sysvinit: With sysvinit, changing the target means adjusting the runlevel. To switch to graphical mode:
sudo telinit 5
Setting a Default Target with Systemd: To set a default target at startup with systemd, use:
sudo systemctl set-default graphical.target
Setting a Default Target with Sysvinit: With sysvinit, setting a default runlevel means changing the runlevel at which the system starts. For example, to set graphical mode as the default:
sudo update-rc.d -f gdm3 remove
sudo update-rc.d gdm3 defaults
sudo telinit 5
This set of commands unlinks the old symbolic link for GDM, the graphical display manager, recreates it, and then switches to runlevel 5, which is generally used to start the graphical environment on Sysvinit-based systems.
Conclusion
In this journey through Linux system administration, you explored the essentials of systemd and sysvinit and demystified their configuration and use. As you gain experience with Linux, we encourage you to experiment with these init systems and customize them according to your needs.
Remember, Linux administration is a continuous process of learning and discovery. Keep exploring and maximizing the potential of your favorite operating system.

