When working with time synchronization on CentOS 7, chrony is often the preferred choice over ntpd. The configuration shown in /etc/chrony.conf
includes several important directives:
# Allow stepping the system clock if offset > 1 second
makestep 1.0 3
# Enable kernel RTC synchronization
rtcsync
# Hardware timestamping support
hwtimestamp *
Before forcing synchronization, check your current time status with:
chronyc tracking
chronyc sources
To force chrony to immediately update both system and hardware clocks, use these commands:
# Step the system clock immediately
chronyc makestep
# Force hardware clock update
chronyc -a 'rtcsync'
hwclock --systohc --utc
After executing these commands, verify the changes with:
date
hwclock --show
chronyc tracking
For scenarios requiring regular forced synchronization, create a script:
#!/bin/bash
# Force chrony sync and update hardware clock
chronyc makestep
chronyc -a 'rtcsync'
hwclock --systohc --utc
If you encounter problems:
- Check chrony logs:
journalctl -u chronyd
- Verify NTP server reachability
- Ensure proper permissions for hwclock operations
When working with legacy systems or time-sensitive applications, you might encounter situations where the system clock drifts significantly. In this case, we see a CentOS 7 system reporting February 1978 while chrony is properly configured with a working NTP server (chronos.univ-brest.fr).
Chrony's default configuration (with makestep 1.0 3) only allows stepping the clock during the first three updates when the offset exceeds 1 second. For larger time drifts, especially decades-old discrepancies, we need more aggressive measures.
# Current chrony.conf settings affecting clock adjustment
makestep 1.0 3 # Only allows stepping for first 3 updates with >1s offset
rtcsync # Syncs hardware clock periodically but not instantly
Here's the step-by-step approach to force immediate hardware clock sync:
# 1. First stop the chronyd service
sudo systemctl stop chronyd
# 2. Perform manual NTP sync using ntpdate (if available)
sudo ntpdate chronos.univ-brest.fr
# 3. If ntpdate isn't available, use chronyd in offline mode
sudo chronyd -q "server chronos.univ-brest.fr iburst"
# 4. Write the system time to hardware clock
sudo hwclock --systohc
# 5. Restart chronyd
sudo systemctl start chronyd
# 6. Verify the sync
chronyc tracking
To prevent future occurrences, modify /etc/chrony.conf:
# More aggressive time correction settings
makestep 1000 1 # Allow stepping any time offset exceeds 1000 seconds
rtcsync # Keep this enabled for periodic hardware clock sync
If you encounter issues, check these diagnostic commands:
# Check NTP server accessibility
chronyc activity
# Detailed synchronization information
chronyc sources -v
# Hardware clock status
sudo hwclock --debug
# Chrony logs inspection
journalctl -u chronyd --no-pager -n 50
For systems where chrony proves problematic, consider these alternatives:
# Using systemd-timesyncd (if available)
timedatectl set-ntp true
# Manual time setting (last resort)
sudo date -s "2023-11-15 12:00:00"
sudo hwclock --systohc