Skip to content

Add First Boot Time Synchronization #12

@mihai-chiorean

Description

@mihai-chiorean

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

  • Time syncs automatically on first boot
  • Uses reliable NTP servers
  • Falls back to pool.ntp.org if primary fails
  • Only runs on first boot (ConditionFirstBoot)
  • Logs sync status for debugging
  • Works without manual intervention

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions