Here, I will show how the "fake-hwclock" service can be easly replaced with the "systemd-timesyncd" service in reading the last saved clock upon an OS reboot:
The "systemd-timesyncd" service keeps track of the system time and updates the file "/var/lib/systemd/clock" with the last time stamp. See also https://unix.stackexchange.com/question ... tp-syncing for more info.
The last updated time stamp of the file "/var/lib/systemd/clock" will be used when starting up the OS, and sets the system time accordingly. Thus, no need to have the "fake-hwclock" running in parallel and periodically store the OS running system time again.
The "fake-hwclock" package can be deinstalled as follows:
Code: Select all
sudo systemctl stop fake-hwclock
sudo apt-get -y remove fake-hwclock
sudo apt-get -y purge fake-hwclock
Next, we will upate the respective configuration file for the "systemd-timesyncd" service with the following commands:
Code: Select all
sudo cp /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.bak
sudo sed -i '/^\[Time/,+2d' /etc/systemd/timesyncd.conf
Code: Select all
sudo sh -c 'cat >> /etc/systemd/timesyncd.conf' << EOF
[Time]
NTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
EOF
Code: Select all
sudo sh -c 'cat >> /etc/systemd/timesyncd.conf' << EOF
[Time]
Servers=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
EOF
Code: Select all
sudo systemctl restart systemd-timesyncd
sudo systemctl daemon-reload
Code: Select all
timedatectl
Code: Select all
sudo sed -i '/^exit 0/d' /etc/rc.local
sudo sh -c 'cat >> /etc/rc.local' << EOF
[ ! -e /var/lib/systemd/clock -a "\`systemctl is-active systemd-timesyncd | grep -i active\`" ] && timedatectl set-ntp 1 > /dev/null 2>&1
sleep 2
EOF
