I'm Xan! 👋
- I like to "automate all the things"! 🤖
- I drink a lot of coffee! ☕
- I'm a massive geek! 🤓
- I'm a father! 👶
- I love GNU/Linux! 🐧
- I work in the cloud! ☁️
- I'm always learning! 🎓
Fake HWClock script for RPi Arch Linux Arm (replicates Raspbian's fake-hwclock)
License: Other
I'm Xan! 👋
So if the box lost power, systemd runs fsck before getting to this little hack. Mount time and last write time (actually last time mounted for write) are set like this:
Last mount time: Wed Dec 31 19:00:21 1969
Last write time: Wed Dec 31 19:00:21 1969
Last checked is not changed, apparently e2fsck sanity checks the time before updating that one. I only know fsck ran from looking at journalctl -b.
Dec 31 19:00:07 localhost kernel: sd 0:0:0:0: [sda] Attached SCSI removable disk
Dec 31 19:00:07 localhost kernel: EXT4-fs (sda3): INFO: recovery required on readonly filesystem
Dec 31 19:00:07 localhost kernel: EXT4-fs (sda3): write access will be enabled during recovery
Dec 31 19:00:20 localhost kernel: EXT4-fs (sda3): recovery complete
Dec 31 19:00:21 localhost kernel: EXT4-fs (sda3): mounted filesystem with ordered data mode. Opts: (null)
Dec 31 19:00:21 localhost dracut-initqueue[143]: Checking ext4: /dev/sda3
Dec 31 19:00:21 localhost dracut-initqueue[143]: issuing e2fsck -a /dev/sda3
Dec 31 19:00:21 localhost dracut-initqueue[143]: rootfs: clean, 50195/424000 files, 456251/1728768 blocks
Dec 31 19:00:21 localhost dracut-initqueue[143]: Mounting /dev/sda3 with -o defaults
Dec 31 19:00:22 localhost kernel: EXT4-fs (sda3): mounted filesystem with ordered data mode. Opts: (null)
Dec 31 19:00:22 localhost dracut-initqueue[143]: Mounted root filesystem /dev/sda3
Dec 31 19:00:22 localhost systemd[1]: Started dracut initqueue hook.
Notice at 19:00:07 it mounts the filesystem readonly prior to checking. It would be cool to run fake-hwclock at that point. It doesn't hurt to run it multiple times, so maybe we could hook it to fsck somehow?
Wouldn't it be useful to create timefile
and immediately exit successfully, in case timefile
doesn't already exist, rather than exiting with an error?
Installed this on a RPi running CentOS 7 ARM.
It appears to be working but I had to do things slightly differently than your documentation says:
I had to run the systemctl command with the full path to the .service file
/opt/alarm-fake-hwclock # systemctl enable /opt/alarm-fake-hwclock/systemd/fake-hwclock.service
I also got a warning after the installation BUT everything does appear to be working reguardless.
root@localhost /opt/alarm-fake-hwclock # systemctl enable /opt/alarm-fake-hwclock/systemd/fake-hwclock.service
Created symlink from /etc/systemd/system/local-fs-pre.target.wants/fake-hwclock.service to /opt/alarm-fake-hwclock/systemd/fake-hwclock.service.
Created symlink from /etc/systemd/system/fake-hwclock.service to /opt/alarm-fake-hwclock/systemd/fake-hwclock.service.
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
When I run and enable fake-hwclock.service, I am seeing in my log a lot of dependany cycle found by auditd an then failed start of many systemd service.
This leads to many criticial failure, the worse being systemd-journald not logging anything.
Here an execprt of what I am seeing in my logs (volatile log in /run because nothing is written to disk, ever)
[...]
févr. 11 07:29:57 ymir systemd[1]: /usr/lib/systemd/system/auditd.service:12: PIDFile= references path below legacy directory /var/run/, updating /va>
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found ordering cycle on systemd-timesyncd.service/start
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found dependency on systemd-tmpfiles-setup.service/start
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found dependency on systemd-journal-flush.service/start
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found dependency on systemd-journald.service/start
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found dependency on fake-hwclock.service/start
févr. 11 07:29:57 ymir systemd[1]: sysinit.target: Found dependency on fake-hwclock.timer/start
févr. 11 07:29:57 ymir kernel: snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
févr. 11 07:29:57 ymir systemd-modules-load[205]: Inserted module 'snd_bcm2835'
févr. 11 07:29:57 ymir systemd[211]: systemd-udev-trigger.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir kernel: media: Linux media interface: v0.10
févr. 11 07:29:57 ymir kernel: Linux video capture interface: v2.00
févr. 11 07:29:57 ymir kernel: bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
févr. 11 07:29:57 ymir systemd[214]: lvm2-lvmetad.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd-fsck[206]: fsck terminated by signal PIPE.
févr. 11 07:29:57 ymir systemd[217]: systemd-remount-fs.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir kernel: EXT4-fs (sda2): re-mounted. Opts: (null)
févr. 11 07:29:57 ymir systemd[220]: systemd-random-seed.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd[221]: systemd-update-utmp.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd[222]: systemd-tmpfiles-setup-dev.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd[223]: systemd-udevd.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir kernel: bcm2835-rng 3f104000.rng: hwrng registered
févr. 11 07:29:57 ymir systemd-journald[377]: Missed 3 kernel messages
[...]
févr. 11 07:29:57 ymir systemd-journald[377]: Missed 1 kernel messages
févr. 11 07:29:57 ymir systemd[262]: systemd-rfkill.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd[263]: systemd-sysctl.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd-sysctl[263]: Couldn't write '2' to 'net/ipv6/conf/wlan0/use_tempaddr', ignoring: No such file or directory
févr. 11 07:29:57 ymir systemd[264]: sys-kernel-config.mount: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd-sysctl[263]: Couldn't write '2' to 'net/ipv6/conf/wlan1/use_tempaddr', ignoring: No such file or directory
févr. 11 07:29:57 ymir systemd-sysctl[263]: Couldn't write '2' to 'net/ipv6/conf/wlan2/use_tempaddr', ignoring: No such file or directory
févr. 11 07:29:57 ymir systemd-sysctl[263]: Couldn't write '2' to 'net/ipv6/conf/br0/use_tempaddr', ignoring: No such file or directory
févr. 11 07:29:57 ymir kernel: usb 1-1.2: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: 51008
févr. 11 07:29:57 ymir systemd[267]: boot.mount: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir kernel: FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
févr. 11 07:29:57 ymir systemd[266]: systemd-networkd.service: Failed to connect stdout to the journal socket, ignoring: Connection refused
févr. 11 07:29:57 ymir systemd[268]: systemd-fsck@dev-disk-by\x2duuid-7f84c0de\x2dxxxxx\x2xxxxxx\x2xxxxxx\x2xxxxxxxxxxxx.service: Failed to connect std>
and possibly others
my guess is that it IS NOT a good idea to include a .timer service inside the .serivce file at all.
On a rpi3 running archlinux-arm, with root on an external SSD via usb.
I added an optional argument for a file to use instead of /usr/bin/fake-hwclock to store the timestamp.
Thanks for posting this! It's exactly what I needed. While fake-hwclock.c is pretty trivial, figuring out where to insert the systemd service is NOT trivial. You did the hard lifting.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.