1. Introduction
Maintaining the real-time clock (RTC) in local time on a Linux system can be crucial for various applications, especially while dealing with legacy software or systems that interoperate with other devices or systems set to local time.
By default, most Linux systems typically use UTC (Coordinated Universal Time) for the hardware clock, but there are situations where local time configuration is more suitable.
In this tutorial, we’ll present a comprehensive guide on configuring and maintaining the real-time clock in local time for different Linux distros.
2. Understanding Real-Time Clock
The real-time clock (RTC) is a hardware clock, usually embedded in the motherboard. It keeps track of the current time and date even when the computer is off. A CMOS battery typically powers the real-time clock and enables it to maintain the time and date across reboots and power losses.
Linux systems use two types of clocks:
- system clock or software clock: maintains the system clock and resets it on every boot based on the hardware clock
- hardware clock or RTC: keeps time and date independent of the operating system (OS)
By default, Linux sets the RTC to UTC and converts it to local time depending on the system’s time zone settings. However, some systems, particularly those dual-booting with Microsoft Windows, may need the RTC to be maintained in local time.
3. Setting Real-Time Clock to Local Time
To configure RTC to local time, the first step is determining if the system is currently set to use UTC or local time using the timedatectl command:
$ timedatectl status
Local time: Qib 2024-05-21 12:14:23 EAT
Universal time: Qib 2024-05-21 09:14:23 UTC
RTC time: Qib 2024-05-21 09:14:23
Time zone: Africa/Nairobi (EAT, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
The timedatectl command is available by default in most Linux distros. The output shows various pieces of information about the system clock settings.
In particular, we can check the last line that reads RTC in local TZ to determine whether the real-time clock uses local time or UTC.
Now, let’s use the timedatectl command to set the real-time clock to use local time:
$ sudo timedatectl set-local-rtc 1
Importantly, we run the command with superuser privileges to effect the changes.
Thus, we configure the real-time clock to local time. At this point, we can verify the change by re-running the timedatectl command:
$ timedatectl status
Local time: Qib 2024-05-21 13:16:21 EAT
Universal time: Qib 2024-05-21 10:16:21 UTC
RTC time: Qib 2024-05-21 10:16:21
Time zone: Africa/Nairobi (EAT, +0300)
[...]
RTC in local TZ: yes
Now, we can confirm the changes by checking whether the value of the last line is yes.
4. Handling Time Synchronization
Most Linux systems typically use systemd-timesyncd or ntpd for time synchronization. These services can adjust the system clock to match Internet time servers.
When using local time, we should ensure the time synchronization service handles it properly.
4.1. systemd-timesyncd
First, let’s check the status of systemd-timesyncd:
$ sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; ve>
Active: active (running) since Tue 2024-05-21 13:38:19 EAT; 14min ago
Docs: man:systemd-timesyncd.service(8)
[...]
If it’s running, it should adjust the system clock automatically.
4.2. ntdp
Next, for ntpd, we can first install it from the local package manager if unavailable:
$ sudo apt install ntp
Alternatively, on Arch Linux, we can use Pacman:
$ pacman -S ntp
Next, we configure ntpd to start at boot:
$ sudo systemctl enable ntp
Finally, we can start ntpd to set and maintain the system time of day in sync with Internet standard time.
5. Preventing Automatic Reversion
Some Linux distributions might occasionally revert the real-time clock setting to UTC when the system updates. To prevent this, we can add a configuration file.
To achieve this, let’s create or edit the /etc/adjtime file:
0.0 0 0.0
0
LOCAL
This instructs the system to treat the real-time clock as local time with zero drift.
6. Dual-Boot Considerations
If we’re dual-booting with Microsoft Windows, it’s important to ensure that both operating systems maintain the real-time clock correctly. By default, Microsoft Windows assumes the RTC is in local time, so no additional configuration is typically necessary.
However, we can modify the registry if we want Windows to use UTC, which is generally better practice.
To achieve this, we open the Registry Editor regedit.exe file and then navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation. Finally, we create a new DWORD value named RealTimeIsUniversal and set it to 1.
This change tells Windows to treat the real-time clock as UTC, aligning it with the Linux configuration if we use UTC.
7. Troubleshooting Common Issues
One of the most common issues occurring over time is that the real-time clock drifts and loses accuracy. Regular synchronization with Internet time servers can help mitigate this issue. We can also consider replacing old CMOS batteries on the motherboard to ensure the hardware clock is accurate, especially when we don’t have access to the Internet.
Another common issue to consider is daylight savings time (DST). If our region observes daylight saving time, we can ensure the Linux system’s timezone settings are configured correctly by reconfiguring the appropriate package:
$ sudo dpkg-reconfigure tzdata
Following the prompts, we can ensure the settings match the timezone configuration.
8. Conclusion
In this article, we’ve explored how to configure and maintain the real-time clock (RTC) in local time.
By following the steps above, we can configure Linux systems to use local time for the RTC, ensuring consistent timekeeping across different operating systems. Using UTC is generally preferred to avoid timezone-related issues, local time can be more convenient in specific scenarios.
Finally, we also looked at how to troubleshoot some of the most common issues to ensure we maintain correct timezone settings across the whole system.