Reduce Embedded Linux Boot Time: Measure with systemd-analyze
Find where an embedded Linux system spends its boot time with systemd-analyze time, blame, critical-chain and plot, and see how bootchart2 fits in.
Contents
Before you shorten the boot time of an embedded Linux device, you need to know where the time goes. On systemd-based images, systemd-analyze answers that with a few commands: a total, a per-unit list, a dependency chain and an SVG chart.
This guide shows how to read each output and what the man page says about its limits. It also covers bootchart2.
Get the big numbers first
Run systemd-analyze with no verb, which is the same as systemd-analyze time. It splits the boot into kernel, initrd and userspace time.
Startup finished in … (kernel) + … (initrd) + … (userspace) = …
multi-user.target reached after … in userspaceThis splits the time by phase. One caveat from the man page: the measurement stops when all services have been spawned, not when they finish initializing or the disk goes idle.
systemd-analyze timeRank units with blame
systemd-analyze blame lists units with the slowest initialization first, for example 32.875s pmlogger.service in the man page.
systemd-analyze blame --no-pager | head -n 15Treat the list with care. The man page lists several caveats:
- A slow unit may just be waiting for another unit.
Type=simpleservices are left out, because systemd considers them started immediately.- Only the “activating” state is measured, so units that go straight from inactive to active (such as device units) do not show up.
- Waiting in the job queue is not included.
Follow the critical chain
blame ignores dependencies. critical-chain shows the chain of units that actually delayed the target. Pass a unit to inspect, or none for the default target.
systemd-analyze critical-chain multi-user.targetRead the tree from the top. The top line is the unit you asked about, and each indented line is a unit it waited for. @ is the time after startup at which the unit became active or started, and + is how long it took to start.
--fuzz=50ms also lists units that finished up to 50 ms before the latest one at the same level. Socket activation and parallel startup can make the chain misleading.
Draw the boot with plot
systemd-analyze plot produces an SVG chart of unit start times and initialization time. Redirect the output to a file and copy it off the device to view it.
systemd-analyze plot > bootup.svgThe plot uses the latest start cycle of each unit, so generate it soon after boot. Units that nothing depends on may have been unloaded after exiting and will be missing. If you want text instead of a picture, systemd-analyze plot --table prints the raw timing data as a table, and --json=MODE prints it as JSON.
Check unit files with verify
Once you change a unit, systemd-analyze verify loads the file and warns about unknown sections and directives, missing dependencies and missing or non-executable commands. The test block below runs it in a container without a booted systemd.
if command -v apt-get >/dev/null; then apt-get update -qq && apt-get install -y -qq systemd; fi
cat > /tmp/demo.service <<'UNIT'
[Unit]
Description=Demo unit
[Service]
ExecStart=/bin/true
UNIT
systemd-analyze verify /tmp/demo.service && echo "verify ok"If the command listed in ExecStart= does not exist, verify prints a warning. The exit status is zero regardless of warnings unless you pass --recursive-errors=.
Bootchart as an alternative
bootchart2 is a boot-time collector plus a renderer, pybootchartgui. Its README says to add options like these to the kernel command line so that /sbin/bootchartd runs as init:
initcall_debug printk.time=y quiet init=/sbin/bootchartdAfter boot, pybootchartgui renders the chart as PNG or SVG. The README recommends CONFIG_PROC_EVENTS=y and CONFIG_TASKSTATS=y in the kernel; without them collection is slower and less accurate. The README does not document build steps, and the repository page lists no release.
A practical loop to reduce boot time
- Run
systemd-analyze timeand note the kernel, initrd and userspace split. - Use
critical-chainto find units on the path to your target. - Use
blameandplotto see how long those units took. - Change one thing, such as disabling a unit you do not need, reboot and compare.
For building such images, see Buildroot: Build a Minimal Linux Image and Boot It in QEMU. To manage the units you find, read systemctl Command: Start, Stop, Enable and Inspect Services. To read the messages a slow unit logged during startup, see journalctl: Read and Filter systemd Logs on Linux.
Sources
This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.