Use paths specified from environment variables for /etc configuration files

Some configuration files that need updates are directly under in /etc. To
update them atomically, we need write access to /etc. For Ubuntu Core this is
an issue as /etc is not writable. Only a selection of subdirectories can be
writable. The general solution is symlinks or bind mounts to writable places.
But for atomic writes in /etc, that does not work. So Ubuntu has had a patch
for that that did not age well.

Instead we would like to introduce some environment variables for alternate
paths.

 * SYSTEMD_ETC_HOSTNAME: /etc/hostname
 * SYSTEMD_ETC_MACHINE_INFO: /etc/machine-info
 * SYSTEMD_ETC_LOCALTIME: /etc/localtime
 * SYSTEMD_ETC_LOCALE_CONF: /etc/locale.conf
 * SYSTEMD_ETC_VCONSOLE_CONF: /etc/vconsole.conf
 * SYSTEMD_ETC_ADJTIME: /etc/adjtime

While it is for now expected that there is a symlink from the standard, we
still try to read them from that alternate path. This is important for
`/etc/localtime`, which is a symlink, so we cannot have an indirect symlink or
bind mount for it.

Since machine-id is typically written only once and not updated. This commit
does not cover it. An initrd can properly create it and bind mount it.
This commit is contained in:
Valentin David
2025-03-10 10:53:41 +01:00
committed by Lennart Poettering
parent fa34fda2eb
commit 0dc39dffbd
19 changed files with 376 additions and 48 deletions

View File

@@ -294,6 +294,9 @@ All tools:
first existing unit listed in the environment variable, and
`timedatectl set-ntp off` disables and stops all listed units.
* `$SYSTEMD_ETC_ADJTIME` - override the path to the hardware clock settings
file. The default is `/etc/adjtime`.
`systemd-sulogin-shell`:
* `$SYSTEMD_SULOGIN_FORCE=1` — This skips asking for the root password if the
@@ -787,3 +790,25 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
`systemd.factory_reset=` kernel command line option: if set to false,
requesting a TPM clearing is skipped, and the command immediately exits
successfully.
`systemd-timedated`, `systemd-firstboot`, `systemd`:
* `$SYSTEMD_ETC_LOCALTIME` - override the path to the timezone symlink. The
default is `/etc/localtime`. The directory of the path should exist and not
be removed.
`systemd-hostnamed`, `systemd-firstboot`:
* `$SYSTEMD_ETC_HOSTNAME` - override the path to local system name
configuration file. The default is `/etc/hostname`.
* `$SYSTEMD_ETC_MACHINE_INFO` - override the path to the machine metadata file. The
default is `/etc/machine-info`.
`systemd-localed`, `systemd-firstboot`:
* `$SYSTEMD_ETC_LOCALE_CONF` - override the path to the system-wide locale
configuration file. The default is `/etc/locale.conf`.
* `$SYSTEMD_ETC_VCONSOLE_CONF` - override the path to the virtual console
configuration file. The default is `/etc/vconsole.conf`.