Ubuntu 16.04.3 LTS定时睡眠与唤醒配置求助
Hey, I totally get the frustration here—trying to set up daily auto suspend and wake on a disk-encrypted Ubuntu 16.04.3 box, only to have rtcwake, cron jobs, and forum scripts fail, plus hibernation is out of the question because of encryption. Let's break down a tested, working solution tailored to your scenario:
First: Verify rtcwake Works Manually
Before diving into cron, let's make sure rtcwake can actually control your system's suspend/wake (disk encryption can add permission hurdles):
- Test an immediate suspend with a 5-minute wake timer:
This should suspend your system right away, then wake it up automatically after 5 minutes. If this fails, check your BIOS/UEFI settings—most motherboards disable RTC wake by default, so you'll need to turn on an option like "RTC Wake" or "Automatic Wake" there.sudo rtcwake -m mem -s 300
Second: Configure Cron Jobs (The Critical Fix)
Most people's cron attempts fail because of permission issues, timezone mismatches, or incorrect rtcwake flags. We'll use root's crontab to avoid permission problems, and fix the timezone gap (Ubuntu uses UTC for cron by default, not EST):
Edit root's crontab:
sudo crontab -eAdd these two lines (adjust for daylight saving time if needed—EST is UTC-5 standard time, UTC-4 during DST):
# Suspend at 1 AM EST (6 AM UTC) daily, set wake for 6 PM EST (11 PM UTC) 0 6 * * * /usr/sbin/rtcwake -m mem -t $(date -d 'today 18:00 EST' +%s) # Fallback: Ensure wake at 6 PM EST (11 PM UTC) if suspend didn't trigger 0 23 * * * /usr/sbin/rtcwake -m no -t $(date -d 'today 18:00 EST' +%s)-m memtells rtcwake to use suspend-to-RAM (the only supported sleep mode for encrypted systems—hibernation-m diskwon't work here)- The
-tflag uses a timestamp for the wake time;date -d 'today 18:00 EST' +%sconverts your desired 6 PM EST wake time to a UTC timestamp that rtcwake understands - The second line is a safety net: it sets the wake timer without suspending, in case the first job fails to trigger suspend
Save and exit, then restart cron to apply changes:
sudo service cron restart
Third: Disk Encryption Specific Notes
A common confusion with encrypted systems: when you suspend (-m mem), the system doesn't need you to re-enter the encryption passphrase on wake. Unlike hibernation (which writes memory to disk), suspend just powers down RAM—your disk stays encrypted, but wake restores RAM state directly, so you'll land at the login screen without a decryption prompt. If you're seeing a decryption prompt on wake, you accidentally used hibernation (-m disk) instead of suspend.
Fourth: Test the Setup
To avoid waiting for the full schedule, test with a short-term timer:
- Open root's crontab again:
sudo crontab -e - Add a test job that suspends in 5 minutes and wakes 10 minutes from now:
*/5 * * * * /usr/sbin/rtcwake -m mem -t $(date -d '+10 minutes' +%s) - Save and wait—your system should suspend in 5 minutes, then wake 10 minutes after you added the job. Once this works, remove the test line and restore your original schedule.
Common Pitfalls to Check
- Timezone Mismatch: Always convert EST to UTC for cron—Ubuntu's cron daemon runs on UTC, not your local timezone. Use
date -d '1:00 AM EST'to see the corresponding UTC time. - Permissions: Never use a regular user's crontab for this—rtcwake requires root privileges to modify system hardware.
- BIOS/UEFI Settings: Double-check that RTC wake is enabled; this is the #1 reason rtcwake fails even when commands work manually.
- Power Management: Make sure your system's power settings don't block auto-suspend—disable any "Never suspend" options in System Settings > Power.
内容的提问来源于stack exchange,提问作者Ryan

