Linux system time and hardware time settings
In Linux, there are two types of Clock: hardware clock and system clock. The hardware clock refers to the clock device on the motherboard, that is, the clock that can usually be set on the BIOS screen. The system clock is the clock in the kernel. All Linux-related commands and functions are read system clock settings. Because there are two different clock types, there will be differences between them. When Linux is started, the system clock reads the hardware clock settings, and then the system clock runs independently.
After the date command is used to set the system time, the hardware clock is not modified. Therefore, after the system is restarted, the system time is counted as the hardware time, this is why the date setting is invalid.
Therefore, you need to synchronize the system time to the hardware clock after setting the system time.
Clock/hwclock:
The display is the same as setting the hardware clock (query and set the hardware clock (RTC. RTC = Real Time Clock, that is, the hardware Clock.
Command parameters:
-R, -- show read and print the hardware clock (read hardware clock and print result)
-S, -- hctosys synchronize the hardware clock to the system clock (set the system time from the hardware clock)
-W, -- systohc synchronize the system clock to the hardware clock (set the hardware clock to the current system time)
Command example:
1. view the hardware clock
Thursday, March 27, 2014-50 seconds-0.328520 seconds
[Root @ localhost ~] # Hwclock-r
Thursday, March 27, 2014, 53 seconds-0.797264 seconds
[Root @ localhost ~] # Hwclock -- show
Thursday, March 27, 2014-01 seconds-0.672267 seconds
2. The clock and hwclock are the same.
Copy code
[Root @ localhost ~] # Type-a hwclock
Hwclock is/sbin/hwclock
Hwclock is/usr/sbin/hwclock
[Root @ localhost ~] # Ll/sbin/hwclock/usr/sbin/hwclock
-Rwxr-xr-x. 1 root 46940 November 22 23:27/sbin/hwclock
Lrwxrwxrwx. 1 root 18 March 26 19:27/usr/sbin/hwclock->.../sbin/hwclock
[Root @ localhost ~] # Type-a clock
Clock is/sbin/clock
[Root @ localhost ~] # Ll/sbin/clock
Lrwxrwxrwx. 1 root 7 March 26 19:27/sbin/clock-> hwclock
Copy code
3. Synchronize the system time to the hardware clock
Copy code
[Root @ localhost ~] # Hwclock
Thursday, March 27, 2014, 51 seconds-0.312960 seconds
[Root @ localhost ~] # Date
Thursday, March 27, 2014 10:50:55 CST
[Root @ localhost ~] # Hwclock-w
[Root @ localhost ~] # Hwclock
Thursday, March 27, 2014-15 seconds-0.875387 seconds
Copy code
Synchronize Network Time To system time
[Root @ localhost ~] # Ntpdate 210.72.145.44
27 Mar 11:11:24 ntpdate [4766]: adjust time server 210.72.145.44 offset 0.011401 sec
210.72.145.44 (IP address of the official time synchronization server of Xi'an Time Service Center, China)
After synchronizing the network time to the system time, you can use hwclock-w to synchronize the system time to the hardware time.
Modify Time Zone
Some systems may still fail after the above two steps are executed, so you need to modify the time zone.
[Root @ localhost ~] # Tzselect # select the time zone as prompted
[Root @ localhost ~] # Ln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
Modify the system time configuration file
[Root @ localhost ~] #/Etc/sysconfig/clock
# Open the clock file and change the content to the following:
UTC = true
ARC = false
ZONE = "Asia/Shanghai"
Restart the system
[Root @ localhost ~] # Reboot
This article permanently updates the link address: