Linux and Windows handle timekeeping differently, especially concerning the system clock and hardware clock (commonly referred to as the RTC or CMOS clock). In Windows, the hardware clock is often set to local time, whereas Linux typically expects the hardware clock to be in UTC (Coordinated Universal Time). This discrepancy can lead to issues, especially in dual-boot systems where both operating systems adjust the clock differently.
In this guide, we will explore how to configure Linux to behave like Windows by forcing it to use local time for the hardware clock.
Why the Difference?
- Windows assumes the hardware clock is in local time to match the system time zone.
- Linux assumes the hardware clock is in UTC because:
- UTC avoids daylight saving time (DST) complexities.
- It ensures consistent behavior across time zones.
However, Linux can be configured to use local time for the hardware clock, achieving Windows-like behavior.
Steps to Force Linux to Use Hardware Time as Local Time
1. Check the Current Hardware Clock Setting
To see whether your Linux system uses UTC or local time for the hardware clock, run:
timedatectl
You’ll see output like:
Local time: Sun 2024-12-15 12:00:00 IST
Universal time: Sun 2024-12-15 06:30:00 UTC
RTC time: Sun 2024-12-15 12:00:00
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Look at the line RTC in local TZ
. If it says no
, your hardware clock is set to UTC.
2. Configure Linux to Use Local Time for the Hardware Clock
To make Linux treat the hardware clock as local time:
Step 1: Update the System Setting
Run the following command:
timedatectl set-local-rtc 1 --adjust-system-clock
Explanation:
set-local-rtc 1
tells Linux to use the hardware clock in local time.--adjust-system-clock
adjusts the system clock accordingly.
Step 2: Verify the Setting
Run timedatectl
again to confirm the change:
Local time: Sun 2024-12-15 12:00:00 IST
Universal time: Sun 2024-12-15 06:30:00 UTC
RTC time: Sun 2024-12-15 12:00:00
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes
The RTC in local TZ
field should now say yes
.
3. Ensure Correct Time Synchronization
To avoid time drift, ensure your system clock stays synchronized. Linux typically uses NTP (Network Time Protocol) for this purpose.
Check if NTP is Active
Run:
timedatectl show | grep NTPSynchronized
If it says yes
, NTP is active. Otherwise, enable it:
sudo systemctl enable --now systemd-timesyncd
4. Adjust Boot Configurations (Optional)
If you use GRUB to boot Linux, you can add a kernel parameter to ensure the time is set correctly on startup. Edit /etc/default/grub
:
sudo nano /etc/default/grub
Add or modify the line:
GRUB_CMDLINE_LINUX="rtc_mode=local"
Then, update GRUB:
sudo update-grub
5. Reboot and Test
Reboot your machine to apply the changes:
sudo reboot
After rebooting, verify the behavior by running timedatectl
again. The hardware clock should now behave like Windows.
Potential Issues
- Dual-Boot Systems:
- If both Linux and Windows adjust the hardware clock independently, you may experience time mismatches. Ensure both operating systems agree on the hardware clock format (local time).
- Daylight Saving Time:
- When using local time for the hardware clock, DST changes could cause issues. Using UTC avoids this problem.
- Time Drift:
- Without proper synchronization (e.g., NTP), time drift can occur. Always enable time synchronization to keep your system clock accurate.
Conclusion
By following these steps, you can force Linux to use the hardware clock in local time, aligning its behavior with Windows. While UTC is the preferred setting for Linux in most cases, this configuration can be helpful in specific setups, such as dual-boot systems, where consistency across operating systems is necessary.