Setting a System Wakeup Time

For many years the computers in the house network have been configured to self-awaken as needed.

The basic trick is to configure the BIOS real-time clock (RTC). There are some oddball tidbits to know.

Electrical power to the system must remain available.

View the RTC status and alarm time with cat /proc/driver/rtc. If that file does not exist then run modprobe rtc-cmos. If the file is created then somewhere in the system boot scripts be sure to load the kernel module. On many to most systems this should be automatic and unnecessary.

Other clues an RTC chip exists is grep -i rtc /proc/ioports and dmesg | grep ‘Real Time Clock'.

Most RTC chips support future alarm times of once per day, month, or year. That means the alarm time cannot exceed the period that the chip supports. Any date beyond that period results in failure. For example, on a chip supporting 24 hours, an alarm of 25 hours into the future will fail.

The chip storage period can be found with dmesg:

dmesg | grep ‘rtc_cmos’ | grep ‘alarms up to'

Before setting the time clearing the register often helps when manually setting alarm times:

echo 0 > /sys/class/rtc/rtc0/wakealarm

An occasional quirk is sometimes the alarm time has to be forced to a future time beyond the supported period. The bogus time causes a failure, which then allows setting the desired alarm time.

When a bogus future time is used the alrm_date field in /proc/driver/rtc will contain asterisks.

Beginning with the 2.6 kernel, the alarm time from the RTC is stored in /sys/class/rtc/rtc0/wakealarm.

The alarm time is set using UTC. The time stored in /sys/class/rtc/rtc0/wakealarm is in epoch time format. That means some conversions are required.

For some people the rtcwake command might be all that is needed. For convenience, automating alarm times might require some shell scripting. For example, the at scheduler might be used to schedule computer tasks during certain nights. Scripting will allow querying those at jobs to ensure the computer awakens at a desired time.

A wakeup alarm might not be an option. Consider a system that needs to power down Friday afternoon, remain powered off through the weekend, and power on Monday morning. Suppose the RTC only supports future dates within 1 day. There is no way to have the system self-awaken Monday morning. The solution might be to send the system a wake-on-lan magic packet.

Posted: Category: Tutorial Tagged: General

Next: Accessing a Disk Image File

Previous: Detecting the First Boot of the Year