Time Settings always 4 hrs wrong [Solved]

Discussions Regarding Software

Moderator: Moderators

Time Settings always 4 hrs wrong [Solved]

Postby william4 » Sat Aug 16, 2008 23:18

The time shown on the top panel in my Sabayon 3.5 is almost always 4 hours ahead of the time that I have set (US Eastern time zone). I can reset it via System -> Adminstration -> Time and Date, but after the next boot it is wrong again. The configuration always goes to "manual" after I have changed it to "Keep synchronized with Internet servers". Does anybody know to solve this issue?

william4
Last edited by william4 on Sun Aug 17, 2008 3:31, edited 1 time in total.
william4
Young Hen
 
Posts: 25
Joined: Wed Aug 13, 2008 2:08

Re: Time Settings always 4 hrs wrong

Postby xlnagla » Sun Aug 17, 2008 0:38

You should Check your config files - there is an option to sync current time with system time using utc (which is common with windows dual-boot) - you may have that enabled. Either use utc and manual or disable this option to get your clock working.

~xlnagla
xlnagla
Sagely Hen
 
Posts: 1078
Joined: Mon May 28, 2007 2:44

Re: Time Settings always 4 hrs wrong

Postby Fitzcarraldo » Sun Aug 17, 2008 1:12

Basically you need to edit the file /etc/conf.d/hwclock (SL 3.5, has already been migrated to Baselayout-2 and OpenRC but if you were using SL 3.4 or earlier then the file would instead be /etc/conf.d/clock). Below are some notes I wrote last year but never posted, which are still relevant whether or not you dual boot with Windows. I have updated the text to include the differences following Baselayout-2 and OpenRC migration.

Clock, Time, UTC, dual boot with Windows

If you dual boot with Windows then this should be of interest to you. If you only run Linux on your PC then this still may be of interest to you if you need to know the time in other timezones (perhaps you have friends or relatives in other timezones, or you have a laptop and take it with you to other timezones).

A. TERMINOLOGY

First let me define a few terms I'm going to use in this post:

a) 'Hardware clock' (also known as 'BIOS clock' or 'CMOS clock') is the battery-backed clock on your motherboard.
b) 'System clock' is the software clock that only exists when Linux is running, and is the clock that is displayed on the Panel.
c) 'Local Time' is the time in your time zone.


B. INTRODUCTION

If you dual boot Linux and Windows, chances are that you've already come across the problem of the on-screen clocks in Linux and Windows having a difference of one or more hours; this usually happens twice a year when the clocks change in countries that adopt Daylight Saving Time (but can also occur in between depending on how the two OSs have been configured -- more about this later). You can experience various effects depending on how your Linux and Windows have been configured, such as the on-screen clock moving forwards (or backwards) by 1 hour in Linux on the allotted day, then when you boot Windows the clock moves forwards (or backwards) by a further 1 hour.

The first thing to know is that Windows stores the Local Time in the hardware clock and that is what is displayed in the System Notification Area on the Taskbar, whereas Linux keeps the times in the hardware clock and system clock separate, and only reads the time from the hardware clock at startup. When you boot Linux it reads the time in the hardware clock and sets the system clock to that time and applies any timezone offset that you have defined in a configuration file. Thus the time in the hardware clock and system clock can be -- and usually is -- different.

Linux is flexible and, if you want, you can configure it to write the time of the system clock to the hardware clock when you shutdown Linux. You don't have to do this, but it's a good idea. Why? Because the harware clock tends to drift with time, so it's good to adjust it now and again. If you either manually adjust your system clock to the correct time or use NTP (network time protocol) to do it automatically via the Internet then you will be ensuring that the hardware clock is kept at the correct time. The various Linux distros provide different ways of configuring how the distro behaves, but for Gentoo/SL there is an environment variable called CLOCK_SYSTOHC (clock_systohc if you have performed the Baselayout-2 and OpenRC migration) in a text file /etc/conf.d/clock (/etc/conf.d/hwclock if you have performed the Baselayout-2 and OpenRC migration) which is used for this purpose: making CLOCK_SYSTOHC="yes" (clock_systohc="yes" if you have performed the Baselayout-2 and OpenRC migration) will make Gentoo/SL write the time of the system clock to the hardware clock at shutdown. Conversely, making CLOCK_SYSTOHC="no" (clock_systohc="no" if you have performed the Baselayout-2 and OpenRC migration) will mean that the time of the system clock is not written to the hardware clock at shutdown.

Now, the text file /etc/conf.d/clock (/etc/conf.d/hwclock if you have performed the Baselayout-2 and OpenRC migration) can also contain an environment variable called CLOCK (clock if you have performed the Baselayout-2 and OpenRC migration). Here's an excerpt from the file clock, followed by an excerpt from the file hwclock:

Code: Select all
$ cat /etc/conf.d/clock
# /etc/conf.d/clock

# Set CLOCK to "UTC" if your system clock is set to UTC (also known as
# Greenwich Mean Time).  If your clock is set to the local time, then
# set CLOCK to "local".  Note that if you dual boot with Windows, then
# you should set it to "local".

CLOCK=""

# Select the proper timezone.  For valid values, peek inside of the
# /usr/share/zoneinfo/ directory.  For example, some common values are
# "America/New_York" or "EST5EDT" or "Europe/Berlin".

TIMEZONE=""


# If you wish to pass any other arguments to hwclock during bootup,
# you may do so here.

CLOCK_OPTS=""

# If you want to set the Hardware Clock to the current System Time
# during shutdown, then say "yes" here.

CLOCK_SYSTOHC=""

# Newer FHS specs say this file should live in /var/lib rather than
# /etc.  If you care about such things, feel free to change this value.
# Note that a blank value means that you do not wish to even use the
# adjtime facility.  This is the default behavior as adjtime can be
# very fragile.  If the clock is updated without updating the adjtime
# file (which is common when using services such as ntp), then the
# clock can be screwed up when it gets updated at next boot.

#CLOCK_ADJTIME="/var/lib/adjtime"
#CLOCK_ADJTIME="/etc/adjtime"
CLOCK_ADJTIME=""


### ALPHA SPECIFIC OPTIONS ###

# If your alpha uses the SRM console, set this to "yes".
SRM="no"

# If your alpha uses the ARC console, set this to "yes".
ARC="no"


Code: Select all
$ cat /etc/conf.d/hwclock
# Set CLOCK to "UTC" if your system clock is set to UTC (also known as
# Greenwich Mean Time).  If your clock is set to the local time, then
# set CLOCK to "local".  Note that if you dual boot with Windows, then
# you should set it to "local".
clock="local"

# If you want to set the Hardware Clock to the current System Time
# during shutdown, then say "YES" here.
# You normally don't need to do this if you run a ntp daemon.
clock_systohc="YES"

# If you wish to pass any other arguments to hwclock during bootup,
# you may do so here. Alpha users may wish to use --arc or --srm here.
clock_args=""

As you can see, the comment in the file recommends that you edit the file to make CLOCK/clock="local" if you dual boot with Windows. This appears to make sense, given that Windows' clock (the hardware clock) contains local time, so when you boot Linux it will copy the time in the hardware clock to the system clock, find that CLOCK/clock="local" and therefore not make any adjustment to the time in the system clock.

However, this can also cause problems. The first time you boot into Windows after Daylight Saving Time starts or finishes in your timezone, Windows will automatically detect this and, if you have 'Automatically perform Daylight Savings update' ticked, Windows will adjust the hardware clock because it assumes the hardware clock contains Local Time. Because Linux has no way of knowing this has happened, its system clock will be out by at least an hour. In addition, if you initially had the hardware clock set to UTC and are using CLOCK/clock="UTC" and have configured Linux to display the time in your timezone, the clock will be wrong under Windows too.

There are umpteen Web sites which suggest ways to get around the problem. Here's one suggestion that I've read for a different Linux distro:

1. Use your machine's CMOS setup utility to set the hardware clock to UTC.
2. Boot Windows. Go to Start/Settings/Control Panel and double click on "Date and Time". Uncheck the "Automatically adjust clock for daylight saving changes" box and click OK.

At this point, Linux will show correct local time and Windows will show UTC regardless of time zone. For me this is fine, as I use Linux 90% of the time and don't need a correct clock for any of the things I still boot Windows for. If, however, you do need a correct clock under both systems, perform the final step:

3. Restart the computer and boot Linux. Login to a terminal, and type (as root) the command:

echo 'UTC="no"' >> /etc/sysconfig/clock

This will cause Linux to perform the local time conversion when it reads from and writes to the hardware clock. As most distributions synchronize the hardware clock with system time on shutdown, this will cause local time to be written to the BIOS on your next reboot. This will keep Windows happy as the system clock now contains local time, but the double-adjustment problem is avoided because only Linux performs it [see Note 1 below]. Note: Although the above will work on Red Hat and Mandrake, under Debian the UTC value is stored in /etc/default/rcS instead. The commands will therefore need according adjustment.

Well, in the case of Gentoo/SL, that author's Step 3 would presumably be the following if you have not migrated to Baselayout-2 and OpenRC:
Edit /etc/conf.d/clock and a) make CLOCK="local", b) make TIMEZONE="<your timezone>" (if you are in Spain, for example, you would enter TIMEZONE="Europe/Madrid"), and c) set the timezone information as per Gentoo Handbook Chapter 7 (if you are in Spain, for example, you would enter the command: "cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime").
Or, if you have migrated to Baselayout-2 and OpenRC, the following:
a) Edit /etc/conf.d/hwclock and make clock="local", b) edit /etc/timezone and enter your timezone (if you are in Spain, for example, you would make the contents of the file /etc/timezone to be "Europe/Madrid" (without the quotes), and c) set the timezone information as per Gentoo Handbook Chapter 7 (if you are in Spain, for example, you would enter the command: "cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime"). The proper contents for the file /etc/timezone is the path relative to your timezone from /usr/share/zoneinfo. For example, for someone living on the east coast of the United States, the correct contents of /etc/timezone would be "America/New_York" (without the quotes).


Note 1: Notice that the time of the Windows clock will not change if you boot Windows first following the start/end of Daylight Saving Time. The Windows clock will only be correct again once you have booted and shutdown Linux.


C. MY SITUATION

I am based in the UK but I travel frequently with my laptop to different timezones. I also have friends, relatives and work colleagues in various timezones who I contact often, so I need to know what time it is there before telephoning. And, just to complicate matters further, I dual boot SL and Windows XP. I have configured KDE to display nine timezones (cities) and 'UTC' by using 'Show Timezone' > 'configure Timezones...'.


D. ONE SOLUTION

If I were to set the Windows clock to the timezone of the area where I live "(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London", untick "Automatically adjust clock for daylight saving changes", and make the Linux variables clock="local", /etc/timezone "Europe/London" and clock_systohc="yes" then, providing I stayed in the UK, my hardware clock and my Linux system clock would be correct (with the caveat in Note 1 above). Furthermore in Linux I could make the Panel display the times of all the timezones I have ticked in 'Show Timezone' > 'Configure Timezones...' by hovering my mouse pointer over the clock in the Panel.

If I were to travel to another timezone, I could change the time displayed by the clock in the Panel to the time of the timezone I'm in by right-clicking on the clock in the Panel and simply selecting, from the drop-down list under 'Show Timezone', the timezone I'm in. This would not change the time in the system clock, which would remain as the time at the Local Timezone (UK time, as I have not changed the Local Time), just the time displayed in the Panel. If I boot into Windows it would still display the time in the UK.

If I were to change the Windows clock to a different timezone to reflect the new one I'm now in, the next time I boot into Linux it would make the Local Timezone time equal to the local time in the hardware clock and write the time in the system clock to the hardware clock on shutdown. Both the time in Local Timezone and the time in the hardware clock would then be correct. So, wherever I am, I can change the configuration of the timezone of the Windows clock to the timezone I happen to be in (but leave the Daylight Saving Time correction unticked). I would also need to edit /etc/timezone to contain the new timezone, and set the timezone information as per Gentoo Handbook Chapter 7.

EDIT: Modified the second-to-last paragraph to make it clearer, and deleted the last paragraph as I think it was incorrect.
Last edited by Fitzcarraldo on Sun Aug 17, 2008 3:23, edited 1 time in total.
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7998
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: Time Settings always 4 hrs wrong

Postby william4 » Sun Aug 17, 2008 2:30

Thank you, Fitzcarraldo, for your very detailed message. I have to study it a bit more,but for the moment the following. I do not have Windows, I have a laptop with triple-Linux boot. The others are Ubuntu 8.04 and Pardus 2008. I use SB 3.5 most of the time, but when I use the others, their time setting is always correct. I am in timezone America/Detroit (Eastern). The settings of the files that you describe were exactly the way I had them on my system, so it is not clear why that time is sometimes off. Perhaps I should make sure that when I shut down, the time setting is correct, as it is written to the hardware, as you said.

william4
william4
Young Hen
 
Posts: 25
Joined: Wed Aug 13, 2008 2:08

Re: Time Settings always 4 hrs wrong

Postby jsizzle » Sun Aug 17, 2008 2:32

Fitzcarraldo, you should consider submitting to the wiki large portions of your detailed answer, that way it will be easy to point folks to.

Just a suggestion,
Jsizzle
Jsizzle
jsizzle
Baby Hen
 
Posts: 18
Joined: Sun Jan 13, 2008 1:59

Re: Time Settings always 4 hrs wrong

Postby Fitzcarraldo » Sun Aug 17, 2008 2:47

william4 wrote:Thank you, Fitzcarraldo, for your very detailed message. I have to study it a bit more,but for the moment the following. I do not have Windows, I have a laptop with triple-Linux boot. The others are Ubuntu 8.04 and Pardus 2008. I use SB 3.5 most of the time, but when I use the others, their time setting is always correct. I am in timezone America/Detroit (Eastern). The settings of the files that you describe were exactly the way I had them on my system, so it is not clear why that time is sometimes off. Perhaps I should make sure that when I shut down, the time setting is correct, as it is written to the hardware, as you said.

william4


Make sure that the clock="<local/UTC>" and clock_systohc="<YES/NO>" settings in all three distros match, and make sure that the timezone in all three distros match. A not-very-satisfactory work-around if you can't solve it would be to make clock_systohc="NO" for SL only, to stop SL at shutdown overwriting the correct time in the hardware clock that was set by the other two distros. But you should be able to fix SL to work correctly.
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7998
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: Time Settings always 4 hrs wrong

Postby Fitzcarraldo » Sun Aug 17, 2008 2:54

jsizzle wrote:Fitzcarraldo, you should consider submitting to the wiki large portions of your detailed answer, that way it will be easy to point folks to.

Just a suggestion,
Jsizzle

Yes, the thought had occurred to me, but it needs to be simplified as it confuses even me now after not having read it for several months!
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7998
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: Time Settings always 4 hrs wrong [solved]

Postby william4 » Sun Aug 17, 2008 3:30

Fitzcarraldo, the setting in my Pardus distro was not correct. It actually showed the same problem as in Sabayon 3.5. All three distros are now set equal and SB starts up with the correct time now. Thanks!

william4
william4
Young Hen
 
Posts: 25
Joined: Wed Aug 13, 2008 2:08


Re: Time Settings always 4 hrs wrong [solved]

Postby xlnagla » Sun Aug 17, 2008 4:19

wow, really nice job Fitzcarraldo - like jsizzle says, this is just too good not to make a wiki page of! Even in its current form it's better than nothing, and besides once you post it others can sure up any bits that confuse them, so that the owness isn't solely on you.

~xlnagla
xlnagla
Sagely Hen
 
Posts: 1078
Joined: Mon May 28, 2007 2:44

Next

Return to Software in General

Who is online

Users browsing this forum: No registered users and 1 guest