[systemd-devel] symlinking /etc/hostname to /data/etc/hostname woes
Lennart Poettering
lennart at poettering.net
Mon Jul 1 07:48:32 UTC 2019
On Mo, 01.07.19 08:25, Belisko Marek (marek.belisko at gmail.com) wrote:
> Hi,
>
> I'm working on rpi3 by using mender OTA system and for identifying
> devices I would like to have for every of it different hostname. As
> rootfs is update-able (rootA, rootB layout) so I tried to create file
> in /data/etc (which is permanent) and in /etc create symlink. When now
> boot my system I still get hostname localhost.
Two issues: /etc/hostname is read very early during boot, before PID 1
starts the first other userspace program. This means you'd have to
mount that fs from the initrd already, to be applied.
hostnamed and friends live in a sandbox these days, that prohibit
write access outside of /etc, and read access to various other
dirs. If you play such symlink games, you have to turn that off. See
the systemd-hostnamed.service service file, specifically
ProtectSystem= and similar options.
That all said, instead of introducing /data and keeping the whole of
the OS read-only, I'd recommend to instead operate with a read-only
/usr only, combined with a writable / that comes up in the initrd
already and is automatically populated on first boot. i.e. keep /etc
and everything else as empty as possible, and store only the stuff in
it actually needed. systemd itself is all set up for this mode, and is
happy if there's no configuration in /etc around. Some distros are not
that happy with such a set up however, they require some bits in /etc
existing. Ideally distros would be fixed to not require that and be
happy with /etc entirely empty, but until then you can use
tmpfiles.d/'s "C" lines copy in basic necessary configuration into
/etc from /usr/share/factory/.
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list