📅 December 5, 2017
Linux Mint 18.3 was released a few days ago!
Despite being a superb Linux distribution, some fundamental problems remain. One such problem is the suspend/resume feature.
After installing Linux Mint 18.3 MATE, I found that if I assign a keyboard shortcut to suspend the system, the Linux system will go into suspend mode but immediately resume.
Power management issues, such as suspend and hibernation, have plagued Linux systems with a variety of distributions across a variety of hardware that I have tried, but since Linux Mint is my preferred distribution, this it the one I am focusing on.
Windows does not have this problem from my usage. Given the same hardware, I have found that Windows will suspend/hibernate/shutdown without any of the problems that are apparent with Linux, such as blank resume screens (requiring a system reset button press), no resuming, dead hibernation (never waking up), or immediate resumption following a suspend.
This article shows a quick way to fix the suspend issue so that we can assign a keyboard shortcut that will suspend Linux. Pressing the power button on the computer will wake up the system.
Suspend or Hibernation?
First of all, this article focuses on the suspend power state. This means the system does not fully shutdown. Instead, enough power is applied to the RAM to retain its contents even though the system looks like it has turned off.
Hibernation saves the system state to the disk and enters a deeper, more power-saving sleep. However, hibernation is a fickle beast with Linux and not recommended. Only use hibernation if you know exactly what your hardware supports and how to troubleshoot on your own.
Setting Up the Suspend Shortcut
After installing Linux Mint MATE 18.3, we need to create a keyboard shortcut that will make the system sleep (enter the suspend state) when pressed. A standard keyboard lacking any sleep buttons was used in my case. Also, any BIOS features regarding suspend/resume were disabled (they did not work anyway with the given hardware).
You will need to create your own suspend shortcut since Linux Mint MATE does not have one set by default. Open the Control Center and choose Keyboard Shortcuts.
Command specifies what command will execute when the shortcut is pressed. This can be the same command that will suspend the system from the command line:
Yes, you can enter systemctl suspend from a terminal and your system will suspend. In my case, I did not need to install any extra software.
Name: Suspend Command: systemctl suspend
Click Apply, and then click the shortcut. Press the key you wish to associate with the shortcut to suspend the system. In this case, I chose the Pause/Break key because of its remote location where it is least likely to be pressed accidentally and because of the name. (Why not pause and take a break? Pause. Break. Get it?)
Press the shortcut. The system should go to sleep. Press the power button on the computer to wake it up, and the system should resume with any open windows and progress intact.
But do not be fooled!
Sometimes, this works fine, but most of the time, I have found that the system immediately wakes up after pressing the Pause/Break key. No matter how many time the shortcut is pressed, the system wakes up immediately via the keyboard shortcut. The system never suspends. It is as if the same key is also waking up the system at the same time.
Suspending the system from the Session dialog works fine.
It turns, that the USB controller is indeed mapping the resume function to the keyboard in some way by default because the system will also wake up by pressing any key on the keyboard. To view a listing of what devices wake up the system, enter cat /proc/acpi/wakeup in a terminal.
The image above shows a different system, not the one we are working with. This was to avoid reconfiguring a system that had already been fixed. But the point to note is that some devices are labeled enabled while others are labeled disabled.
Enabled status means that device will wake up the system when triggered. Disabled means the device has no effect, and the system will remain in its suspended state.
All S-states in the listing above are S4, which represent hibernation. S3 states are what we what, and they handle the suspend mode.
There should also be a device named PWRB with an S-state of S3. This is the power button. When pressed, it will wake up the system. The system immediately resumes from suspend because one of the enabled devices is triggering the wakeup upon pressing the suspend keyboard shortcut that was intended to turn it off. This is a USB keyboard, after all.
Now, we could test each device one-by-one to find the offender and disable only that device, but the easier way is to disable all enabled devices EXCEPT the power button (PWRB).
In the example listing above, which is from the system we want to fix, all devices are disabled except for the power button (an S3 state).
To disable a device so it will persist across reboots, we must edit /etc/rc.local. Open it as root for editing in a text editor of your choice.
sudo xed /etc/rc.local
Keep your cat /proc/acpi/wakeup listing open. For each disabled device, we must add a line above exit 0 that will disable that device. For example, if OHC1 is disabled, we disable with
echo "OHC1" > /proc/acpi/wakeup
Do this for each device, but do not disable the power button (obviously). You might have several lines depending upon your hardware. Here is an example of the final edits.
Save the changes and reboot. If you run cat /proc/acpi/wakeup again, you should see that all devices except for the power button have been disabled.
What Happens Now?
It should work. Press the suspend keyboard shortcut to suspend the system. The system should suspend and look like it has been turned off (no fans, no power lights, no activity, blank monitor).
Press the power button, and the system should wakeup and resume. If so, the great!
“It is not working.”
Things might not work out properly depending upon the hardware. The system might resume but the monitor stays blank without any way to turn it back on short of a hardware reset. The system might not wakeup at all requiring a hardware reset. Anything could happen.
If so, there might be other issues involved that are preventing proper resumption. These are beyond the scope of advice offered here and will require investigation.
For the given issue, I have found the solution presented here to be sufficient and reliable for my hardware. Suspend/Resume work perfectly. Of course, the keyboard no longer resumes the system like before, by that is fine.