It looks like this thread fell through the cracks and no one replied to it, yet I came across it today when googling for something similar. I gather that a change made to the balena preload command back in February 2019 intentionally stepped back from setting the deviceName field and the BALENA_DEVICE_NAME_AT_INIT environment variable at preload time:
Before that change, a random name used to be generated locally, but it would mismatch the name set / generated through the balenaCloud API and then, at first boot, the supervisor would overwrite the preloaded name with the API name, and this would generate further confusion and problems (like a device reboot).
Could this be created during the preload process?
I gather that the current plan (not yet implemented) is for users/developers to add the device name to the config.json file at preload time, then for the supervisor to give precedence to that value (on first boot) when setting the BALENA_DEVICE_NAME_AT_INIT variable:
Meanwhile, if it was sufficient to have a permanent unique ID for the device, the suggestion is to use the device’s UUID (or a hash or “substring” of the UUID) instead of its name, perhaps by means of device preregistering.
I know this is an old thread so I’m not expecting much of a reply but…What is the latest on this issue?
In production, we are going to be writing the hostname to config.json, and it would be nice if BALENA_DEVICE_NAME_AT_INIT variable matched the hostname.
Is there any way of changing BALENA_DEVICE_NAME_INIT before the device is registered with Balena?
The code to support this on the device has been approved and is pending testing. Once it merges in then you will need a balenaOS release with this new version or later, and an updated preloader tool to use it. I am going to create an issue to tie all this together and then you can be notified when it’s ready.