# Messed up system clock

## Princess Firefly

I struggled for a while trying to get my clock working.  For some reason everytime I booted the clock would be set to some random time and date (within a few days of the correct time but still...).  

I eventually traced the problem down to the clock rc script (the one that's used at boot time is in /etc/runlevel/boot/clock but if you do a del and add of clock later it will copy the script from /etc/init.d/clock).

The script says (under start):

...

	if [ -x /sbin/hwclock ]

	then

		ebegin "Setting system clock to hardware clock ${TBLURB}"

		errstr="$(/sbin/hwclock --adjust ${myopts} 2>&1 >/dev/null)"

		errstr="${errstr}$(/sbin/hwclock --hctosys ${myopts} 2>&1 >/dev/null)"

		#hwclock do not return a fail status

		if [ -n "${errstr}" ]

		then

			eend 1 "Failed to set system clock to hardware clock"

...

The first 

		errstr="$(/sbin/hwclock --adjust ${myopts} 2>&1 >/dev/null)"

is the problem.  I have no idea what it's supposed to do (the next line sets the system clock to the hardware clock) and since it ends up screwing with my system clock I just commented it out and now everything works fine.  ie:

...

	if [ -x /sbin/hwclock ]

	then

		ebegin "Setting system clock to hardware clock ${TBLURB}"

#		errstr="$(/sbin/hwclock --adjust ${myopts} 2>&1 >/dev/null)"

		errstr="${errstr}$(/sbin/hwclock --hctosys ${myopts} 2>&1 >/dev/null)"

		#hwclock do not return a fail status

		if [ -n "${errstr}" ]

		then

			eend 1 "Failed to set system clock to hardware clock"

...

Comment it out in both /etc/runlevels/boot/clock and in /etc/init.d/clock in case you're adding and removing the clock script for some reason later on in the future.

I suppose the I commented out is supposed to do something useful somehow but I have no idea what.  If you do please respond to this cause I'm interested to know.

The Princess

----------

## steveD

I  have the same problem with the system clock. When I turn off my machine and turn on again the next day, the clock is messed up.

I think the clock file in the run level is a symbolic link to the real file in /etc/init.d. All real scripts are in this folder (/etc/init.d).

----------

## Malakin

By default gentoo assumes your sysem clock is set to GMT which is really dumb imo. Maybe this could be the problem for one of you. If so you can just edit /etc/rc.conf and change this clock="local"

Update: To be a little more clear, for an OS to assume your clock is set to gmt is dumb, not the idea of setting your clock to gmt.Last edited by Malakin on Tue Apr 30, 2002 6:10 am; edited 1 time in total

----------

## Guest

Setting the clock to GMT is not stupid, it is how things are done in *nix.

----------

## Stalione

GMT is the standard, if the user does not specify the time zone, setting it to GMT is not only normal but also the smart thing to do.  But of course that was just your opinion..and I respect that    :Smile: 

----------

## steveD

I just found out the solution for this clock mess-up problem.

The real problem is the file /etc/adjtime. The content of this file has something to do with the problem. Blanking out the content of this file or delete this file (it will be re-created next time), the problem will be gone.

----------

## Mrbook

I had exactly the same problem. What happened was that I had my system set up to "GMT" and later I changed it to "local" on /etc/rc.conf

If you do this YOU MUST delete /etc/adjtime (it will get created automaticelly again, so don't worry), since it has the values by which every time the clock gets adjusted, it must change in order to set the system time to GMT. Which is not what you want if your system is set to local.

----------

## Jeevz

Yup that worked for me. Thanks.

----------

## Manny Calavera

That helped for me, too   :Cool: 

Thank you!

see you,

- Manny -

----------

## drak

Thanks for the post it helped in tracking down the problem however for me it was not the actual cause!

after running 

```

hwclock --adjust --utc --debug

```

I found this

```

hwclock from util-linux-2.12

hwclock: Open of /dev/rtc failed, errno=2: No such file or directory.

No usable clock interface found.

Cannot access the Hardware Clock via any known method.

```

So I am currently recompiling my kernel with support for rtc, found under device drivers, char devices Enhanced Real Time Clock Support, or you could try to mknod the device!

----------

## toralf

```

nhh221 ~ # hwclock --adjust --utc --debug

hwclock from util-linux-2.12

hwclock: Open of /dev/rtc failed, errno=2: No such file or directory.

Using direct I/O instructions to ISA clock.

Last drift adjustment done at 1101802429 seconds after 1969

Last calibration done at 1101802429 seconds after 1969

Hardware clock is on local time

Assuming hardware clock is kept in UTC time.

Waiting for clock tick...

...got clock tick

Time read from Hardware Clock: 2004/11/30 09:21:17

Hw clock time : 2004/11/30 09:21:17 = 1101806477 seconds since 1969

Time since last adjustment is 4048 seconds

Need to insert 0 seconds and refer time back 0.000000 seconds ago

Needed adjustment is less than one second, so not setting clock.

```

And I haven't any RTC compiled into the kernel:

```

nhh221 ~ # grep -i rtc /usr/src/linux/.config

# CONFIG_RTC is not set

# CONFIG_GEN_RTC is not set

# CONFIG_SENSORS_RTC8564 is not set

```

 *Quote:*   

> By default gentoo assumes your sysem clock is set to GMT which is really dumb imo
> 
> 

 

Nope, because there is only one time - that is UTC - and every application can _display_ the representive local time.

----------

