Chapter 9: Services and the boot process
systemd and boot cheat sheet
The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.
The chapter in eight sentences
- systemd is PID 1; it manages units (services, targets, sockets, timers, mounts), and
systemctlis its control tool. - A service has two independent properties: whether it is running now (
start,stop) and whether it starts at boot (enable,disable);enable --nowdoes both. maskmakes a unit impossible to start at all;unmaskundoes it.systemctl statusshows the state and the last log lines;journalctl -u NAMEshows its whole log;systemctl --failedlists trouble.- Your own units belong in
/etc/systemd/system; change packaged ones with a drop-in, and alwayssystemctl daemon-reloadafter editing. - A service unit needs
ExecStart=with a full path, a restart policy as wanted, andWantedBy=multi-user.targetto start at boot. - Boot order: firmware, GRUB, kernel, initramfs, systemd, default target; set it with
systemctl set-default, switch now withisolate. - With console access you can recover:
rd.breakresets a lost root password (remount/sysroot,chroot,passwd,touch /.autorelabel), andfindmnt --verify,mount -aandnofailprotect against a bad/etc/fstab.
Cheat sheet
Services
| Command | Does |
|---|---|
| `systemctl start | stop |
| `systemctl enable | disable [--now] NAME` |
| `systemctl mask | unmask NAME` |
systemctl status NAME | State and recent log |
| `systemctl is-active | is-enabled NAME` |
systemctl list-units --type=service | What is loaded |
systemctl list-unit-files | What is installed |
systemctl --failed | Failed units |
journalctl -u NAME | The service's log |
Unit files
| Item | Detail |
|---|---|
| Your units | /etc/systemd/system/NAME.service |
| Packaged units | /usr/lib/systemd/system/ (do not edit) |
| Drop-in | /etc/systemd/system/NAME.service.d/*.conf or systemctl edit NAME |
| Show what applies | systemctl cat NAME |
| After any change | systemctl daemon-reload |
| Check the file | systemd-analyze verify FILE |
[Service] | ExecStart=, Restart=, User=, Environment= |
[Install] | WantedBy=multi-user.target |
| Status 203/EXEC | Program not found or not executable |
Boot and recovery
| Command / key | Does |
|---|---|
systemctl get-default, set-default T | Show / set the boot target |
systemctl isolate T | Switch the running system |
systemd-analyze, blame, critical-chain | Boot timing |
cat /proc/cmdline | Arguments of the running kernel |
grubby --update-kernel=ALL --args=X | Add a kernel argument (--remove-args removes) |
GRUB: e, then Ctrl+X | Edit one boot |
rd.break | Early shell for a root-password reset |
findmnt --verify, mount -a | Test /etc/fstab |
nofail | Optional file system |
Flashcards
- Start, stop, restart and reload a service?
- systemctl start | stop | restart | reload NAME
- Boot policy versus current state?
- enable/disable change boot; start/stop change now. is-enabled and is-active ask.
- Make a service start now and at boot?
- systemctl enable --now NAME
- Forbid a service completely?
- systemctl mask NAME (undo with unmask)
- See a service in detail, and its log?
- systemctl status NAME · journalctl -u NAME
- List failed units?
- systemctl --failed
- Where are your unit files, and what after editing?
- /etc/systemd/system/ · systemctl daemon-reload
- Three sections of a service unit?
- [Unit] description and ordering · [Service] what to run · [Install] what enable does
- Show and change the default target?
- systemctl get-default · systemctl set-default multi-user.target
- Boot order in six words?
- Firmware, GRUB, kernel, initramfs, systemd, target.
- Add a kernel argument permanently, and for one boot?
- grubby --update-kernel=ALL --args=... · press e in GRUB
- Reset root password with console access?
- rd.break, remount /sysroot rw, chroot, passwd root, touch /.autorelabel, exit twice.