Based on the Linux Master 1 exam syllabusReport an error
systemctl, start (once, now) and enable (automatically at every boot) are different. To do both, use enable --now.[Unit], [Service], [Install] structure. /etc/systemd/system takes precedence over /usr/lib/systemd/system, and daemon-reload is required after editing. Logs: journalctl -u service -f.init read /etc/inittab to decide which runlevel to bring the system up to.| Runlevel | Meaning | Description |
|---|---|---|
| 0 | Halt | Powers the system off |
| 1 (S, single) | Single-user mode | For recovery/inspection, root only, no network |
| 2 | Multi-user (no NFS) | Partial network |
| 3 | Multi-user + network | Text (CLI) environment — the server standard |
| 4 | Unused (user-defined) | Reserved |
| 5 | Multi-user + network + GUI | Graphical (X11) environment |
| 6 | Reboot | Restarts the system |
runlevel # check the current runlevel (e.g. N 3 → previous N, current 3)
who -r # check the runlevel and the time it changed
init 3 # switch to runlevel 3 (text)
init 0 # shut down the system (init 6 = reboot)
telinit 5 # switch runlevel, same as init⚠️ Trap: You must never set runlevel 0 or 6 as the boot default. If 0 (halt) or 6 (reboot) is the default runlevel, the system shuts down the moment it powers on or falls into an endless reboot loop. The default is usually 3 for text servers and 5 for GUI desktops. Also remember that runlevel 1 = single-user (rescue) mode.
The only difference between runlevels 3 and 5 is the presence of a GUI (X Window). 3 gives a text console, while 5 even brings up a graphical login screen. Servers use 3 as the default to save resources and desktops use 5. The per-runlevel scripts lived in /etc/rc.d/rc{0~6}.d/ with S (start) and K (kill) prefixes.
| Runlevel | systemd target | Meaning |
|---|---|---|
| 0 | poweroff.target | Halt |
| 1 | rescue.target | Single-user (rescue) |
| 2 | multi-user.target | Multi-user (text) |
| 3 | multi-user.target | Multi-user + network (text) |
| 4 | multi-user.target | (user-defined) |
| 5 | graphical.target | Graphical (GUI) |
| 6 | reboot.target | Reboot |
systemctl get-default # check the current default target
systemctl set-default multi-user.target # make the default text mode
systemctl set-default graphical.target # make the default GUI mode
systemctl isolate multi-user.target # switch to the text target immediately (like init 3)
systemctl rescue # go to single-user (rescue) mode
systemctl reboot # reboot
systemctl poweroff # shut downThe key point is that runlevels 2, 3, and 4 have all been merged into the single multi-user.target (text multi-user). The GUI is graphical.target (the old 5). So "change from GUI to text" is systemctl set-default multi-user.target, and "switch immediately" is systemctl isolate (the role of the old init N). set-default takes effect from the next boot, while isolate takes effect right now.
systemd was announced in 2010 by Red Hat's Lennart Poettering. init's shell-script-based sequential boot got slower as services increased, whereas systemd greatly shortened boot time by creating sockets and D-Bus in advance and starting services concurrently. There was a big debate at its introduction that it "breaks the Unix philosophy", but it has now become the de facto standard.
systemctl. It replaces both the old service and chkconfig.| Command | Action | Old SysV equivalent |
|---|---|---|
systemctl start service | Start immediately | service X start |
systemctl stop service | Stop immediately | service X stop |
systemctl restart service | Restart | service X restart |
systemctl reload service | Re-read config only (no downtime) | service X reload |
systemctl status service | Check state and recent logs | service X status |
systemctl enable service | Register auto-start at boot | chkconfig X on |
systemctl disable service | Unregister auto-start at boot | chkconfig X off |
systemctl is-enabled service | Check whether auto-start is on | — |
systemctl list-units | List of active units | — |
systemctl start sshd # start the SSH daemon immediately
systemctl enable sshd # register auto-start at every boot
systemctl enable --now sshd # register + start immediately in one go
systemctl status sshd # state (active/inactive) and some logs
systemctl is-active sshd # prints active if it's running⚠️ Trap:
startandenableare different.startmeans "turn it on once, now" (it may be off again after a reboot), whileenablemeans "turn it on automatically at every boot" (it is not started right now). To do both, usesystemctl enable --now. Exams have traps that swap the two.
Try it yourself: Run systemctl status sshd (or crond) and look at the Active: line and the Loaded: line. Active: active (running) means it's running, and enabled/disabled in the parentheses shows whether it auto-starts at boot. You can see on a single screen that whether it's running (active) and whether it auto-starts (enabled) are separate pieces of information.
| Unit type | Extension | Target |
|---|---|---|
| service | .service | Daemon/service |
| target | .target | Bundled state, like a runlevel |
| socket | .socket | Socket-based activation |
| mount | .mount | Filesystem mount |
| timer | .timer | Scheduled execution (replaces cron) |
| device | .device | Device |
/usr/lib/systemd/system/ (or /lib/systemd/system/)/etc/systemd/system//etc takes precedence over the one in /usr/lib.[Unit]
Description=My Web Service
After=network.target # start after network.target
[Service]
ExecStart=/usr/bin/myapp # start command
Restart=on-failure # restart automatically on failure
User=myuser
[Install]
WantedBy=multi-user.target # which target to link to on enablesystemctl daemon-reload # must run after changing a unit file
systemctl start myapp # start the new service
systemctl enable myapp # register auto-start in the WantedBy targetWantedBy=multi-user.target in [Install] is the key to what enable does. When you enable, a symbolic link is created in this target's .wants/ directory, so the service starts automatically when boot reaches that target. In [Unit], After=/Before= define the start order and Requires=/Wants= define dependencies.
If you skip systemctl daemon-reload after editing a unit file, the change is not applied. Because systemd caches unit files in memory, even if you edit the file on disk it keeps running with the old contents until daemon-reload. Memorize "edit unit → daemon-reload → restart" as one set.
journalctl, which complements (or replaces) the old /var/log/messages text log.journalctl # all logs (oldest first)
journalctl -u sshd # only the logs of the sshd service
journalctl -f # follow logs in real time (like tail -f)
journalctl -b # only logs since this boot
journalctl --since "1 hour ago" # logs from the last hour
journalctl -p err # only errors (priority err and above)
journalctl -k # kernel messages (like dmesg)| Option | Meaning |
|---|---|
-u service | Logs of a specific unit |
-f | Follow in real time |
-b | Logs of the current boot session |
-p | Priority filter (emerg to debug) |
-r | Reverse order, newest first |
--since/--until | Specify a time range |
journalctl -u service -f is the most useful combination for watching a specific service's logs in real time. The journal is by default stored in memory/temporary storage, so it can disappear on reboot; if you change it to Storage=persistent in /etc/systemd/journald.conf, it is kept permanently on disk (/var/log/journal/).
Try it yourself: Use journalctl -b -p err to pick out only the errors that occurred during this boot. If the system had problems, they are shown in red. Then narrow down to just today's SSH-related logs with journalctl -u sshd --since "today" and you will feel the power of combining filters.
/etc/inittab : The configuration file that traditional init read to determine the default runlevel.systemctl start vs enable : Turning on once now vs. registering to turn on automatically at every boot. They are separate concepts.systemctl isolate : Switch to a different target immediately. Equivalent to the old init N.daemon-reload : A command that makes systemd re-read unit files from disk. Required after editing because of caching.WantedBy= : A directive in the [Install] section. It decides which target's .wants/ gets the link on enable.journalctl.Click a choice to reveal the answer and explanation.
Question 1
In the traditional SysV init system, which runlevel corresponds to a text (CLI) based multi-user + network environment?
Question 2
Which pair of runlevels must never be set as the boot default?
Question 3
In a systemd environment, which target corresponds to the old runlevel 5 (GUI)?
Question 4
Which of the following correctly describes the difference between systemctl start httpd and systemctl enable httpd?
Question 5
After modifying a systemd unit file, which command must you run so that systemd recognizes the change?
Question 6
In a systemd unit file, which section and directive specify the target to link the service to on enable?
Question 7
You want to follow only the sshd service's logs in real time. Which journalctl command is correct?