From ca71b8822763a725e9175a6d428b5f92abaf403e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 15 Mar 2022 14:08:24 -0500 Subject: [PATCH] initramfs: sync time with NTP Using the Busybox NTP client, we can set the system clock in early userspace. This will ensure the system clock is correct before anything, even systemd, is started from the real rootfs. Obviously, this requires the DHCP server to specify NTP server addresses in the client lease. --- initramfs/busybox.config | 4 ++-- initramfs/overlay/usr/share/udhcpc/default.script | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/initramfs/busybox.config b/initramfs/busybox.config index 03cdb72..da51bfd 100644 --- a/initramfs/busybox.config +++ b/initramfs/busybox.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.35.0 -# Tue Mar 8 23:49:30 2022 +# Tue Mar 15 14:06:30 2022 # CONFIG_HAVE_DOT_CONFIG=y @@ -928,7 +928,7 @@ CONFIG_FEATURE_IP_ROUTE_DIR="/etc/iproute2" # CONFIG_NSLOOKUP is not set # CONFIG_FEATURE_NSLOOKUP_BIG is not set # CONFIG_FEATURE_NSLOOKUP_LONG_OPTIONS is not set -# CONFIG_NTPD is not set +CONFIG_NTPD=y # CONFIG_FEATURE_NTPD_SERVER is not set # CONFIG_FEATURE_NTPD_CONF is not set # CONFIG_FEATURE_NTP_AUTH is not set diff --git a/initramfs/overlay/usr/share/udhcpc/default.script b/initramfs/overlay/usr/share/udhcpc/default.script index bff26bc..08e9ac6 100755 --- a/initramfs/overlay/usr/share/udhcpc/default.script +++ b/initramfs/overlay/usr/share/udhcpc/default.script @@ -29,5 +29,11 @@ renew|bound) printf 'nameserver %s\n' "${ns}" >> /etc/resolv.conf done fi + if [ -n "${ntpsrv}" ] && [ -x /usr/sbin/ntpd ]; then + for ts in ${ntpsrv}; do + /usr/sbin/ntpd -n -q -p "${ts}" || continue + break + done + fi ;; esac