1

On bootup, systemd gives me

System time before build time, advancing clock

if the hardware clock is older than the build time.

But where does it get this build time? It advances the time to 09/Sept/2020

But uname -v gives me 15/Feb/2021

and /etc/timestamp contains 21/July/2021.

So where does systemd get this build time from?

2 Answers 2

2

That timestamp probably comes from the build-time of the systemd daemon, and not the build time of the kernel (uname). I don't know where /etc/timestamp comes from.

After looking at systemd code, I think the build-time is set when the systemd binaries are compiled, or if present, from the file /usr/lib/clock-epoch

This is the error message:

$ ag 'System time before build time' src/core/main.c 1602: log_info("System time before build time, advancing clock."); 

The condition for that error message depends on the output of the function...

$ ag clock_apply_epoch src/shared/clock-util.c 142:int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) { 

...which will stat a hard-coded path or use a constant defined at compile time.

$ ag EPOCH_FILE src/shared/clock-util.c 140:#define EPOCH_FILE "/usr/lib/clock-epoch" 152: if (stat(EPOCH_FILE, &st) < 0) { 154: log_warning_errno(errno, "Cannot stat " EPOCH_FILE ": %m"); 

The constant is defined here:

$ ag TIME_EPOCH meson.build 724:conf.set('TIME_EPOCH', time_epoch) 
2
  • Thanks but /usr/lib/clock-epoch doesn't seem to exist. Commented Sep 22, 2021 at 8:44
  • That's why there is a condition for that state in the code. Also, it's really easy to check if the file is there, so I'm not sure why it seems that way for you. On this system, that file definitely does not exist. Commented Sep 22, 2021 at 12:39
2

On Ubuntu 22 I've found a way to get around this from reading the systemd-timesyncd man page where it mentions 2 files that timesync uses. After disabling the timesync server as above do the following:

  1. Set your system date and time back to the date you want
  2. sudo touch /var/lib/systemd/timesync/clock
  3. sudo touch /usr/lib/clock-epoch

Now reboot and my system time stays at my original date and time prior to the system deamon build time. No more advancing the system time to the build time.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.