환경
사용 방법
/etc/rc.local
#!/bin/bash
# Enable RTC device of Raspberry Pi CM4 module
echo "Loading kernel module for PCF85063 RTC module ..."
echo "pcf85063 0x51" > /sys/class/i2c-adapter/i2c-10/new_device
modprobe rtc-pcf85063
# Sync hardware clock to system clock
echo "Reading from HW clock ..."
hwclock --hctosys
echo "Done."
/lib/systemd/system/rc-local.service
...
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
/etc/rc.local 권한 설정
sudo chmod +x /etc/rc.local
crontab
...
0 2 * * 6 /bin/bash -c 'service ntp stop; ntpd -gq; if [ "$?" -eq "0" ]; then hwclock --set --date="$(date "+%m/%d/%y %H:%M:%S")"; fi; service ntp start'
재부팅 후 dmesg로 결과 확인
...
[ 15.200054] i2c i2c-10: new_device: Instantiated device pcf85063 at 0x51
[ 15.262737] rtc-pcf85063 10-0051: registered as rtc0
[ 15.264656] rtc-pcf85063 10-0051: setting system clock to 2022-03-17T06:13:33 UTC (1647497613)
...
참고자료