Site: US UK AU |
Nexcess Blog

Changing The Timezone In CentOS From The CLI

January 15, 2014 0 Comments RSS Feed

2013 Round Up

Red Hat’s documentation on how to change the timezone tells you to use a GUI to change. As a sysadmin, I’m not going to install a gigantic GUI to change a timezone on a server.

The correct way to change the timezone without a GUI is:

1. edit /etc/sysconfig/clock to be what you want
2. run /usr/sbin/tzdata-update which will update /etc/localtime

There are a million sites telling you to copy or link /usr/share/zoneinfo/herp/derp to /etc/localtime but if you’re on RHEL or CentOS and forget to set the timezone in /etc/sysconfig/clock, you’ll find your clock will be off the next time tzdata updates.

This happens because there is a trigger on glibc-common for the tzdata package to run /usr/sbin/tzdata-update which copies timezone set in /etc/sysconfig/clock to /etc/localtime. If you didn’t update your timezone in /etc/sysconfig/clock you’ll find your server will revert to the old time zone which is annoying.

I was perplexed why they used an RPM trigger to do this (I had never actually seen one used before) so I did some research and its to avoid circular dependencies where the tzdata package would require glibc but glibc requires tzdata. I thought the explanation in a red hat bug was good so I’ll just link to:
Red Hat Bugzilla – Search by bug number
Red Hat Bugzilla – Bug 167787

I also though a symlink would be a good idea but they stopped doing that since the time would be incorrect until /usr is mounted:
Re: Making /etc/localtime a symlink?

Posted in: Nexcess