Rtcwake

From VDR Wiki
Jump to navigation Jump to search

Introduction

The rtcwake is part of the util-linux package. It uses cross-platform Linux interfaces to enter a system sleep state, and leave it no later than a specified time. It uses any real time clock (RTC) framework driver that supports standard driver model wakeup flags. It can be viewed a successor of nvram_wakeup.

On some systems, such as [Raspberry_Pi], no RTC hardware is present by default, and rtcwake typically does nothing. On commodity PC systems, it typically works, with a few caveats that are mentioned below.

Suspend to RAM

The following command should shut down much of the system, leaving the system RAM powered, and resume normal operation in 60 seconds.

sudo rtcwake -m mem -s 60

Suspend to disk (hibernate)

On some systems, this is the only way for rtcwake to support wake-up from a ‘power off’ state.

The following command should suspend the system to disk and resume in 4 minutes:

sudo rtcwake -m disk -s 240

If no swap partition has been set up, it should fail like this and return a nonzero exit status:

rtcwake: wakeup from "disk" using /dev/rtc0 at Sun Apr 23 16:26:15 2023
rtcwake: write error

Making Linux resume from suspend-to-disk

If a swap partition has been set up, it could happen that the system fails to resume, and instead starts up as if the system had been forcibly shut down.

If your system uses initramfs-tools, you should check the contents of the file /etc/initramfs-tools/conf.d/resume. If it says RESUME=none, you should edit it to point to your swap partition, and finally execute sudo update-initramfs -u.

In some systems, mkinitcpio is used instead.

Wake up from soft-power-off

The followings command may appear to work, but the system will fail to start up:

sudo rtcwake -m off -s 240
sudo rtcwake -m no -s 240 && sudo shutdown -h now

Some systems do not support wake-up from the ACPI S5 (soft power-off) state. In the Linux boot messages (sudo dmesg), you could find a line like the following:

rtc_cmos 00:02: RTC can wake from S4

This means that suspend to disk will work; see the previous section.

Another reason for missed wakeup would be that disabled power management for some driver will cause the wake-up timer to be disabled on shutdown. To eliminate this possibility, you may execute sudo powertop, press the Tab key 4 times to reach Tunables section, and then use Enter and the up and down arrow keys to tune each "Bad" to "Good". Near the top of the screen, you will see equivalent commands for the tuning, such as:

echo 'auto' > '/sys/bus/pci/devices/0000:00:16.3/power/control';