All Products
Search
Document Center

Alibaba Cloud Linux:What do I do if the local time of an Alibaba Cloud Linux 2 instance falls behind the time of the NTP server after I start or restart the instance?

Last Updated:Dec 08, 2023

This topic describes the cause of the following issue and how to resolve the issue: After you start or restart an Elastic Compute Service (ECS) instance that runs Alibaba Cloud Linux 2, the local time of the instance falls behind the time of the Network Time Protocol (NTP) server.

Problem description

After you start or restart an instance that meets the following conditions, the local time of the instance differs from the time of the NTP server by 8 hours. You cannot run the hwclock -w command to change kernel time.

  • Image version: Alibaba Cloud Linux 2.1903

  • Kernel version: kernel-4.19.24-10.al7.x86_64 or earlier

Cause

The real-time clock is accurate, and _set-local-rtc_ is configured. However, the instance does not synchronize its local time with the NTP server when the operating systems of the instance with an early kernel version is started.

Solution

  1. Enable the following configurations in the kernel:

    # Set system time from RTC on startup and resume
    CONFIG_RTC_HCTOSYS=y
    #  RTC used to set the system time
    CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
  2. Add the hwclock --hctosys parameter to the /etc/rc.d/rc.local file so that the instance can synchronize its local time with the NTP server on startup.

    echo "hwclock --hctosys" >>/etc/rc.d/rc.local
    chmod +x /etc/rc.d/rc.local
  3. Optional. To resolve and prevent the issue, we recommend that you upgrade the kernel of the instance to kernel-4.19.34-11.al7.x86_64 or later.