DESK-MX-L-AN-0005: How to synchronize date/time

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box


200px-Emblem-important.svg.png

This application note has been validated using the kit version in the History table.


History
Issue Date Development Kit version
2022/06/22 DESK-MX6UL-L 1.0.1


Introduction[edit | edit source]

System date and time can be easily kept synchronized using the NTP services available on the Internet.

To set the date, you need to set your timezone information and activate the NTP protocol for your system to synchronize with NTP servers.

If the ntp package is not present in the root file system, it is possible to install it using the standard dnf tool as described here:

root@desk-mx6:~# dnf install ntp
desk-mx6l-cortexa9hf_neon                       2.0 MB/s | 3.1 MB     00:01
Last metadata expiration check: 0:00:08 ago on Tue Mar 31 09:05:08 2020.
Dependencies resolved.
================================================================================
 Package          Arch                 Version            Repository       Size
================================================================================
Installing:
 ntp              cortexa9hf_neon      4.2.8p11-r0        cortexa9hf      322 k
Installing dependencies:
 ntp-tickadj      cortexa9hf_neon      4.2.8p11-r0        cortexa9hf      8.4 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 330 k
Installed size: 783 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): ntp-tickadj-4.2.8p11-r0.cortexa9hf_neon. 109 kB/s | 8.4 kB     00:00
(2/2): ntp-4.2.8p11-r0.cortexa9hf_neon.rpm      1.1 MB/s | 322 kB     00:00
--------------------------------------------------------------------------------
Total                                           1.0 MB/s | 330 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : ntp-tickadj-4.2.8p11-r0.cortexa9hf_neon                1/2
  Running scriptlet: ntp-4.2.8p11-r0.cortexa9hf_neon                        2/2
Running useradd commands...
NOTE: ntp: Performing useradd with [ --system --home-dir /var/lib/ntp                        --no-create-home                        --shell /bin/false --user-group ntp]
  Installing       : ntp-4.2.8p11-r0.cortexa9hf_neon                        2/2
  Running scriptlet: ntp-4.2.8p11-r0.cortexa9hf_neon                        2/2
update-alternatives: Linking /usr/sbin/ntpd to /usr/sbin/ntpd.ntp
Created symlink /etc/systemd/system/multi-user.target.wants/ntpd.service \u2192 /lib/systemd/system/ntpd.service.
  Verifying        : ntp-4.2.8p11-r0.cortexa9hf_neon                        1/2
  Verifying        : ntp-tickadj-4.2.8p11-r0.cortexa9hf_neon                2/2

Installed:
  ntp.cortexa9hf_neon 4.2.8p11-r0    ntp-tickadj.cortexa9hf_neon 4.2.8p11-r0

Complete!
root@desk-mx6:~#

Then the /etc/ntp.conf file has to be modified according to the ntp server pool used for time synchronization, for example in Italy:

server 0.it.pool.ntp.org
server 1.it.pool.ntp.org
server 2.it.pool.ntp.org
server 3.it.pool.ntp.org

Timezone[edit | edit source]

Be sure you are properly configured for your locatimezone. In order to consult your current timezone on Linux, you can run the timedatectl command.

root@desk-mx6:~# timedatectl
                      Local time: Tue 2022-02-22 12:12:22 UTC
                  Universal time: Tue 2022-02-22 12:12:22 UTC
                        RTC time: Tue 2022-02-22 12:12:22
                       Time zone: Universal (UTC, +0000)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
root@desk-mx6:~#

For that purpose, you may have to install the proper tzdata package, for example:

root@desk-mx6:~# dnf install tzdata-europe
desk-mx6l-noarch                                 30 kB/s | 155 kB     00:05
Last metadata expiration check: 0:00:00 ago on Tue Feb 22 12:14:45 2022.
Dependencies resolved.
================================================================================
 Package                Arch            Version           Repository       Size
================================================================================
Installing:
 tzdata-europe          noarch          2018f-r0          noarch           25 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 25 k
Installed size: 132 k
Is this ok [y/N]: y
Downloading Packages:
tzdata-europe-2018f-r0.noarch.rpm               236 kB/s |  25 kB     00:00
--------------------------------------------------------------------------------
Total                                           202 kB/s |  25 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : tzdata-europe-2018f-r0.noarch                          1/1
  Verifying        : tzdata-europe-2018f-r0.noarch                          1/1

Installed:
  tzdata-europe.noarch 2018f-r0

Complete!
root@desk-mx6:~#

and then configure it using timedatectl

root@desk-mx6:~# timedatectl set-timezone Europe/Rome
root@desk-mx6:~# timedatectl status
                      Local time: Tue 2022-02-22 13:16:08 CET
                  Universal time: Tue 2022-02-22 12:16:08 UTC
                        RTC time: Tue 2022-02-22 12:16:09
                       Time zone: Europe/Rome (CET, +0100)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
root@desk-mx6:~#


By default, working with a distribution with systemd, you should have the systemd-timesyncd daemon by default, as seen before:

systemd-timesyncd.service active: yes