How does setting the hwclock work in Ubuntu?

Asked by Hanno on 2009-07-27


can you please explain how Ubuntu reads and stores the hwclock? What happens when and in which order during startup and shutdown? How are the scripts triggered?

I'm working on a script that will set the acpi wakeup timer for a digital video recorder (based on vdr).

This acpi setting is lost when hwclock is called. Therefore it is necessairy to set the acpi wakeup timer _after_ the system clock is stored in the RTC during shutdown.

So where do I put this script so that it will always be called after hwclock?

Thank you in advance to anyone taking the time explaining this!



Question information

English Edit question
Ubuntu util-linux Edit question
No assignee Edit question
Last query:
Last reply:

if you install bum you can manage the bootup sequence and check where it comes in

Hanno (hzulla) said : #2

@actionparsnip Thanks. But bum is for init.d/Runlevel scripts only. Ubuntu also uses udev-Scripts for hwclock and this is when it gets messy.

Hanno (hzulla) said : #3

Or to clarify - I don't understand

- the interdependence between /lib/udev/rules.d/85-hwclock.rules and /etc/init.d/


- when which of these scripts is called and why during shutdown.

(I do understand init.d-scripts. I don't understand udev-scripts and what triggers them.)

and finally

- what is responsible for calling /sbin/hwclock --systohc during shutdown?

It should be /etc/init.d/, but apparently, it isn't. Why is there no "Saving the system clock" message in my syslog although there is HWCLOCKACCESS=yes in /etc/default/rcS?


As per the comment at the top of /etc/init.d/, this script is not run on *startup* in Ubuntu - the code still remains inside the script because Debian do still run it on startup and deleting the code would make merging harder.

Instead the kernel sets the system clock from the hardware clock on initial startup; if the hardware clock was in local time instead of UTC, the system clock is re-adjusted to UTC by the /lib/udev/rules.d/85-hwclock.rules file

It is the init script that is called on shutdown, and calls /sbin/hwclock --systohc - it's present in the /etc/rc0.d and /etc/rc6.d directories as

Note that this isn't done on the Live CD for obvious reasons

Can you help with this problem?

Provide an answer of your own, or ask Hanno for more information if necessary.

To post a message you must log in.