Error Message Seen: "missing btime in /proc/stat"

Follow

Issue

When configuring Cumulus Linux, I see an error while executing <application> with this message:

missing btime in /proc/stat

How do I correct this error?

Environment

  • Cumulus Linux, all versions
  • This generally relates to the hardware clock

Resolution

To solve this issue, you simply need to synchronize the system time with the hardware clock.

  1. Set the system time manually using the date command to set your date and time:
    cumulus@switch:~$ sudo date --set="Mon Dec 15 2014 10:36:16 EST"
    Mon Dec 15 15:36:16 UTC 2014

    Note: The clock is always set with Coordinated Universal Time (UTC), regardless of the timezone used in the date command.

  2. You need to manually synchronize the hardware clock to the current system time as well using this command:

    cumulus@switch:~$ sudo hwclock --systohc

    Now the hardware clock is set to the system time. 

  3. Turn on the NTP daemon to continue to keep it updated. Execute this command to start the NTP daemon:
    cumulus@switch:~$ sudo ntpd -q

Root Cause

This error can occur as the result of the switch's real time clock losing power. This results in the device setting the boot time (btime) value in the system to 0. Many processes rely on this value, and if it is zero, it causes a problem. Some common Python libraries use this as well, and Python is used a lot in Cumulus Linux.

For a deeper understanding as to how this issue arises, here is some background information on how time works in Cumulus Linux, or any flavor of Linux for that matter.

Linux Time

There are really two clocks on most computer systems: the real-time clock (RTC) found in the CMOS hardware and the system clock (AKA the kernel or system clock) maintained in software.

The hardware clock maintains time when the system is turned off, and is powered by a capacitor (or a lithium battery depending on the vendor). While the system is running, the RTC runs off system power.

When a Linux device boots, it sets the variable btime in /proc/stat, with the time read off the RTC. This is represented in Unix time (aka POSIX time or Epoch time). With the system booted, time is maintained in the kernel, and synchronized back to the hardware clock.

In some cases, the hardware clock may be reset to zero due to a loss of power to the RTC. This equates to January 1st, 1970 @ midnight (1 January 1970 00:00:00). This can lead to some issues in the system and errors like the one seen in this article.

Note: The RTC capacitor will not hold charge for a long duration, as a lithium battery does. Therefore it is best to consider setting up the time during initial system setup.

Synchronizing the System Time with the Hardware Clock

If you see the above error or you see that your logs are dated in the year 1970, it is important to update your hardware clock (unless you have access to a time machine, then this may be correct).

This simple procedure should only need to be done once, to ensure that your hardware clock is set correctly. First, check the hardware clock with the following command:

  hwclock --show

If your hardware clock is reporting the wrong time and/or date, then you must set the system time to current local time and date.

You must be root (or use sudo), to set the time manually or to enable NTP.

Updating Time Manually

You can use the date command to set your date and time:

  cumulus@switch:~$ sudo date --set="Mon Dec 15 2014 10:36:16 EST"
Mon Dec 15 15:36:16 UTC 2014

Notice that the clock is always set as Coordinated Universal Time (UTC).

You need to manually synchronize the hardware clock to the current system time as well using this command:

  cumulus@switch:~$ sudo hwclock --systohc

Now the hardware clock is set to the system time.

Updating Time via NTP

The NTP daemon is included in Cumulus Linux by default, and is setup with some default time servers in /etc/ntp.conf. These will suffice for our needs, or you can edit the file to point at your own NTP servers. Simply execute this command to start the NTP daemon:

  cumulus@switch:~$ sudo ntpd -q

This will automatically update the hardware clock as well, making this the preferred method of maintaining the system time.

Note: Remember the term local time (time zone) is relative to UTC, so make sure the time and time zone are set correctly in the system.  Refer to the Cumulus Linux documentation for Setting Date and Time.

Have more questions? Submit a request

Comments

Powered by Zendesk