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

**URL:** <https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323>\
**Category:** General Discussions\
**Tags:** yocto, raspberrypi-cm3, systemd, warrior\
**Created:** [August 17, 2020, 8:38pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323 "2020-08-17T20:38:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 17, 2020, 8:38pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/1 "2020-08-17T20:38:53Z")

</div>

Hello,

One of the requirements in my project is to change timezone of the system. I am using timedatectl to achieve this.

My file system being read only I am unable to change the timezone on the device.

```
-rw-r--r-- 1 root root 10 Jul 17 21:48 timezone
lrwxrwxrwx 1 root root 29 Jul 17 21:48 localtime -> /usr/share/zoneinfo/Universal
-rw-r--r-- 1 root root 15 Aug 14 22:08 timestamp

```

Should I just create a symlink for timezone and timestamp ?

Edit1: I am currently looking at [https://bugs.launchpad.net/ubuntu/+source/ubuntu-system-settings/+bug/1227520](https://bugs.launchpad.net/ubuntu/+source/ubuntu-system-settings/+bug/1227520)

I think they are facing somewhat similar situation. But they are suggesting to create a symlink of /etc/localtime as well. Which I don’t understand?

---

<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:** [August 18, 2020, 2:26pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/2 "2020-08-18T14:26:19Z")

</div>

That is how I would start but it’s always a bit of trial and error to figure out everything that needs to be moved.

I haven’t tried this myself so I don’t have a definite answer though. Please let us know what you find.

Drew

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 18, 2020, 2:40pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/3 "2020-08-18T14:40:29Z")

</div>

> [@drewmoseley](#):
>
> That is how I would start

meaning just create a symlink of timezone and timestamp?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 18, 2020, 6:58pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/4 "2020-08-18T18:58:47Z")

</div>

I was able to create a symlink for `localtime` and `timezone` by editing the `tzdata` recipe file. But I am still unable to change the timezone.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 18, 2020, 9:27pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/5 "2020-08-18T21:27:29Z")

</div>

@drewmoseley how do people change timezone on a read-only file system?

---

<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:** [August 19, 2020, 1:07pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/6 "2020-08-19T13:07:20Z")

</div>

I don’t know. I can’t say I’ve ever tried that.  
Drew

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 20, 2020, 2:52pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/7 "2020-08-20T14:52:10Z")

</div>

So I think. I know what the issue might be. The file `timedated.c` actually looks for `\etc\localtime` it read and writes using that file specifically. So I think irrespective of what symlink I create I will not be able to change the timezone unless I change that link in the c file. But I have some trouble understanding the c file

```
static int context_read_data(Context *c) {
        _cleanup_free_ char *t = NULL;
        int r;

        assert(c);

        r = get_timezone(&t);
        if (r == -EINVAL)
                log_warning_errno(r, "/etc/localtime should be a symbolic link to a time zone data file in /usr/share/zoneinfo/.");
        else if (r < 0)
                log_warning_errno(r, "Failed to get target of /etc/localtime: %m");

        free_and_replace(c->zone, t);

        c->local_rtc = clock_is_localtime(NULL) > 0;

        return 0;
}   

```

Where is the function get\_timezone() defined?

---

<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:** [August 20, 2020, 5:23pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/8 "2020-08-20T17:23:12Z")

</div>

I assume that is a standard system function provided by the C library or some such.  
One possibility may be to use a bind mount of /etc/localtime into the /data partition. I have not tried it myself but that may work:

> # mount -t bind /data/localtime /etc/localtime

And then /data/localtime is the symlink to the file in /usr/share/zoneinfo.

Drew

---

<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:** [August 20, 2020, 5:24pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/9 "2020-08-20T17:24:25Z")

</div>

See [this link](https://www.yoctoproject.org/pipermail/yocto/2018-June/041454.html) for a discussion in the Yocto community about this.

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 20, 2020, 5:28pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/10 "2020-08-20T17:28:31Z")

</div>

I recently saw [this link](https://github.com/systemd/systemd/pull/8277/files). But your method sounds less painful

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 20, 2020, 8:20pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/11 "2020-08-20T20:20:59Z")

</div>

So based on that link. I did create a volatile bind.  
` VOLATILE_BINDS ?= "\ /data/system/localtime /etc/localtime \ n\ "`  
I do see  
`/data/system/localtime -> /usr/share/zoneinfo/Universal` But I am still unable to use `timedatectl set-timezone "America/New_York"`

Still the same error:  
`Failed to set timezone: failed to set timezone: Read only file system`

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 21, 2020, 9:57pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/12 "2020-08-21T21:57:22Z")

</div>

So I am able to change the timezone. But my `date` command is still in UTC?

```
root@raspberrypi-cm3:~# timedatectl
               Local time: Fri 2020-08-21 17:55:02 EDT
           Universal time: Fri 2020-08-21 21:55:02 UTC
                 RTC time: Fri 2020-08-21 21:55:03
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
root@raspberrypi-cm3:~# date
Fri Aug 21 21:55:16 UTC 2020
root@raspberrypi-cm3:~#

```

Any help or pointers why this could be happening?

---

<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:** [August 22, 2020, 9:08pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/13 "2020-08-22T21:08:42Z")

</div>

That’s just how the date command works. It does respect the TZ environment variable:

```
$ TZ=America/New_York date
Sat Aug 22 17:07:31 EDT 2020
$ TZ=America/Los_Angeles date
Sat Aug 22 14:07:44 PDT 2020

```

More details: [https://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-timezone](https://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-timezone)

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 24, 2020, 1:25pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/14 "2020-08-24T13:25:57Z")

</div>

But that was not how my system was behaving before the read-only rootfs.  
Below is an example of the system. That does not have a read-only rootfs

```
root@raspberrypi-cm3:~# date
Mon Aug 24 08:23:46 CDT 2020
root@raspberrypi-cm3:~# timedatectl
               Local time: Mon 2020-08-24 08:23:52 CDT
           Universal time: Mon 2020-08-24 13:23:52 UTC
                 RTC time: Mon 2020-08-24 13:23:53
                Time zone: America/Chicago (CDT, -0500)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
root@raspberrypi-cm3:~#

```

The problem with exporting TZ is I can execute it from a script. As it does not make a global change

FYI I am using [this link](https://github.com/systemd/systemd/pull/8277/files) as template

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 24, 2020, 6:36pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/15 "2020-08-24T18:36:39Z")

</div>

I got it working thanks a lot for all the help 🙂

---

<div class="post-metadata">

**Author:** ![SLIP76](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@SLIP76](https://hub.mender.io/u/SLIP76)\
**Post date:** [June 22, 2021, 11:18am UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/16 "2021-06-22T11:18:04Z")

</div>

@thesillywhat could you please share a solution for your problem? I’m facing the same issue now and do not want to reinvent the wheel… Thanks!

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [June 22, 2021, 6:33pm UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/17 "2021-06-22T18:33:54Z")

</div>

Look at the link in my comment above. I have currently marked that particular link as a solution.  
Also please let me know if you have found a better way

---

<div class="post-metadata">

**Author:** ![vssaran](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/vssaran/32/1753_2.png) [@vssaran](https://hub.mender.io/u/vssaran)\
**Post date:** [October 15, 2022, 6:23am UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/18 "2022-10-15T06:23:27Z")

</div>

@thesillywhat I am too facing similar issue with readonly root file system, I had follwed the link [this link](https://github.com/systemd/systemd/pull/8277/files) which you mentioned but still when changing timezone using timedatectl it showing Read-Only filesystem. Can you support me to resolve this issue.

The systemd version i was using is  
root@Docsis-Gateway:~# systemctl --version  
systemd 244 (244)  
+PAM -AUDIT -SELINUX +IMA -APPARMOR -SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL +XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN -PCRE2 default-hierarchy=hybrid

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [October 18, 2022, 9:41am UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/19 "2022-10-18T09:41:30Z")

</div>

@vssaran the link to the systemd PR is not really applicable, it was never merged. The technique that I’ve successfully used in the past is to softlink the required directories in `/etc` to a writeable, persistent place as mentioned in [Integrating timedatectl//systemd-timesyncd with readonly root file system - #8 by drewmoseley](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/8)

---

<div class="post-metadata">

**Author:** ![vssaran](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/vssaran/32/1753_2.png) [@vssaran](https://hub.mender.io/u/vssaran)\
**Post date:** [October 21, 2022, 4:10am UTC](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323/20 "2022-10-21T04:10:22Z")

</div>

@TheYoctoJester Thanks for the idea. It worked using mount-copybind.

[Next page](https://hub.mender.io/t/integrating-timedatectl-systemd-timesyncd-with-readonly-root-file-system/2323.md?page=2)
