systemd
Created at 2017-06-17T18:25:33+09:00

TODO

  • follow until "Startup finished in x.xxxs (kernel) + y.yyys (userspace) = z.zzzzs."
  • unit dependency management and execution
  • [x] boot units chain
    • runlevel (default, shutdown)
    • fstab generater
    • login, getty
  • systemd, systemctl
  • logind, loginctl
  • journald, journalctl
  • udevd
  • [x] build from source
  • [x] systemd-analyze
  • systemd user instance from pam login (pam_systemd.so)

Debugging

$ sudo journalctl --boot=0                           # show log from latest boot (with --output=verbose help searching)
$ sudo journalctl --boot=0 SYSLOG_IDENTIFIER=systemd # show only systemd's log (SYSLOG_PID=1 didn't work ?)
$ systemd-analyze plot > sd-plot.svg                 # show timing of units
$ systemd-analyze dot | dot -Tsvg > sd-dot.svg       # show dependency (with --require option might be better)

Building and Testing

$ mkdir out
$ cd out
$ meson ..
$ ninja
$ ninja -t browse # Check dependency
$ ninja test                             # run all tests (i.e. mesontest --bo-rebuild --print-errorlogs)
$ mesontest --no-rebuild test-fstab-util # run single test

Boot unit chain

Here, I picked some important-looking units.

graphical.target              => multi-user.target
multi-user.target             => basic.target, systemd-logind.service,
                                 dbus.service, systemd-user-sessions.service,
                                 getty.target, NetworkManager.service
basic.target                  => sysinit.target, slices.target
sysinit.target                => local-fs.target swap.target
                                 systemd-udevd.service, systemd-journald.service, ...
systemd-user-sessions.service => network.target
slices.target                 => -.slice, system.slice
local-fs.target               => -.mount, systemd-fsck-root.service (fstab generator, SEE BELOW)
swap.target                   => dev-sda2.swap (fstab generator, SEE BELOW)
getty.target                  => getty@tty1.service

fstab Generator

-.mount and dev-sda2.swap referenced above are generated from /etc/fstab on the fly.

# /etc/fstab
/dev/sda4               /           ext4        rw,relatime,data=ordered    0 1
/dev/sda2               none        swap        defaults    0 0


### tree /run/systemd/generator ###
├── dev-sda2.swap
├── local-fs.target.requires
│   └── -.mount -> /run/systemd/generator/-.mount
├── local-fs.target.wants
│   └── systemd-fsck-root.service -> /usr/lib/systemd/system/systemd-fsck-root.service
├── -.mount
└── swap.target.requires
    └── dev-sda2.swap -> /run/systemd/generator/dev-sda2.swap


### /run/systemd/generator/dev-sda2.swap ###
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)

[Swap]
What=/dev/sda2


### /run/systemd/generator/-.mount ###
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target

[Mount]
What=/dev/sda4
Where=/
Type=ext4
Options=rw,relatime,data=ordered

systemd, systemctl

[ Data structure ]


[ main path ]
- main => ??

Reference

  • systemd
  • systemd.special (about default.target ...)
  • systemd.unit (about semantics of symlinks and Requires=, Wants= ...)
  • systemd.mount (about fstab generator)