Integrating timedatectl//systemd-timesyncd with readonly root file system

Are you able to set different timezone using mount-copybind?

Apologies for the necropost but this seems worth reopening.

@TheYoctoJester @thesillywhat @vssaran @SLIP76
Were you trying to persist changes /etc/localtime to a RW partition, or were you OK with changes being written to a volatile overlay/partition and subsequently lost on reboots?

Iā€™m asking because AFAICT binding /etc/localtime to a persistent partition is not a workable solution.

timedated does ā€œatomic writesā€ where the the symlink is created with a temp name, then moved to /etc/localtime with a C rename(). If attempted over a bindmounted /etc/localtime, this fails with a ā€œresource busyā€ error

Generally speaking and AFAICT, a symlink cannot be created at a bind mounted path. And mount-copybind cannot overcome that.

My hunch is everyone here who reported getting this working was either:

  • fine with TZ being lost on reboots and/or system updates
  • fine with bindmounting the whole /etc directory
  • fine with patching systemd/timedated to write the symlink to another location
  • did not use systemd/timedated
  • or built some service to keep /etc/localtime in sync with a copy located on a writeable path

If Iā€™m mistaken, Iā€™d love to see some actual code!

In my case, I have reached a point where I think Iā€™ll leave the whole system in Universal time, and manage timezone at the application layer. Less moving parts and complexity to manage.

It depends on what your application is trying to do.

My application could not be on UTC. For me it was less work.
So whatever helps you achieve it. Mine works okay for my application.

In my case, I have reached a point where I think Iā€™ll leave the whole system in Universal time, and manage timezone at the application layer. Less moving parts and complexity to manage.

It depends on what your application is trying to do.
My application could not be on UTC. For me it was less work.
So whatever helps you achieve it. Mine works okay for my application.

FWIW, our application also needs to be timezone-aware. We just probably donā€™t need the rest of the system to be timezone-aware.

In this case, it means weā€™ll probably end up writing the TZ information to a file on a persistent partition, and use that as a sytemd EnvironmentFile so the TZ env var is used by our app.

Anyway, Iā€™m still curious to know if anyone here did manage to get timedated working with a /etc/localtime bind mounted to a persistent partition.

I didnā€™t and from what I have gathered, Systemd isnā€™t to keen on that. I had a big discussion with lennart pottering who not only rejected my patch but failed to provide me with a better solution.

And I didnā€™t tell him to do the work. I was willing to do the work and put in testing time.
But yes, if anyone has better solution. I am open to ideas.