Time synchronization between two systems

Source: Internet
Author: User
Tags time zones local time valid

First, we need to understand a few concepts:

1. "System time" and "Hardware Time"

System time: Typically the time we see the date command, all the time calls (except for direct access to the hardware time) in the Linux system are used this time.

Hardware time: The time in the BIOS on the motherboard, by the motherboard battery power to maintain operation, the system on the boot to read this time, and according to it to set the system time (note: System startup According to the hardware time to set the system time of the process may have time zone conversion, depending on the specific system and related settings).

2. "UTC Time" and "local time"

UTC time: Coordinated Universal 8 E2 I (H7 t0 ^/^time World coordinated Time (also known as World standard Time, world unification time), with GMT (Greenwich Mean time, Greenwich mean times), under general precision requirements, is a Kind of, in fact, that is to say GMT≈UTC, but UTC is calibrated by atomic clocks, more accurate.

local time: Because in different time zones, local time is generally different from UTC, the conversion method is

local time = UTC + Time zone or UTC = local time-time zone

Time zone East is positive, West is negative, for example, in China, the local time is used in Beijing time, on Linux display is CST (China Standard time, Chinese standard, when attention to the United States Central Standard when Standard time also abbreviated as CST, It's not the same as the CST here!), the time zone is East eight, or area +8, so cst=utc+ (+ 8 hours) or utc=cst-(+ 8 hours).

Second, time order

1. System Time Date

Call date directly and get the local time. If you want to get UTC time, use Date-u.

[12-01 19:07> ~]$ Date

Monday, December 07, 2009 14:22:20 CST

[12-01 19:07> ~]$ Date-u

Monday, December 07, 2009 06:22:22 UTC

2. Hardware Time/sbin/hwclock

Is the time in the BIOS the direct call to/sbin/hwclock display time? Not necessarily! This depends on whether UTC is enabled in/etc/sysconfig/clock, if UTC (Utc=true) is enabled, The time zone conversion is actually displayed, not the actual time in the BIOS, and if the--localtime option is added, the actual time in the BIOS is always obtained.

[12-01 19:07> ~]# Hwclock

December 07, 2009 Monday 14:28 43 sec -0.611463 seconds

[12-01 19:07> ~]# Hwclock--UTC

December 07, 2009 Monday 14:28 46 sec -0.594189 seconds

[12-01 19:07> ~]# Hwclock--localtime

December 07, 2009 Monday 06:28 50 sec -0.063875 seconds

3./etc/localtime

This file is used to set the system time zone, copy the corresponding file in/usr/share/zoneinfo/to/etc and rename it to LocalTime to modify the time zone settings, and this modification takes effect in time for the date command. This file is used by either date or Hwclock and will be converted between UTC and the local based on the time zone setting of the file.

4./etc/sysconfig/clock

This file is only valid for Hwclock, and seems to be only useful when the system starts and shuts down, such as modifying the Utc=true to Utc=false before and after the execution Hwclock (--UTC, or--localtime) has not changed, to restart the system before the birth Effect. Note: If you set Utc=false and restart the system, some commands are executed as follows:

Date December 07, 2009 Monday 19:26:29 CST

Date-u Monday, December 07, 2009 11:26:29 UTC

Hwclock December 07, 2009 Monday 19:26 30 sec -0.442668 seconds

Hwclock--UTC December 08, 2009 Tuesday 03:26 31 sec -0.999091 seconds

Hwclock--localtime December 07, 2009 Monday 19:26 32 sec -0.999217 seconds

Visible, if you do not use Utc,bios time (red part) is the system local time, and note that the execution of the Hwclock--UTC results does not make any sense, because we have disabled UTC, and obviously does not conform to the "local time =utc+ timezone" relationship.

Third, the time synchronization between Linux and Windows dual system

When the system starts and shuts down, there are two ways to sync between the hardware time and the system time (assuming that the CST represents local time in China):

Mode A: Use UTC (for Linux is/etc/sysconfig/clock utc=true)

Power on: BIOS------->UTC (consider time in BIOS as UTC)------(Time zone change)----->CST

Shutdown: CST-------(Time zone change)----->utc-------stored to------>bios

Mode B: Do not use UTC (for Linux is/etc/sysconfig/clock utc=false)

Power-on: BIOS--------------------->CST (consider the time in the BIOS as CST)

Shutdown: CST---------stored to------>bios

This can be supported by setting/etc/sysconfig/clock,linux, but Windows supports mode B (at least the default support B, and I don't know how to get it to support a), so in a dual-system scenario, if Linux is set to a mode, Then the Linux and Windows system switch will be caused by time confusion, the solution is to disable the UTC in Linux, also set to B.

Note: You can use the hardware time to set the system time by Hwclock--hctosys (note that it is not simple to copy the time in the BIOS to the system time, to see if UTC is used, and to do time zone conversion if used), through the Hwclock--SYSTOHC To set the hardware time based on the system time (also depends on whether UTC is enabled to decide whether to make a time zone conversion).

In short, regardless of the use of--SYSTOHC or--hctosys, after synchronization directly run without parameters of the Hwclock time and direct running date should be consistent, this time is the BIOS in the time (Hwclock--localtime) That is not necessarily true, if UTC is enabled, it is not, and UTC is not enabled.

Also note: Manually using Hwclock hwclock--set--date= ' YYYY-MM-DD ' in the system to set the BIOS time is only valid when the system is running, because when the system shuts down, the BIOS time is reset according to the system time, The manual settings are then overwritten.

The Linux clock is divided into system clocks (systems Clock) and hardware (real time Clock, short RTC) clocks. The system clock is the clock in the current Linux kernel, and the hardware clock is the battery-powered clock on the motherboard, which can be set in the BIOS. When Linux is started, the hardware clock will read the system clock settings, and the system clock will be independent of the hardware operation.

All the commands (including functions) in Linux are set by the system clock. In Linux, the commands for clock viewing and setting are mainly date, hwclock, and clock. In which, clock and hwclock usages are similar, only one on the line, but the clock command in addition to supporting the x86 hardware system, but also support the Alpha hardware system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.