1 # systemd {#sec-systemd-state}
3 ## `machine-id(5)` {#sec-machine-id}
5 `systemd` uses per-machine identifier — {manpage}`machine-id(5)` — which must be
6 unique and persistent; otherwise, the system journal may fail to list earlier
9 `systemd` generates a random `machine-id(5)` during boot if it does not already exist,
10 and persists it in `/etc/machine-id`. As such, it suffices to make that file persistent.
12 Alternatively, it is possible to generate a random `machine-id(5)`; while the
13 specification allows for *any* hex-encoded 128b value, systemd itself uses
14 [UUIDv4], *i.e.* random UUIDs, and it is thus preferable to do so as well, in
15 case some software assumes `machine-id(5)` to be a UUIDv4. Those can be
16 generated with `uuidgen -r | tr -d -` (`tr` being used to remove the dashes).
18 Such a `machine-id(5)` can be set by writing it to `/etc/machine-id` or through
19 the kernel's command-line, though NixOS' systemd maintainers [discourage] the
22 [UUIDv4]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)
23 [discourage]: https://github.com/NixOS/nixpkgs/pull/268995
26 ## `/var/lib/systemd` {#sec-var-systemd}
28 Moreover, `systemd` expects its state directory — `/var/lib/systemd` — to persist, for:
29 - {manpage}`systemd-random-seed(8)`, which loads a 256b “seed” into the kernel's RNG
30 at boot time, and saves a fresh one during shutdown;
31 - {manpage}`systemd.timer(5)` with `Persistent=yes`, which are then run after boot if
32 the timer would have triggered during the time the system was shut down;
33 - {manpage}`systemd-coredump(8)` to store core dumps there by default;
34 (see {manpage}`coredump.conf(5)`)
35 - {manpage}`systemd-timesyncd(8)`;
36 - {manpage}`systemd-backlight(8)` and {manpage}`systemd-rfkill(8)` persist hardware-related
38 - possibly other things, this list is not meant to be exhaustive.
40 In any case, making `/var/lib/systemd` persistent is recommended.
43 ## `/var/log/journal/{machine-id}` {#sec-var-journal}
45 Lastly, {manpage}`systemd-journald(8)` writes the system's journal in binary
46 form to `/var/log/journal/{machine-id}`; if (locally) persisting the entire log
47 is desired, it is recommended to make all of `/var/log/journal` persistent.
49 If not, one can set `Storage=volatile` in {manpage}`journald.conf(5)`
50 ([`services.journald.storage = "volatile";`](#opt-services.journald.storage)),
51 which disables journal persistence and causes it to be written to