# clock drift on each reboot

## dgulotta

Every time I reboot, my system clock gets about 35 seconds farther behind.  It seems that the problem is that the system time gets set at shutdown,  but /etc/adjtime isn't updated to reflect the fact that the system time was adjusted.  So at every boot the system thinks that it needs to compensate for all of the drift that happened since I last set the hardware clock manually.  The problem seems to occur with sys-apps/util-linux-2.28 and 2.26.2, but it didn't occur with 2.25.2-r2.  Is there any way I can fix this?

My /etc/conf.d/hwclock is just the standard one:

```
# Set CLOCK to "UTC" if your Hardware Clock is set to UTC (also known as

# Greenwich Mean Time).  If that 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="UTC"

# If you want the hwclock script to set the system time (software clock)

# to match the current hardware clock during bootup, leave this

# commented out.

# However, you can set this to "NO" if you are running a modern kernel

# and using NTP to synchronize your system clock.

#clock_hctosys="YES"

# If you do not want to set the hardware clock to the current system

# time (software clock) during shutdown, set this to no.

#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=""

```

Edit: I think this is a bug caused by hwclock --systohc changing its behavior in util-linux-2.26, and /etc/init.d/hwclock not being updated accordingly.

----------

## venomfang

Here is where i would start:

1) Rule out this being a hardware problem (ex bad cmos/bios battery).  This can be done by disabling the clock sync, doing a couple of reboot cycles and seeing if the time in the bios/uefi has drifted.

2) Are you using NTP at all to sync your time?   If you are you should really set the  clock_hctosys option to no.   It is redundant if you have a reliable network connectin to an ntp server.

3) Do you get any errors when you hwclock --systohc? Does hwclock --show show the correct time after this?  Just looking at ruling out the init script.

Hope this helps.

----------

## chithanh

You can check this by running

```
# /etc/init.d/hwclock restart
```

If every time you do that the clock shifts by 35 seconds then this points to a bug in util-linux or the init scripts.

----------

## cwr

For that reason, I don't adjust the CMOS clock at shutdown.  I just let the clock run and either reset

it with calls to NTPD or (usually) adjust the relative system clock time with adjtime.

Will

----------

## dgulotta

The drift happens when I run /etc/init.d/hwclock restart.  I added some echo statements and it seems that the script runs hwclock --hctosys (which takes drift into account) and hwclock --systohc --noadjfile (which updates the harwareclock without updating /etc/adjtime).

----------

