meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sw:yocto:overlayfs:machine-id [2026/04/10 13:23] – created niziaksw:yocto:overlayfs:machine-id [2026/04/10 19:10] (current) niziak
Line 1: Line 1:
 ====== machine-id ====== ====== machine-id ======
  
-Read only rootfs+Read only root FS
-  * with tmpfs overlay on /etc +  * with preinit script (before real /sbin/init) 
-  with preinit to bind mount persistent /mnt/state/machine-id on /etc/machine-id. +    * tmpfs overlay on ''/etc'' mounted 
-  * fist boot works well+    * bind mount persistent ''/mnt/state/machine-id'' on ''/etc/machine-id''
 +  * first boot works well
   * after reboot systemd complains:   * after reboot systemd complains:
  
Line 15: Line 16:
 </code> </code>
  
 +[[https://www.linux.org/docs/man8/systemd-machine-id-commit.html|SYSTEMD-MACHINE-ID-COMMIT(1)]]
  
-<code> +It runs because of conditions defined in unit file:
-### Editing /etc/systemd/system/systemd-machine-id-commit.service.d/override.conf +
-### Anything between here and the comment below will become the contents of the drop-in file+
  
 +<file ini systemd-machine-id-commit.service>
 +[Unit]
 +DefaultDependencies=no
 +Conflicts=shutdown.target
 +Before=shutdown.target
 +After=local-fs.target first-boot-complete.target
 +ConditionPathIsReadWrite=/etc
 +ConditionPathIsMountPoint=/etc/machine-id
  
 +[Service]
 +Type=oneshot
 +RemainAfterExit=yes
 +ExecStart=systemd-machine-id-setup --commit
 +</file>
  
-### Edits below this comment will be discarded 
  
 +This unit is designed to be run when ''/etc/machine-id'' is in transient state (e.g. bind mounted to tmpfs by systemd),
 +so ''ConditionPathIsMountPoint=/etc/machine-id'' is fulfilled in our case.
  
-### /usr/lib/systemd/system/systemd-machine-id-commit.service +As workarund ''ConditionFirstBoot=yes'' is added: 
-# #  SPDX-License-Identifier: LGPL-2.1-or-later +<file ini /etc/systemd/system/systemd-machine-id-commit.service.d/bind-mount-fix.conf> 
-# # +[Unit] 
-# #  This file is part of systemd+ConditionPathIsReadWrite=|/etc 
-# # +ConditionPathIsReadWrite=|/mnt/state/machine-id 
-# #  systemd is free software; you can redistribute it and/or modify it +ConditionFirstBoot=yes 
-# #  under the terms of the GNU Lesser General Public License as published by +ConditionPathIsMountPoint=/etc/machine-id 
-# #  the Free Software Foundation; either version 2.1 of the License, or +</file>
-# #  (at your option) any later version. +
-+
-[Unit] +
-# Description=Commit a transient machine-id on disk +
-# Documentation=man:systemd-machine-id-commit.service(8) +
-# DefaultDependencies=no +
-# Conflicts=shutdown.target +
-# Before=shutdown.target +
-# After=local-fs.target first-boot-complete.target +
-ConditionPathIsReadWrite=/etc +
-# ConditionPathIsMountPoint=/etc/machine-id +
-+
-# [Service] +
-# Type=oneshot +
-# RemainAfterExit=yes +
-# ExecStart=systemd-machine-id-setup --commit +
-# TimeoutSec=30s+
  
-</code>+Second approach is [[https://github.com/systemd/systemd/issues/39438|persisting /etc/machine-id on system which is bootstrapped from immutable /usr, with tmpfs on / #39438]]: 
 + 
 +<file ini /etc/systemd/system/systemd-machine-id-commit.service.d/bind-mount-fix.conf> 
 +[Unit] 
 +ConditionPathIsReadWrite= 
 +ConditionPathIsReadWrite=/var/mutable/etc/ 
 +ConditionPathIsMountPoint= 
 +ConditionPathIsMountPoint=/var/mutable/etc/machine-id 
 + 
 +[Service] 
 +ExecStart= 
 +ExecStart=systemd-machine-id-setup --commit --root=/var/mutable/ 
 +</file> 
 + 
 +More about problem: 
 +[[https://github.com/systemd/systemd/issues/14131|Various use-cases for first boot/machine-id are broken #14131]]