Why is my systemd journal not persistent across reboots?
The reason for this behavior is that the machine identifier in /etc/machine-id
changes at every reboot. This starts a new logging directory under /var/log/journal
. Old logs can be viewed with the following command:
journalctl --merge
I'm still looking into the cause of the changing machine-id. Linode support is aware of the problem. I will update this answer when I know more.
UPDATE -- The root cause of the problem is simply that Linode zeroed out the contents of /etc/machine-id
from their filesystem images. The result is the following chain of events:
- The kernel loads and mounts the root filesystem read-only
- systemd, run from the initial ramdisk, tries to read
/etc/machine-id
from the root filesystem (the file exists but has zero contents) - systemd cannot read the machine identifier, but can also not write a new one since the root filesystem is mounted read-only
- systemd mounts
tmpfs
on/etc/machine-id
(Yes, apparently you can mount a filesystem onto a file) - systemd invokes systemd-machine-id-setup which generates a random machine-id and stores it in the now-volatile
/etc/machine-id
- The system boots with a volatile machine identifier
You can check if your system has a volatile, rather than a permanent machine-id by looking at the output of mount
:
$ mount | grep machine-id
tmpfs on /etc/machine-id type tmpfs (ro,mode=755)
The problem is easy to fix: simply write a persistent machine-id to the real /etc/machine-id
. This is easier said than done, however, because you cannot unmount tmpfs
from /etc/machine-id
on a running system. These are the steps I took to fix it on Linode:
cp /etc/machine-id /etc/machine-id.copy
, then poweroff the system- In the Linode Manager, go to the tab Rescue and boot into rescue mode
- Access the system via the Lish console
- Mount the root filesystem:
mount /dev/xvda /mnt
- Move the copy created in step 1 to the real machine-id:
mv /etc/machine-id.copy /etc/machine-id
- Reboot
Such are the consequences of a missing machine-id at boot. I hope this will help a random passer-by in the future.