What systemd does at boot

Video 067 of 140 in Virtualization Foundations, in the unit “The boot sequence, end to end”. 3:52, with English and Hindi audio.

Near the end of the boot, the kernel hands control to init, the first program. On Ubuntu, that program is systemd. It runs as process ID one, and every other process on the server descends from it. systemd mounts the disks, starts the services and opens the logins. This article explains how it does this, why it starts services in parallel, and which commands show what it is doing.

What you will learn

Why systemd starts services in parallel

Older init systems ran start-up scripts one after another, in a fixed order. Each script had to finish before the next one began. That made boot slow. One service that waited on the network held up every service after it.

systemd starts services in parallel instead. Each one starts as soon as the things it needs are ready, so services that do not depend on each other start together.

What systemd does at boot, in order

Units and targets

Inside systemd, the things it manages are called units. A service, a disk mount and a network socket are all units.

A target is a unit too. It is a group of other units that a boot should reach, such as the group a server boots to.

Asking systemd what it is doing

You can ask systemd about its own state with a few read-only commands. The exercise below shows the name of process ID one, the target the boot aims for, the units that failed, and the slowest units at boot.

Note: An empty list from systemctl --failed means that no unit failed during this boot.

Try it yourself

You need a shell on an Ubuntu server. Each command asks systemd about itself or about the last boot, and none of them change the server.

  1. Print the name of process ID one, the first process the kernel starts.

    ps -p 1 -o comm=

    What you should see: The name of process ID one, which should be systemd.

  2. Show the target that the boot is aimed at.

    systemctl get-default

    What you should see: The target the boot is aimed at.

  3. List the units that failed.

    systemctl --failed

    What you should see: The units that failed. An empty list means none failed.

  4. Show the slowest units at boot, with the time each one took.

    systemd-analyze blame | head -5

    What you should see: The slowest units at boot, each with the time it took.

Terms

systemd
The service manager that runs as process ID one and starts the services a server needs.
Unit
A named thing that systemd manages, such as a service, a disk mount or a network socket.
Target
A unit that groups other units, which a boot should reach.
fstab
The file that lists the disks and folders to attach at boot, and where each one is attached.

Check yourself

Why does systemd start services in parallel?

So one slow service does not hold up every service behind it. Each service starts when the things it needs are ready.

What is a target?

A unit that groups other units, such as the group a server boots to.

What does systemctl --failed show?

The units that did not start. An empty list means no failures were recorded during this boot.

Previous: The kernel and the initramfs. Next: Where a boot stops when it fails.