Linux clock shows invalid time (UTC vs Localtime problem)

In a Linux multi-boot system it often happens that one distro shows correct system time and another does not. The problem is in how the startup scripts interpret the hardware (BIOS) clock when setting the OS time (the so called System Clock).

If you want to learn more about this (and fix this problem PROPERLY!) – here’s an excellent article on the subject:

Below I am offering a “quick and dirty fix” for the impatient one 🙂

1. Make sure /etc/localtime is a symlink to your correct TZ file (which will be found somewhere in /usr/share/zoneinfo/…).
2. Make sure your correct TZ is specified in /etc/sysconfig/clock, e.g. ZONE=”Europe/Rome”
3. Depending on whether you intend to keep your hw (BIOS) clock in UTC or locatime add UTC=true or UTC=false to that file.
4. Execute hwclock and note what it tells you:
# hwclock
Tue 20 Sep 2011 01:26:34 PM EEST -0.422645 seconds

Let’s assume that the time shown above (as your local time) is actually the time kept as UTC, and that your correct local time would be +3hrs = 03:26:34 PM or 15:26:34.

So you need to set the hwclock with the correct time. So you set the hwclock to the correct (local!) time by using the above time string and changing the time to the correct time:

hwclock --set --date="Tue Sep 20 16:08:49 EEST 2011

At this stage you need to press the RESET button on your computer.

Yes, it is bad, I know…

So… If you don’t want to take chances with your data then don’t do it – follow the link I gave above, read the article and do the “proper” fix. Now… chances are… on a newly installed system, with no heavy processes running in the background accessing the harddisks – nothing bad will happen. But, then, hey – you know best if this is a risk you want to take so in the end it’s your call 😉

Leave a Reply

Your email address will not be published. Required fields are marked *