Lets see how to check and correct the hardware clock of the system in case its wrong or not synced with system clock.
I. Check hardware and system clock of your system
[root@cavium11 log]# hwclock Wed 06 Apr 2022 05:41:53 AM EDT -1.000377 seconds [root@cavium11 log]# date Wed Apr 6 01:38:56 EDT 2022
Here we can see the hardware clock has different time than software clock.
Hence we can sync the hardware clock to the system clock and the issue should be resolved.
# hwclock -systohc --debug
III. Other Options
a. In case we want to sync hardware clock to system clock, i.e. in reverse order, we can try below command.
hwclock -hctosys --debug
b. Understanding /etc/adjtime file and adjusting hardware clock.
When our system boots, it takes the time from hardware clock.
We can adjust the hardware clock using this file.
[root@ngelinux001 ~]# cat /etc/adjtime -0.000017 1643268372 0.000000 1643268372 LOCAL [root@ngelinux001 ~]#
-0.000017 1643268372 0.000000
-0.000017 is the drift rate in seconds per day.
1643268372 number of seconds since 1969 UTC
0.000000 All zeros.
1643268372 number of seconds since 1969 UTC, same as second column above.
LOCAL –> it says either LOCAL or UTS.
c. Setting Hardware clock
[root@ngelinux001 ~]# hwclock --set --date "01/05/2022 22:41:15" [root@ngelinux001 ~]# hwclock Wed 05 Jan 2022 10:41:19 PM IST -0.797284 seconds
d. Running the hwclock command in test mode.
We can also run the hwclock command in test mode, so it will not make any changes.
And will run in test mode.
# hwclock --adjust --test --debug
Similarly you can use this “test” option with any hwclock command.