Ubuntu: How to set up a RTC clock in Ubuntu Core?



Question:

I have a Raspberry Pi 3 that register data in time, so I need an RTC clock

I've attached dtoverlay=i2c-rtc,ds3231 to config.txt.

hwclock.service would be perfect, but it is masked, and I can't unmask it.

hwclock -s works fine, but when I try to execute from a confined snap I get this (time-control is connected):

ed10vi86@localhost:~$ sudo hwclock.hwclock-test -s --debug  hwclock from util-linux 2.27.1  Using the /dev interface to the clock.  Assuming hardware clock is kept in UTC time.  Waiting for clock tick...  /dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change  ...got clock tick  Time read from Hardware Clock: 2017/06/29 10:49:54  Hw clock time : 2017/06/29 10:49:54 = 1498733394 seconds since 1969  Time since last adjustment is 1498733394 seconds  Calculated Hardware Clock drift is 0.000000 seconds  Calling settimeofday:      tv.tv_sec = 1498733394, tv.tv_usec = 0      tz.tz_minuteswest = -120  /snap/hwclock/x1/hwclock-test: line 2:  1656 Bad system call         hwclock $@  

And snappy-debug.security scanlog:

= Seccomp =  Time: Jun 29 12:49:54  Log: auid=1000 uid=0 gid=0 ses=1 pid=1656 comm="hwclock" exe="/sbin/hwclock" sig=31 arch=40000028 79(settimeofday) compat=0 ip=0x76f0c246 code=0x0  Syscall: settimeofday  

Works fine in devmode


Solution:1

I know this is kind of a delayed response, but I figured I'd share my solution. It seems that you can "recreate" the hwclock service and get the desired result, as follows:

In order to unmask a service, the corresponding definition file needs to be present in /etc/systemd/system. Luckily, in Ubuntu Core this directory is mapped to /writable/system-data/etc/systemd/system - so in that writable directory you can create a file called hwclock.service with the following contents (tweaked if desired):

[Unit]  Description=Hardware clock synchronization  [Service]  Type=oneshot  ExecStart=/sbin/hwclock --hctosys --utc --adjfile=/writable/system-data/etc/adjtime  ExecStop=/sbin/hwclock --systohc --utc --adjfile=/writable/system-data/etc/adjtime  [Install]  WantedBy=multi-user.target  

Then you can unmask and enable the service as normal:

sudo systemctl unmask hwclock  sudo systemctl enable hwclock  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »