balena-io / docs

Documentation for the balenaCloud platform.
https://docs.balena.io/
Apache License 2.0
68 stars 367 forks source link

DBUS call to change hostname doesn't work on resinOS 2.0 because of RO-filesystem #462

Closed shaunmulligan closed 4 years ago

shaunmulligan commented 7 years ago

When trying to change the hostname using the example from here: https://docs.resin.io/runtime/runtime/#change-the-device-hostname

you get the following error:

Error System.Error.EROFS: Failed to set static hostname: Read-only file system
ab77 commented 7 years ago

Also getting this on Resin OS 2.0.6+rev3 (prod). Any work arounds?

imrehg commented 7 years ago

Also in the forums: https://forums.resin.io/t/read-only-file-system-when-calling-setstatichostname-via-dbus/1578

imrehg commented 7 years ago

@ab77 current workaround (sort of), is setting the hostname in the config.json, by adding a "hostname": "my_name" key-value pair to it. (see more at https://resin.io/blog/resinos-2-0-released-in-production/#otherfeaturesandfixes) :/

ykuzma1 commented 6 years ago

This problem also seems to be affecting other DBUS functionality like disabling the host NTP service: https://forums.resin.io/t/use-custom-ntp-server-s/1266/3

dhoney commented 6 years ago

Any update on this?
I have a need in production to roll this out.

Are the v1 API endpoints still working? Not having much luck with the alternative route here: https://github.com/resin-io/resin-supervisor/blob/master/docs/API.md#patch-v1devicehost-config

dt-rush commented 6 years ago

tl;dr: setting StaticHostname via DBus fails due to read-only rootfs, setting Hostname doesn't affect result of hostname command or mDNS responses from host OS. Simply use the config.json to control host-name (hence, can't change dynamically).

hostnamed is the daemon which handles the DBus messages on org.freedesktop.hostname1. Its method SetStaticHostname wants to modify /etc/hostname, but of course that's in the read-only root fs.

There's also SetHostname, which modifies the kernel dynamic hostname, but I've had no success there either. For example:

# SetHostname("hello-world")
root@resin:~# dbus-send \
>   --system \
>   --print-reply \
>   --dest=org.freedesktop.hostname1 \
>   /org/freedesktop/hostname1 \
>   org.freedesktop.hostname1.SetHostname \
>   string:"hello-world" \
>   boolean:true
method return time=1534012762.536926 sender=:1.35 -> destination=:1.34 serial=5 reply_serial=2

# get Hostname
root@resin:~# dbus-send \
>   --system \
>   --dest=org.freedesktop.hostname1 \
>   --print-reply /org/freedesktop/hostname1 \
>   org.freedesktop.DBus.Properties.Get \
>   string:org.freedesktop.hostname1 \
>   string:Hostname
method return time=1534012789.482289 sender=:1.35 -> destination=:1.36 serial=7 reply_serial=2
   variant       string "hello-world"

root@resin:~# hostname
resin

... so it seems that whatever SetHostname is setting is not affecting the value returned by hostname. Running an mDNS query for hello-world.local didn't turn up anything, but resin.local still broadcasts as living at the address of the host OS.

I'd recommend setting this through the config.json as mentioned in imrehg's comment above

pcarranzav commented 6 years ago

The best and recommended way to do this is to use the supervisor API endpoint to set the hostname: https://github.com/resin-io/resin-supervisor/blob/master/docs/API.md#patch-v1devicehost-config

We should update the docs to make it clear that the supervisor API is the way to do this.

garethtdavies commented 4 years ago

Closing, as docs were previously updated to the below:

Changing the device hostname is no longer possible via this method, due to the fact that the /etc/hostname file is stored on the read-only root partition. To change the device hostname, use the balena supervisor API.