How to change default hwclock on BBB Debian to always be /dev/rtc1?

I’ve added an external battery backup real time clock (Adafruit’s Chronodot) via I2C to my BBB. I’ve successfully managed to add it as a module in Debian 8.2 using Adafruit guide, and it is now accessible via hwclock using the override command hwclock -r -f /dev/rtc1.

Reading around the web it states that the system time, synced with NTP, can automatically write the current system time every 11 minutes to the hwclock. The default hwclock is /dev/rtc0 which isn’t backed up with a battery. Is it possible to change the default hwclock to always be /dev/rtc1? Or will hwclock automatically update both /dev/rtc0 and /dev/rtc1 with the system time?

Thank you for your time.


 **-f**, **--rtc=***filename*
              Override **hwclock**'s default rtc device file name.  Otherwise it
              will use the first one found in this order:
              For **IA-64:**

HI WIlliam,

Thank you for getting back to my post, really appreciate your time.
However, your solution is the same approach as I mentioned my initial post (hwclock -r -f /dev/rtc1). This doesn’t actually set the default rtc source, it only overrides the default for the command. I need an approach that permanently sets hwclock to /dev/rtc1 automatically all of the time, i.e. after reboot etc. Thus executing the command hwclock should always default to /dev/rtc1 and not rtc0.

I think however I may have found the answer to my own questions thanks to a post talking about OpenRC
I haven’t tested it yet, but it looks promising.

root:# cd /etc/init.d/
root: /etc/init.d# nano

In the script is the following line that looks to be setting the default hardware clock to rtc0.


Thus, I bet if I change it to =rtc1 then I should be away.

I will post back with my results.

Actually, on reflection there’s another file that should be edited and not the one I posted above.

root:# nano /etc/default/hwclock

HI WIlliam,

Thank you for getting back to my post, really appreciate your time.
However, your solution is the same approach as I mentioned my initial post (hwclock -r -f /dev/rtc1).

Yeah, I did not realize until after I posted. I figured it would require “hacking” the kernel(otherwise), but looks like you’ve found something that will work better for you.

Additionally, I know there is a package called “fake-hwclock” which simulates an rtc for those systems that do not have. One, so was going to suggest perhaps looking over the code. But seems largely moot now.

To get back to this thread, it seems that editing the default HCTOSYS_DEVICE field in /etc/default/hwclock won’t work in my situation. I’m assuming because the RTC1 (DS3231) is loaded via a script when Debian boots the hwclock has already loaded and defaulted to RTC0 because RTC1 is yet to be loaded.

This isn’t really too much on an issue though. Using Adafruit’s guide for creating a script to load the RTC (DS3231) I am able to set the system time and default hwclock RTC0 on bootup. Likewise I have made a similar script that runs when Debain shuts down, reboots and halts to set the DS3231 RTC to the system time. This allows the system to sync with an NTP server if available and update the external RTC.

Robert, when using rtc0, did you also use …/i2c-adapter/i2c-0… ?

I also had to change the default rtc… I managed it by recompiling the kernel. In the menu config you can specify the default rtc…

I don~t think Robert recompiled the kernel. I am using 3.8.13 Debian.

The best way I found for myself. Was to simply install ntpdate, run it, then update the external real clock from system time. Then, if you absolutely need rtc0 updated. You update it from the system time. Or rtc1. No need to recompile the kernel.

Sure, it’s a couple of extra steps, but steps that can be done at boot with a simple script / service. Then if you need, or want to update the real time clock. Since time on computer can drift. You run a cron job every X time frame to run a script that pulls in system time from an atomic clock, then re-apply to rtc1.

The problem have been discussed there :