Description
Add time synchronization service that runs on first boot to ensure accurate system time.
Problem
Raspberry Pi doesn't have RTC, so time is wrong on first boot until NTP sync occurs.
Implementation
1. Systemd Service
# first-boot-timesync.service
[Unit]
Description=First Boot Time Sync
After=network-online.target
Wants=network-online.target
ConditionFirstBoot=yes
[Service]
Type=oneshot
ExecStart=/usr/bin/timedatectl set-ntp true
ExecStart=/usr/bin/systemctl restart systemd-timesyncd
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
2. NTP Configuration
# /etc/systemd/timesyncd.conf
[Time]
NTP=time.google.com time.cloudflare.com
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org
3. Recipe
# time-sync.bb
SUMMARY = "First boot time synchronization"
LICENSE = "MIT"
SRC_URI = " \
file://first-boot-timesync.service \
file://timesyncd.conf \
"
inherit systemd
do_install() {
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/first-boot-timesync.service \
${D}${systemd_unitdir}/system/
install -d ${D}${sysconfdir}/systemd
install -m 0644 ${WORKDIR}/timesyncd.conf \
${D}${sysconfdir}/systemd/
}
SYSTEMD_SERVICE:${PN} = "first-boot-timesync.service"
SYSTEMD_AUTO_ENABLE:${PN} = "enable"
Acceptance Criteria
Description
Add time synchronization service that runs on first boot to ensure accurate system time.
Problem
Raspberry Pi doesn't have RTC, so time is wrong on first boot until NTP sync occurs.
Implementation
1. Systemd Service
2. NTP Configuration
3. Recipe
Acceptance Criteria