Is there any way to read total running time of a linux system from BIOS or CPU?

I've searched BIOS informations by dmidecode. But it gives release date which is not proper for my question.

Then I've checked out /proc. But it holds uptime values just from last reboot. Maybe, writing these uptime values for every boot could be an option.

Then I've checked dumpe2fs. It gives total running time of a particular hard drive. It's useless for me because hdd could be changed while my application is running.

Except these above, how can I read or calculate the total runtime of my system ? Where can I read from ?

  • Total running time of the CPU, the hard drive(s), or the application? Or other components? How would you define where the identity of "the system" comes from? – ilkkachu Dec 8 '17 at 9:32
  • I've meant total running time of CPU. Of course I'd rather read from BIOS if there's a way. – Cumhur Sayan Dec 8 '17 at 9:37

This isn’t something the firmware tracks, as far as I’m aware. Even BMCs don’t measure total uptime.

This won’t help with past uptime from previous boots, but you can start recording uptimes now, by installing a tool such as uptimed and setting it up so that it never discards values (set LOG_MAXIMUM_ENTRIES to 0 in uptimed.conf). That will measure operating system uptime, not total CPU “on” time, but it should be close enough... Once you’ve got uptimed running, you can run uprecords to view the totals, for example

    up  1492 days, 02:57:18 | since                     Sat Sep  7 00:50:06 2013
  down    61 days, 08:11:24 | since                     Sat Sep  7 00:50:06 2013
   %up               96.051 | since                     Sat Sep  7 00:50:06 2013

As pointed out by quixotic, you’ll be able to get some idea of historical uptime by looking at your logs. If you’re running systemd, you can view the boots which have been logged using journalctl --list-boots. Log rotation means that this is likely to miss quite a lot of uptime though.

As pointed out by JdeBP, last reboot might give you a longer list of boots with the associated uptime.

  • historical uptime (for the OS, not the hardware) might be estimable given appropriate logs. journald might be handy here. though power outages, hard crashes, or other unmarked system halts might muddy those waters. – quixotic Dec 8 '17 at 10:24
  • Thanks @quixotic; my comment there was in relation to installing uptimed, which wasn’t clear. I’ve updated my answer. – Stephen Kitt Dec 8 '17 at 10:29
  • Even if one is using a systemd operating system, last reboot should work, and present the data that are recorded in the old binary logs (which scroll far less) by systemd-update-utmp. – JdeBP Dec 8 '17 at 10:50
  • @JdeBP you’d think so, but it seems to vary wildly: some of my systems show all boots going back to their installation, others only have the last boot... – Stephen Kitt Dec 8 '17 at 10:54
  • @JdeBP if memory serves correctly, last reboot doesn't handle system crashes well. If a system is started at 07:00 and crashes or is abruptly powered off at 08:00, but is not restarted until 10:00, the actual usage (1 hour) and declared usage (3 hours) will be off by two hours. This may have changed with systemd, though; I don't have a server handy to test. – roaima Dec 8 '17 at 11:15

If you don't have problems in getting that information from the operating system, with tuptime you can view a complete report of the total time of the linux system, including system crashes.

For example, as default output and resume:

# tuptime

System startups:    8   since   08:32:29 AM 11/24/2016
System shutdowns:   3 ok   -   4 bad
System uptime:      99.99 %   -   1 year, 195 days, 5 hours, 47 minutes and 14 seconds
System downtime:    0.01 %   -   1 hour, 6 minutes and 34 seconds
System life:        1 year, 195 days, 6 hours, 53 minutes and 48 seconds

Largest uptime:     240 days, 7 hours, 38 minutes and 10 seconds   from   08:41:51 AM 02/07/2017
Shortest uptime:    18 hours, 15 minutes and 14 seconds   from   02:26:05 PM 02/06/2017
Average uptime:     70 days, 0 hours, 43 minutes and 24 seconds

Largest downtime:   45 minutes and 15 seconds   from   10:00:01 AM 03/14/2018
Shortest downtime:  5 seconds   from   02:26:00 PM 02/06/2017
Average downtime:   9 minutes and 31 seconds

Current uptime:     85 days, 4 hours, 41 minutes and 1 second   since   10:45:16 AM 03/14/2018

Alternatively it is possible to get a list with all historical events with the list argument, in which you have how was the shutdown event, bad (a crash) or ok (following the shutdown process):

# tuptime -l

Startup:  1  at  08:32:29 AM 11/24/2016
Uptime:   46 days, 16 hours, 52 minutes and 32 seconds
Shutdown: BAD  at  01:25:01 AM 01/10/2017
Downtime: 5 minutes and 10 seconds

Startup:  2  at  01:30:11 AM 01/10/2017
Uptime:   27 days, 12 hours, 55 minutes and 49 seconds
Shutdown: OK  at  02:26:00 PM 02/06/2017
Downtime: 5 seconds

Startup:  3  at  02:26:05 PM 02/06/2017
Uptime:   18 hours, 15 minutes and 14 seconds
Shutdown: OK  at  08:41:19 AM 02/07/2017
Downtime: 32 seconds

Startup:  4  at  08:41:51 AM 02/07/2017
Uptime:   240 days, 7 hours, 38 minutes and 10 seconds
Shutdown: BAD  at  05:20:01 PM 10/05/2017
Downtime: 3 minutes and 17 seconds

Startup:  5  at  05:23:18 PM 10/05/2017
Uptime:   7 days, 14 hours, 56 minutes and 43 seconds
Shutdown: BAD  at  08:20:01 AM 10/13/2017
Downtime: 11 minutes and 35 seconds

Startup:  6  at  08:31:36 AM 10/13/2017
Uptime:   25 days, 1 hour, 7 minutes and 4 seconds
Shutdown: OK  at  08:38:40 AM 11/07/2017
Downtime: 39 seconds

Startup:  7  at  08:39:19 AM 11/07/2017
Uptime:   127 days, 1 hour, 20 minutes and 42 seconds
Shutdown: BAD  at  10:00:01 AM 03/14/2018
Downtime: 45 minutes and 15 seconds

Startup:  8  at  10:45:16 AM 03/14/2018
Uptime:   85 days, 4 hours, 42 minutes and 9 seconds

Take into account that last reboot and journalctl --list-boots gets the information from the logs, and these logs have a max life. Instead, tuptime stores the information in a particular db file dedicated to it.

For installation, supossing that you use Linux, the package is available in the Debian an derivates:

# apt-get install tuptime

If not, you can get the installation script "tuptime-install.sh" from the repository: https://github.com/rfrail3/tuptime/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.