Ubuntu – How to permanently disable sleep/suspend

suspend

Subtly broken is worse than frankly broken…

Background:

  1. I already disabled suspend in System Settings -> Power.

  2. The "Suspend" option still appears on the gear menu (not that I expected it to disappear), and the sleep (moon) button on my keyboard still triggers suspend.

  3. The options in #1 are, as others have pointed out, just too easy to hit by mistake once every month or so.

  4. It seems like 1% of platforms get suspend right, because some driver engineer somewhere forgot to check that PCIe or IO space register X gets restored when upon wake. So it's worse than broken: everything usually looks fine after waking up, only it's not. And hopefully none of those corrupted registers affects reliability in a creeping manner, like ECC configuration or storage FIFO depth. But they usually do, in one form or another, which is one reason, for example, why errata against graphics drivers continue infinitely, years after they debut on the market ("graphics chip X hangs an hour after resuming from suspend blah blah blah").

  5. There should be an automated test to see what registers change across a sleep cycle, but few vendors have such a test. The test is complicated somewhat by the fact that some registers are expected to change, such as timers. And worse, sometimes you have to read registers in a certain order or with a particular granularity, or by first writing a read index somewhere else. So this process cannot be centralized at a convenient place in the industry, like Canonical's offices. It's really and truly hopeless unless PCIe is redefined in such a manner that makes comparison easy, which it won't be.

  6. The magical test suite in #5 will never be written because of the chaotic state of driver development. Hence in the absence of that, my question.

  7. I'm so desperate that I don't mind hacking on /etc/whatever_suspend_file, but it would be nice if there were a "polite" way to do this, like that nonexistent checkbox in System Settings -> Power that says "Permanently disable suspend because it was ill-conceived from day one."

  8. NB: I'm not talking about hibernation here, which shouldn't suffer from the problems above because it involves a power cycle. Although in principle, restoring registers from permanent storage could have similar problems.

Best Answer

According to the Debian Wiki, you can also disable it via systemd like so:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

While I have done this on my machine, I can't attest to its effectiveness. Not brave enough to try it out intentionally.