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

**URL:** <https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767>\
**Category:** General Discussions\
**Created:** [July 1, 2019, 7:58am UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767 "2019-07-01T07:58:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [July 1, 2019, 7:58am UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/1 "2019-07-01T07:58:29Z")

</div>

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](https://lists.freedesktop.org/archives/systemd-devel/2019-July/042982.html) )Anyone did something similar and would be willing to share? Thanks.

---

<div class="post-metadata">

**Author:** ![samlewis](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/samlewis/32/393_2.png) [@samlewis](https://hub.mender.io/u/samlewis)\
**Post date:** [July 1, 2019, 8:11am UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/2 "2019-07-01T08:11:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [July 1, 2019, 8:31am UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/3 "2019-07-01T08:31:09Z")

</div>

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

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

exec /usrlib/systemd "$@"

```

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [July 1, 2019, 4:01pm UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/4 "2019-07-01T16:01:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TimFroehlich](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/timfroehlich/32/164_2.png) [@TimFroehlich](https://hub.mender.io/u/TimFroehlich)\
**Post date:** [July 1, 2019, 6:07pm UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/5 "2019-07-01T18:07:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [July 1, 2019, 6:39pm UTC](https://hub.mender.io/t/move-hostname-from-etc-to-data-etc-issues/767/6 "2019-07-01T18:39:28Z")

</div>

> [@mirzak](#):
>
> #!/bin/sh /bin/mount /dev/sda4 /data exec /usrlib/systemd “$@”

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:

```auto
[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](https://bugzilla.kernel.org/show_bug.cgi?id=200773#c2) anyway I’m not aware mounting any loopback device on my system. Thanks.
