pomec
Posts: 6
Joined: Thu Dec 29, 2016 2:22 am
Location: Texas

"who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 5:07 pm

I am working with a RP4 and it appears that the boot process does not update the time stamp of a boot process. It appears that the boot timestamp is set to zero which would result in the beginning date Unix/Linux starting counting which was "1969-12-31 18:00". This also causes the 'last' command to display the wrong timestamp of a boot process. My Rp4 is connected to a wired network. The 'date' command results in an accurate date and time.

Is this a bug in the timestamp of the boot process, or is there a way to update the boot timestamp.

Thank you,

Greg Ennis

epoch1970
Posts: 5016
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 5:27 pm

Welcome to systemd...
viewtopic.php?t=148634#p1172550
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
thagrol
Posts: 2951
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 5:32 pm

There's no hardware RTC on a Pi (unless you add one). Instead the Pi gets its date and time from an internet NTP server and periodically writes the current date/time to a file on disc so the next boot has at least a vague ideas of what the time is.

If the write fails (e.g a read only file system, a full filesystem) or you've disabled the fake hardware clock service the next boot won't have the stored date/time so it'll be way out until the network is live and the configured NTP server can be reached.

If you don't have a read only fs (enabling overlay files system in raspi-config means you do) and havent' disabled that service, I've no idea whgat the issue may be. Sorry.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

GlowInTheDark
Posts: 582
Joined: Sat Nov 09, 2019 12:14 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:00 pm

The problem is that even if you have a hardware RTC, it runs its little userland thing late in the boot process, so it only updates the system time then. Obviously, the OS (Linux) has already been booted at that point and obviously the recorded time of the system boot has already been written to disk (as "epoch zero" time).

Real computers, with real RTCs, get the system time updated by the BIOS, before any OS has started to load/boot.

All things considered, it would be nice if the Pi had a real RTC - but obviously, this is not high on anyone's list of priorities from a hardware design POV. If it did have one, then one of the early stages of the boot process (bootcode.bin or whatever they're calling it these days) could do the necessary, before Linux loads. Then you'd get the right time recorded for the boot time.

BTW, just in case it isn't clear, this could also be done with an external (third-party) RTC, but that's not likely to happen, since there's no standard as to *which* third-party RTC to support.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

pomec
Posts: 6
Joined: Thu Dec 29, 2016 2:22 am
Location: Texas

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:16 pm

Thank you all for your answers and efforts to help.

I can understand not having a RTC, and I don't particularly think it would be worthy to have this either.

That being said, is there a way for the boot process to wait just a bit for the network to come alive and get the time of the boot from the network ntp servers? This would cause only a 30 to 60 second discrepancy of the boot time stamp.

Greg Ennis

User avatar
rpdom
Posts: 17007
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:31 pm

pomec wrote:
Mon Jun 29, 2020 6:16 pm
That being said, is there a way for the boot process to wait just a bit for the network to come alive and get the time of the boot from the network ntp servers?
No, because the boot process can't get the time until it has got that far through the boot process. The timestamp is logged right at the beginning.
Unreadable squiggle

trejan
Posts: 1855
Joined: Tue Jul 02, 2019 2:28 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:38 pm

GlowInTheDark wrote:
Mon Jun 29, 2020 6:00 pm
Real computers, with real RTCs, get the system time updated by the BIOS, before any OS has started to load/boot.
It doesn't work like that as there is no system time in a PC BIOS or UEFI firmware. The OS kernel needs to read it directly or use the UEFI time services hardware abstraction layer.
GlowInTheDark wrote:
Mon Jun 29, 2020 6:00 pm
If it did have one, then one of the early stages of the boot process (bootcode.bin or whatever they're calling it these days) could do the necessary, before Linux loads. Then you'd get the right time recorded for the boot time.
That isn't necessary. You need to put the RTC and I2C drivers inside the kernel instead of a module so it can initialise and read the RTC earlier. The existing Pi OS setup with modules will load after systemd has started which is after when the start up time is recorded.

This is a cosmetic issue anyway.

pomec
Posts: 6
Joined: Thu Dec 29, 2016 2:22 am
Location: Texas

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:40 pm

Thank you, Ok, I understand.

Could this be remedied by a script activated in the /etc/rc.local file designed to function after the boot process, and to sense the presence of the network after the network has become active and the time had been set. Can anyone tell me where this script would need to write the boot timestamp?

GlowInTheDark
Posts: 582
Joined: Sat Nov 09, 2019 12:14 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:48 pm

If the overarching goal of the exercise is to know (i.e., to be able to display via shell commands on a running system) when the system was booted, there are various other ways to get that information.

Here's how I generally do it; I'm sure there are many others.

This is AWK code, but should be adaptable to any language:

Code: Select all

BEGIN {
    getline < (fn = "/proc/uptime")
    close(fn)
    print "The system was booted at:",strftime("%c",t=systime()-$1)
}
I think you just have to accept that "who -b" isn't going to do it.

P.S. A simpler, although less attractive, way to do it would be to put something in rc.local to write out the date to a file. Then catting that file would tell you when rc.local was executed (more or less).
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

hippy
Posts: 7431
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:53 pm

rpdom wrote:
Mon Jun 29, 2020 6:31 pm
pomec wrote:
Mon Jun 29, 2020 6:16 pm
That being said, is there a way for the boot process to wait just a bit for the network to come alive and get the time of the boot from the network ntp servers?
No, because the boot process can't get the time until it has got that far through the boot process. The timestamp is logged right at the beginning.
I wouldn't argue for delaying anything, merely updating the epoch boot time with something more reasonably accurate than "50 years ago".

'cat /proc/uptime' seems to give a reasonably accurate up-time, so current time once determined minus up-time would be a pretty good kludge for boot time.

But I doubt anything is going to change. It will be batted around as someone else's problem to fix. There's no enthusiasm for RPT patching the incorrect 'BCM2835' in the places where that appears, so there will be even less for RPT fixing an issue which seems to have even less adverse consequence.

GlowInTheDark
Posts: 582
Joined: Sat Nov 09, 2019 12:14 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 6:55 pm

'cat /proc/uptime' seems to give a reasonably accurate up-time, so current time once determined minus up-time would be a pretty good kludge for boot time.
That's what the code posted above does.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

hippy
Posts: 7431
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 7:05 pm

GlowInTheDark wrote:
Mon Jun 29, 2020 6:55 pm
'cat /proc/uptime' seems to give a reasonably accurate up-time, so current time once determined minus up-time would be a pretty good kludge for boot time.
That's what the code posted above does.
Indeed. I was typing as you posted.

hippy
Posts: 7431
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 7:16 pm

who -a | grep "run-level 3"

pomec
Posts: 6
Joined: Thu Dec 29, 2016 2:22 am
Location: Texas

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 7:29 pm

Everyone,

I surely appreciate everyone's help. I actually agree this is more of a cosmetic irritation than a need. /proc/uptime will give me what I need, and 'who -a' also gives me the boot time.

Thank you all very much!!!!

Greg Ennis

GlowInTheDark
Posts: 582
Joined: Sat Nov 09, 2019 12:14 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 8:10 pm

hippy wrote:
Mon Jun 29, 2020 7:16 pm
who -a | grep "run-level 3"
On my system: who -a | grep run.level
shows run-level 5 (not 3).

Anyway, I thought runlevels were a thing of the past now in the age of systemd.

In fact, "man runlevel" has this to say:
NOTES
This is a legacy command available for compatibility only. It should not
be used anymore, as the concept of runlevels is obsolete.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

User avatar
dickon
Posts: 1436
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 8:15 pm

Indeed. You might consider adding systemd to your otherwise-bogus list of immature technologies.

GlowInTheDark
Posts: 582
Joined: Sat Nov 09, 2019 12:14 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Mon Jun 29, 2020 9:17 pm

dickon wrote:
Mon Jun 29, 2020 8:15 pm
Indeed. You might consider adding systemd to your otherwise-bogus list of immature technologies.
I have a feeling that you have no idea what the phrases "not ready for prime time" and "mature" actually mean. They are both terms of art. You probably don't want to apply your common, street meanings here.

Anyway, I've kind of gotten use to systemd. Not really worth fighting it anymore.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

hippy
Posts: 7431
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Tue Jun 30, 2020 12:13 pm

GlowInTheDark wrote:
Mon Jun 29, 2020 8:10 pm
On my system: who -a | grep run.level
shows run-level 5 (not 3).
Ah yes -

run-level 3 = Booted to CLI
run-level 5 = Booted to GUI

Guess which I was using :D
GlowInTheDark wrote:
Mon Jun 29, 2020 8:10 pm
Anyway, I thought runlevels were a thing of the past now in the age of systemd.

In fact, "man runlevel" has this to say:
NOTES
This is a legacy command available for compatibility only. It should not
be used anymore, as the concept of runlevels is obsolete.
Seems I dodged that bullet by not using that command, only filtering the result of "who' output.

If someone knows how 'sed' or similar works they could probably add to the 'who -a | grep run-level' to convert it to what 'who -b' would show if it weren't exhibiting 'stuck at epoch' behaviour.

Jim Danner
Posts: 10
Joined: Sun Nov 17, 2019 5:10 pm

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Wed Jul 08, 2020 2:18 pm

hippy wrote:
Tue Jun 30, 2020 12:13 pm
If someone knows how 'sed' or similar works they could probably add to the 'who -a | grep run-level' to convert it to what 'who -b' would show if it weren't exhibiting 'stuck at epoch' behaviour.
You mean something like

Code: Select all

who -a | sed -En '/system boot/{:a N;/run-level/!ba;s/19.+level [0-9]\s+//p}'

hippy
Posts: 7431
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: "who -b" gives a time stamp of "system boot 1969-12-31 18:00"

Thu Jul 09, 2020 5:59 pm

Jim Danner wrote:
Wed Jul 08, 2020 2:18 pm
You mean something like ...
<insert thumb-up icon here> - Thanks, works for me.

Return to “Raspberry Pi OS”