[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: time zone and UTC issue



On Wed, Nov 28, 2012 at 03:55:16PM +0530, J. B wrote:
> 
> My box is configured to the local time zone from beginning, both hwclock and
> system time.

Firstly, to clarify, there are two clocks:
- hardware clock (UTC or local)
- system clock (UTC)

The system clock is *always* UTC.  Even if you, the user, are using
a local timezone, the local time is calculated based upon the time
in the UTC system clock.  Given that Linux is a multi-user system,
you can have several users, each in a separate timezone.  All see
file timestamps and other dates in their respective timezones,
though all of them are stored in UTC internally.  It's completely
transparent to the user.

> But linux always favor hwclock to UTC. What is the advantage of doing that ?

There are several reasons.  If you want to look in detail at this,
take a look at
- /lib/udev/hwclock-set
- /etc/init.d/hwclock.sh
- hwclock(8)

At boot, we have the following sequence:
- UTC hardware clock
  + system clock (UTC) set from hardware clock (UTC) by kernel
  + no further action

- LOCAL hardware clock
  + system clock (LOCAL) set from hardware clock (LOCAL) by kernel
  + system clock adjusted from LOCAL to UTC by hwclock-set or hwclock.sh

Since the system clock is UTC but is actually in local time for part
of the boot, this means that until it's corrected later in the boot,
it's incorrect to start with, and this can make the clock run backwards
at the time of adjustment, and this screws up timestamps prior to the
correction.  Having the hardware clock in UTC means that the clock is
correct (modulo any NTP adjustment) from the moment the kernel starts
executing.

The other issue with LOCAL is that if you dual boot, both operating
systems may change the hardware clock on daylight savings changes,
making the clock become inaccurate.  Since the clock doesn't know
if it's been adjusted, there's no way to know that the adjustment
should be applied (or not).  Even a single boot system doesn't have
a way to record whether or not the adjustment is made--there are
corner cases if the clock gets adjusted where it may be applied
twice (or not at all).  Storing the time in UTC solves all these
issues, since it never requires any daylight savings adjustment.

> If I need my hwclock to UTC then what should be the right way to do that ?
> I have followed "dpkg-reconfigure tzdata" and found it has changed the local time to
> UTC too. Confused .....

Just make sure that the date is set correctly (run "date" and set it
with "date --set="newdate" if it's wrong).  Then run
  hwclock --utc --systohc
to set the hardware clock from the system clock in UTC.  Look at
/etc/adjtime and you should see UTC on the third line.  Use --local
in place of --utc, and it switches it back to LOCAL.  I'd definitely
recommend using UTC though.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800


Reply to: