systemd as PID 1 and boot targets
What the first process does, how systemd targets replaced runlevels, how to choose the default target, reach rescue or emergency mode, and find slow boots.
systemd as PID 1 and boot targets
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- PID 1 is special: the kernel starts it, every orphaned process is handed to it, and it only receives the signals it chose to handle. On most distributions it is systemd.
- systemd boots by starting default.target and everything it pulls in. A target is a named group of units, the modern form of a runlevel: multi-user.target is runlevel 3, graphical.target is runlevel 5.
- systemctl get-default and set-default read and change the default target. systemctl isolate switches the running system to another target and stops what that target does not need.
- rescue.target gives a root shell with filesystems mounted and almost nothing else. emergency.target gives a shell with nothing mounted except the root filesystem, possibly still read-only. Both can be chosen from the kernel command line.
- systemd-analyze, blame and critical-chain show where boot time went, with the caveat that a slow unit may only be waiting for another.
The first process
When the initramfs has mounted the real root, it executes /sbin/init and the kernel’s own boot work is done. Every other user-space process on the machine will descend from this one. It gets process ID 1, and that number comes with duties nothing else has.
- It adopts orphans. The
_exit(2)man page says that when a process exits, its children “are inherited by init(1)” unless a nearer subreaper claims them. PID 1 has to collect their exit status, or they linger as zombies. - It is shielded from signals. The
kill(2)man page notes “the only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers”. A straykill -9 1does nothing. - It brings the system up and takes it down. Mounting filesystems, starting services in the right order, and shutting them down cleanly at power-off are its job.
On Debian, Ubuntu, Fedora, RHEL and Arch, that program is systemd. Its man page says it “is usually not invoked directly by the user, but is installed as the /sbin/init symlink”. On Debian 13 the systemd-sysv package is what provides /usr/sbin/init, according to its file list. Alpine and some minimal or container images use other inits.
The devops lesson running services with systemd covered starting and enabling one service. Here we look at how systemd brings up the whole machine.
Targets, not runlevels
The older SysV init booted to a numbered runlevel: 1 for single-user maintenance, 3 for a multi-user text system, 5 for graphical, 0 and 6 for halt and reboot. Each runlevel ran a fixed list of scripts in order.
systemd replaced numbers with targets: units whose only job is to group other units and act as a synchronisation point. The bootup(7) man page describes the boot as activating “all units that are dependencies of default.target”, in parallel where ordering allows. default.target is a symlink, usually to multi-user.target on servers or graphical.target on desktops.
The old numbers still work as aliases. systemd’s own build file creates runlevel0.target for poweroff.target, runlevel1.target for rescue.target, runlevel2 through runlevel4 for multi-user.target, runlevel5.target for graphical.target and runlevel6.target for reboot.target, when built with SysV compatibility. Debian’s systemd package ships all seven files.
A useful way to picture it: runlevels were a numbered menu where you ordered set meal 3. Targets are named milestones on a dependency graph, and you can define your own.
The commands, from systemctl(1). I have not run them here:
systemctl get-default # which target does boot aim for?
sudo systemctl set-default multi-user.target # change it (re-points the symlink)
sudo systemctl isolate multi-user.target # switch now, stopping what it doesn't need
systemctl list-units --type=target # which targets are active
The man page warns that isolate “is dangerous, since it will immediately stop processes that are not enabled in the new target, possibly including the graphical environment or terminal you are currently using”.
Rescue and emergency
Two targets exist for repairs.
rescue.target “pulls in the base system (including system mounts) and spawns a rescue shell”, per systemd.special(7): all filesystems mounted, almost no services. Use it to fix a service that crashes the boot.
emergency.target is “the most minimal version of starting the system in order to acquire an interactive shell; the only processes running are usually just the system manager (PID 1) and the shell process”. Nothing beyond the root filesystem is mounted, and root may still be read-only, so you often start with mount -o remount,rw /. systemd drops you here on its own when “a file system check on a required file system fails”. A typo in /etc/fstab is the classic cause.
To reach either for one boot, edit the kernel command line in GRUB, as in the previous lesson, and add systemd.unit=rescue.target or systemd.unit=emergency.target. systemd(1) lists shortcuts kept for SysV habits: rescue, single or 1 for rescue mode, emergency for emergency mode, and 3 or 5 for multi-user or graphical. From a running system, systemctl rescue and systemctl emergency do the same as isolating those targets. Both normally ask for the root password before giving you the shell, so know it, or know the recovery tricks in the last lesson of this roadmap.
Why did boot take so long?
systemd-analyze with no arguments prints how long firmware, loader, kernel, initrd and user space each took. Two subcommands narrow it down:
systemd-analyze blamelists units by how long they took to start. The man page’s own sample hassystemd-networkd-wait-online.servicenear the top at about 21 seconds, a common culprit on servers.systemd-analyze critical-chainprints the chain of units that actually held up reaching the default target, with@for when each became active and+for how long it took.
Read blame carefully. The man page warns its output “might be misleading as the initialization of one service might be slow simply because it waits for the initialization of another service to complete”. A database that “took 30 seconds” may have spent 29 of them waiting for the network. critical-chain is usually the better first look. Dependencies and ordering between units get their own lesson later, in units, targets and dependencies.
About the video
The embed is tutoriaLinux’s “systemd on Linux 3: Targets”, July 2021, about 9 minutes, in full. Dave Cohen covers what targets are, the old runlevels, listing targets, useful network targets, systemctl isolate, get-default, and why add-wants is a bad habit. That covers the middle of this lesson well. It is from 2021 and does not cover rescue versus emergency in depth or systemd-analyze, which the lesson does. English was judged from the title, channel and original English audio track. It is a different episode from the tutoriaLinux video embedded in the devops systemd lesson. Joe Collins’s systemd chapter in deeper is a longer, broader walkthrough.
What was run: nothing on Linux. Quotations are from systemd(1), systemctl(1), systemd.special(7), bootup(7) and systemd-analyze(1) on man7.org (systemd 262 development pages), _exit(2) and kill(2); the runlevel aliases from systemd’s units/meson.build on GitHub and Debian’s package file list, checked 2026-11-28.
Check yourself
How do you make a server that boots to a graphical login boot to a text console from now on?
sudo systemctl set-default multi-user.target, which points the default.target symlink at multi-user.target.
A machine fails to boot because an /etc/fstab entry is wrong. Which target are you likely dropped into, and why that one?
emergency.target. It is used when a required filesystem fails to mount or check, and it starts nothing beyond a shell on a minimal root.
How do you boot once into rescue mode without changing the default?
Edit the kernel command line in the GRUB menu and add systemd.unit=rescue.target, or the shortcut rescue (or single or 1).
systemd-analyze blame lists a service that took 20 seconds. Why might that service not be the real problem?
It may have spent most of that time waiting for another unit, such as the network coming online. critical-chain shows which units actually held up the boot.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.