[systemd-devel] /etc/machine-id and a read-only rootfs

Max Marrone max at opentrons.com
Mon Feb 22 22:44:03 UTC 2021


I'm trying to understand some implications of the way systemd loads
/etc/machine-id.

My understanding is, first: systemd reads /etc/machine-id during *early
boot.* At that point, I'm only guaranteed that the *root* filesystem will
be there for me.

Second: there's no way to delay that machine-id initialization until other
filesystems are ready. It happens early, no matter what.

Therefore: if I want a persistent machine-id across reboots, and I want
systemd to autogenerate it on first boot instead of me predefining it as
part of installation, then my machine needs the ability to write to its own
root filesystem.

For example, you couldn't have: (1) a permanently *read-only-*mounted root
filesystem, to which /etc belongs; (2) a separate partition containing a
writeable machine-id file, which gets bind-mounted atop /etc/machine-id.
Because the writable one would be available too late in the boot process.

Is all of this correct?

For context, I'm working on an embedded-ish device. We prefer to keep our
rootfs read-only. All of our writeable stuff, including some system-level
config files, is in a separate filesystem, accessible from the rootfs by
symlinks or bind mounts. To update the device's software, we replace the
whole root partition. This is nice because we never have to worry about an
update accidentally clobbering some piece of configuration that's meant to
be persistent. Our problem is that, since our rootfs images have an empty
/etc/machine-id, a new machine-id gets generated in memory each time the
device reboots.

I'm aware of systemd-machine-id-commit.service
<https://www.freedesktop.org/software/systemd/man/systemd-machine-id-commit.service.html>,
but that seems to only work for *remounting the rootfs* as read-write, not
using a different filesystem entirely. It would let me write-back the
machine-id when that filesystem becomes writable, but it wouldn't let me
postpone reading the machine-id until that filesystem is mounted. So
systemd would still generate a new machine-id on each reboot, I think.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210222/c70c6738/attachment.htm>


More information about the systemd-devel mailing list