9

I expected that timedatectl would update /etc/timezone when changing timezones, but no:

% sudo timedatectl set-timezone 'Asia/Kuala_Lumpur'
% cat /etc/timezone
Asia/Bangkok

Is there a reason that it doesn't? (Bug?)

If I manually update /etc/timezone to match timedatectl set-timezone, are there any side-effects I should be aware of?

Is there anywhere else I should consider changing timezone, eg xfce4 panel clock?

2
  • 1
    I don't think many things use /etc/timezone, localtime() and co. don't. if $TZ is not set, what matters is /etc/localtime Commented Jun 25, 2018 at 9:41
  • @StéphaneChazelas Java does use /etc/timezone, apparently...
    – Nickolay
    Commented Feb 7 at 12:31

3 Answers 3

7

timedatectl updates /etc/localtime, which is the documented way of setting the default timezone in most Linux-based environments (along with its override, the TZ environment variable, which is the only POSIX-defined way of specifying the timezone).

/etc/timezone appears to be mostly Debian-specific (including derivatives). On Debian systems, timedatectl set-timezone also updates /etc/timezone, in version of systemd older than 252.6-1 (so until Debian 11 included).

If you manually update /etc/timezone, you should also update the /etc/localtime symlink (and make sure you keep the latter a symlink). Updates to /etc/localtime appear to be taken into account by (most?) desktop environments, so there’s no need to use environment-specific tools to update the timezone.

If you’re running Debian, you should use dpkg-reconfigure tzdata to configure the default timezone; that updates /etc/localtime and /etc/timezone as above, and it also updates the selected timezone in the debconf database (which serves as the default when configuring tzdata). If you don’t do this, the next time tzdata is updated, the timezone will be restored to the value in the debconf database. dpkg-reconfigure tzdata also takes care of updating the SE Linux context, if you’re using SE Linux.

6
  • 1
    And to answer Tom's other question, timedatectl is a systemd thing that queries timedated over dbus and timedated derives the name of the timezone (like Europe/London) by doing a readlink() on /etc/localtime. If /etc/localtime is not a symlink, then that name cannot be derived as those timezone definition files don't contain that information. Commented Jun 25, 2018 at 9:55
  • I use dpkg-reconfigure tzdata on Debian to configure the system timezone. I assume it does what is needed. It does modify /etc/timezone and /etc/localtime Commented Jun 25, 2018 at 10:05
  • Thanks @Stéphane, good point about dpkg-reconfigure, running that is necessary to ensure the setting is preserved across package upgrades. Commented Jun 25, 2018 at 10:10
  • On Debian systems, timedatectl set-timezone also updates /etc/timezone - Hmm, not so on Manjaro (Arch-based). I've let them know.
    – Tom Hale
    Commented Jun 26, 2018 at 6:16
  • 1
    @Nickolay no worries, thanks for bringing it to my attention! Commented Feb 7 at 13:53
2

In the early days systemd (which timedatectl and timedated are parts of) used to update /etc/timezone. In v190 (around 2012) this behavior was constrained to Debian, which invented the file, and later the support was moved from upstream to distro patches. As far as I can see, Arch never supported this in their package.

According to the NEWS entry of systemd (253~rc2-1) experimental, the Debian maintainers plan to drop this from their patchset as well:

The Debian-specific /etc/timezone will no longer be supported by systemd-timedated, as it is no longer useful and its functionality has been subsumed into /etc/localtime, and tzdata will no longer create it.

(There are recent messages on debian-users talking about /etc/timezone being a legacy relic, the apparent inconsistency between their messages and the wiki on one hand, and what I experienced first-hand on an (admittedly not up-to-date) system on the other hand, is what prompted me to do this research.)

-2

/etc/timezone is fully optional on UNIX. It is not used by any official system software.

The timezone you have in mind is typically inherited from init(1) via login to the shell.

From the documentation, /etc/timezone is intended to contain time zone names in relation to host or domainnames.

5
  • What's an official system software? What do you mean by UNIX? What documentation are you referring to? Commented Jun 25, 2018 at 9:57
  • Software delivered with the system. Typical UNIX systems are Solaris, AIX, HP-UX. FreeBSD.
    – schily
    Commented Jun 25, 2018 at 9:59
  • 4
    Do any of those systems have a timedatectl command? Commented Jun 25, 2018 at 10:06
  • No, but the documented content of /etc/timezone is something like US/Eastern East.Sun.COM #Sun East Coast. Is this what timedatectlsets up?
    – schily
    Commented Jun 25, 2018 at 11:45
  • You seem to be referring to the /etc/timezone file used by the sysidtool software on Solaris to build NIS maps. It is specific to Solaris. timedatectl is a systemd utility to interact with its timedated service, which suggests the OP is running a GNU/Linux system using systemd's init framework, more specifically, probably a Debian-based one as that /etc/timezone file is mostly Debian-specific. See also 0pointer.de/public/systemd-man/timezone.html, out-of-date as systemd no longer uses that file even on Debian. Commented Jun 25, 2018 at 12:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .