1# systemd {#sec-systemd-state} 2 3## `machine-id(5)` {#sec-machine-id} 4 5`systemd` uses per-machine identifier — {manpage}`machine-id(5)` — which must be 6unique and persistent; otherwise, the system journal may fail to list earlier 7boots, etc. 8 9`systemd` generates a random `machine-id(5)` during boot if it does not already exist, 10and persists it in `/etc/machine-id`. As such, it suffices to make that file persistent. 11 12Alternatively, it is possible to generate a random `machine-id(5)`; while the 13specification 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 15case some software assumes `machine-id(5)` to be a UUIDv4. Those can be 16generated with `uuidgen -r | tr -d -` (`tr` being used to remove the dashes). 17 18Such a `machine-id(5)` can be set by writing it to `/etc/machine-id` or through 19the kernel's command-line, though NixOS' systemd maintainers [discourage] the 20latter approach. 21 22[UUIDv4]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) 23[discourage]: https://github.com/NixOS/nixpkgs/pull/268995 24 25 26## `/var/lib/systemd` {#sec-var-systemd} 27 28Moreover, `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 37 state; 38- possibly other things, this list is not meant to be exhaustive. 39 40In any case, making `/var/lib/systemd` persistent is recommended. 41 42 43## `/var/log/journal/{machine-id}` {#sec-var-journal} 44 45Lastly, {manpage}`systemd-journald(8)` writes the system's journal in binary 46form to `/var/log/journal/{machine-id}`; if (locally) persisting the entire log 47is desired, it is recommended to make all of `/var/log/journal` persistent. 48 49If not, one can set `Storage=volatile` in {manpage}`journald.conf(5)` 50([`services.journald.storage = "volatile";`](#opt-services.journald.storage)), 51which disables journal persistence and causes it to be written to 52`/run/log/journal`.