From b9ddea7cd00a0b31446bf6c235d3ada2feab8c13 Mon Sep 17 00:00:00 2001 From: Herr Frei Date: Mon, 7 Sep 2026 13:50:40 +0200 Subject: [PATCH] Save system time to RTC on shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** Currently, `tc-config` reads the RTC on boot, but `rc.shutdown` never writes the system time back to the RTC on shutdown. As a result, any time drift or NTP-based correction made during the session is lost, and the hardware clock gradually becomes stale across reboots. **Fix:** Added a step in `etc/init.d/rc.shutdown` that writes the current system time back to the RTC via `hwclock -w`, mirroring the boot-time logic in `tc-config`: - Respects the `nortc` boot code — RTC write is skipped entirely if RTC handling was disabled at boot. - Respects the `noutc` boot code — uses `hwclock -l -w` (local time) if set, otherwise `hwclock -u -w` (UTC), consistent with how the clock was read at boot. --- etc/init.d/rc.shutdown | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/etc/init.d/rc.shutdown b/etc/init.d/rc.shutdown index ff96e21..de0bd26 100755 --- a/etc/init.d/rc.shutdown +++ b/etc/init.d/rc.shutdown @@ -14,6 +14,17 @@ if ! grep -q "noswap" /proc/cmdline; then swapoff -a 2>/dev/null fi +# Save system time back to the Hardware Clock (RTC), unless disabled +# via boot code. Mirrors the logic used in tc-config at boot time. +if ! grep -q "nortc" /proc/cmdline; then + echo "${BLUE}Saving system time to Hardware Clock (RTC).${NORMAL}" + if grep -q "noutc" /proc/cmdline; then + /sbin/hwclock -l -w 2>/dev/null + else + /sbin/hwclock -u -w 2>/dev/null + fi +fi + # Kill all processes except those listed in /var/tmp/k5_skip. K5_SKIP=$(awk 'BEGIN {RS="[\n ]";ORS=" "}{print "-o "$1}' /var/tmp/k5_skip) echo "${RED}Killing $K5_SKIP all processes."