Skip to content

Save system time to RTC on shutdown - #91

Open
herrfrei wants to merge 1 commit into
tinycorelinux:masterfrom
herrfrei:master
Open

Save system time to RTC on shutdown#91
herrfrei wants to merge 1 commit into
tinycorelinux:masterfrom
herrfrei:master

Conversation

@herrfrei

@herrfrei herrfrei commented Sep 7, 2026

Copy link
Copy Markdown

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.

**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.
@paul-1

paul-1 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

If you are running ntpd (Or chrony), then the kernel should be doing this automatically every 11 minutes.

If you are not running ntpd, then you should script this to update the clock when you set the system time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants