Move hostname from /etc/ to /data/etc issues

Hi,

for my project on rpi3 I want to use different hostname for every device. I’ve tried just symlink /etc/hostname to /data/etc/hostname but seems it’s not working easily (look this systemd reply )Anyone did something similar and would be willing to share? Thanks.

I do something similar and do it by having a oneshot systemd service that has After=config.mount set, and runs /bin/hostname -F /etc/hostname. Seems to work well!

I have also used the trick mentioned in the linked thread, that is make sure /data is mounted before systemd runs with a custom init script,

e.g

#!/bin/sh
/bin/mount /dev/sda4 /data

exec /usrlib/systemd "$@"

systemd has the concept of a transient hostname that can probably be utilized here. Basically, if your rootfs is read-only, you obviously can’t write to /etc/hostname and probably don’t want to remount rw to do so. I think you can just call something like “hostnamectl --transient set-hostname foo” in a start script. I’m not sure if there are still programs out there that will directly read from /etc/hostname so it may fail in that case.

Thirding @samlewis and @mirzak’s posts. That’s what I do.

OK I’ve added similar (just change /usrlib/systemd to /lib/systemd/system hostname works fine but I start getting on serial console messages like:

[  193.798330] F2FS-fs (loop0): Can't find valid F2FS filesystem in 2th superblock
[  212.820053] F2FS-fs (loop0): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[  212.827088] F2FS-fs (loop0): Can't find valid F2FS filesystem in 1th superblock
[  212.836804] F2FS-fs (loop0): Magic Mismatch, valid(0xf2f52010) - read(0x0)

it looks similar to that anyway I’m not aware mounting any loopback device on my system. Thanks.