Suspending NVIDIA powered laptops
calendar Jan. 16, 2015   category  bash , scripting   comments  comments


Nowadays there are many many many Linux distributions to choose from. Most of them work fine on a laptop so picking one is usually just a matter of personal preference. I chose Fedora to install on my laptop and added the RPM Fusion repository which, among other things, provides the NVIDIA binary driver, which I need (want) to play various games in Wine.

This works well enough, except that after enabling the driver the suspend functionality didn't work anymore. When looking at various logfiles, I found out that the lid open/close actions are still detected:

 

 

Jan 15 23:18:10 porcaria systemd-logind: Lid closed.
Jan 15 23:25:01 porcaria systemd-logind: Lid opened.

 

 

But unfortunately the laptop stays on and didn't get suspended like it used to when using the nouveau driver. Weirdness ...

I've google'd for a while and noticed that other people seem to experience the same issue when using the NVIDIA driver. Some people suggest you modify /etc/systemd/logind.conf like this:

 

[Login]
HandleSuspendKey=suspend
HandleLidSwitch=suspend
HandleLidSwitchDocked=suspend

 

I only mention this because for some folks this is the solution to their suspend problem, but for me it didn't do much to resolve this issue. What did work was installing acpid and creating a handler file that triggers on the lid close/open action and put the system in suspend mode. Here's how I did it:

 

 

# yum install acpi acpid
# chkconfig acpid on

 

 

That will install the daemon and ensures it runs after a reboot. Now create a new file called /etc/acpi/events/anything with the following contents:

 

 

# Pass all events to our one handler script
event=.*
action=/etc/acpi/handler.sh %e

 

 

This will forward all events to the handler script /etc/acpi/handler.sh which you have to create as well with the following contents:

 

 

#!/bin/sh
case $1 in
        button/lid)
                case $3 in
                        close)
                                systemctl suspend
                                ;;
                        open)
                                xset dpms force on
                                ;;
                        *)
                                logger "ACPI undefined: $@"
                                ;;
                esac
                ;;
        *)
                logger "ACPI undefined: $@"
                ;;
esac

 

 

Next, make it executable:

 

 

# chmod +x /etc/acpi/handler.sh

 

 

Start the daemon (only once, since we don't want to reboot just yet):

 

 

# service acpid start

 

 

And now when you close the lid on your laptop, acpid will trigger and the system will be suspended. While this is far from a pretty solution, it works for me. If you have a better solution, do let me know!



Share: