I have an embedded linux machine which has a read-only root filesystem which is loaded from a UBI/UBIFS.
Every time the device boots it creates a new systemd machine-id which I understand from reading the documentation:
The machine ID is usually generated from a random source during system installation and stays constant for all subsequent boots. Optionally, for stateless systems, it is generated during runtime at early boot if it is found to be empty.
From reading the systemd machine-id-setup.c file, I have an understanding on how it works in the sense that, it will try to generate the machine-id at /etc/machine-id if it doesn't exist, if that fails and the partition is read-only, it will generate it in /run/machine-id and mount it to /etc/machine-id (not a symlink).
There question is, am I able to have a fixed machine-id for a stateless device? The two options I have are:
1) Store machine-id to non-volatile storage (external/eMMC):
- After booting, check if /etc/machine-id exists
- If doesn't exist, then continue through systemd services passing the service/mount which generates the machine-id (as normal).
- New service file: once machine-id has been generated then copy this string to a partition which is not in memory/NAND i.e. eMMC (non-volatile).
Therefore now that the device has been initialised at least once and the machine-id is stored in a non-volatile storage medium; boot sequence is now as follows:
- Device boots and mounts the non-volatile partition.
- Checks if non-volatile machine-id exists (same as first step above)
- This file exists therefore we mount it to /etc/machine-id
- The service file which handles the population of /etc/machine-id now does not execute because this already exists.
2) Modify the systemd machine-id-setup.c file and change the hardcoded directories where the machine-id is generated, stored and saved. However I would like to avoid this solution as it means I would have to modify the systemd system files.
Could anyone share some insight into this?