165

I'm using archlinux. It never auto-suspend before a recent system upgrade(maybe I updated the kernel?).

I think it is related to laptop-mode or acpid, so I stop them:

/etc/rc.d/laptop-mode stop
/etc/rc.d/acpid stop

I also edit /etc/laptop-mode/laptop-mode.conf:

ENABLE_LAPTOP_MODE_TOOLS=0

Then I edit /etc/acpi/actions/lm_lid.sh, commented out the last line:

# /usr/sbin/laptop_mode auto

But all of above don't work. Following lines were found in /var/log/kernel.log(unrelated lines omitted):

Oct 23 15:29:20 localhost kernel: [18617.549098] PM: Syncing filesystems ... done.
Oct 23 15:29:20 localhost kernel: [18618.001898] PM: Preparing system for mem sleep
Oct 23 15:29:30 localhost kernel: [18618.039565] Freezing user space processes ... (elapsed 0.01 seconds) done.
Oct 23 15:29:30 localhost kernel: [18618.052596] Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
Oct 23 15:29:30 localhost kernel: [18618.065999] PM: Entering mem sleep
Oct 23 15:29:30 localhost kernel: [18618.066167] Suspending console(s) (use no_console_suspend to debug)
Oct 23 15:29:30 localhost kernel: [18618.097917] sd 0:0:0:0: [sda] Synchronizing SCSI cache
Oct 23 15:29:30 localhost kernel: [18618.098103] sd 0:0:0:0: [sda] Stopping disk
Oct 23 15:29:30 localhost kernel: [18618.270537] snd_hda_intel 0000:00:14.2: power state changed by ACPI to D3hot
Oct 23 15:29:30 localhost kernel: [18619.274374] PM: suspend of devices complete after 1196.192 msecs
Oct 23 15:29:30 localhost kernel: [18619.274691] PM: late suspend of devices complete after 0.313 msecs
Oct 23 15:29:30 localhost kernel: [18619.440877] ohci_hcd 0000:00:14.5: wake-up capability enabled by ACPI
Oct 23 15:29:30 localhost kernel: [18619.642144] ACPI: Waking up from system sleep state S3
Oct 23 15:29:30 localhost kernel: [18620.049424] PM: noirq resume of devices complete after 333.503 msecs
Oct 23 15:29:30 localhost kernel: [18620.049852] PM: early resume of devices complete after 0.334 msecs
Oct 23 15:29:30 localhost kernel: [18622.418605] PM: resume of devices complete after 2371.906 msecs
Oct 23 15:29:30 localhost kernel: [18622.419018] PM: Finishing wakeup.
Oct 23 15:29:30 localhost kernel: [18622.419019] Restarting tasks ... done.
Oct 23 15:29:30 localhost kernel: [18622.464752] video LNXVIDEO:01: Restoring backlight state

I think this is not caused by pm-susend, because /var/log/pm-suspend.log don't log anything.

I don't want my laptop go to sleep when I close the lid. How to do it?

Kernel version: 3.6.2-1-ARCH

heiz
  • 1,803
  • 2
    I was just about to ask this myself when your question popped up in "Questions that may already have your answer." It did. Thanks. – cjm Nov 11 '12 at 01:04
  • 1
    On Debian 8 "Jessie" the command systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target disables every type suspension. – CDuv Oct 17 '15 at 21:39

2 Answers2

205

Edit /etc/systemd/logind.conf and make sure you have

HandleLidSwitch=ignore

which will make it ignore the lid being closed. (You may need to also undo the other changes you've made.)

Then, you'll want to reload logind.conf to make your changes go into effect (thanks to Ehtesh Choudhury for pointing this out in the comments):

systemctl restart systemd-logind

Full details over at the archlinux Wiki.

The man page for logind.conf also has the relevant information,

HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch=

    Controls whether logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep" and "lock". If "ignore", logind will never handle these keys. If "lock", all running sessions will be screen-locked; otherwise, the specified action will be taken in the respective event. Only input devices with the "power-switch" udev tag will be watched for key/lid switch events. HandlePowerKey= defaults to "poweroff". HandleSuspendKey= and HandleLidSwitch= default to "suspend". HandleHibernateKey= defaults to "hibernate".
kballou
  • 192
EightBitTony
  • 21,373
  • 17
    After changing HandleLidSwitch, how do I reload logind.conf on the fly? Nevermind, it's systemctl stop systemd-logind && systemctl start systemd-logind. – Ehtesh Choudhury Jul 04 '13 at 07:08
  • 13
    Or maybe systemctl restart systemd-logind, or even just systemctl reload systemd-logind? not sure it's enough, thus, looking forward for a reply before trying to close my lid (long computation in progress... (: ). Also, isn't there an userspace tool that can manage such acpi features? – cedbeu Aug 01 '13 at 12:29
  • 2
    it's definitely not on the wiki anymore, and I don't see a logind.conf article (short of the small section on that page). – Ehtesh Choudhury Dec 09 '13 at 21:26
  • I think the man page for logind.conf covers the requirements and format of the option. It's there in the Ubuntu man pages, for example. – EightBitTony Mar 05 '14 at 11:25
  • 2
    The related topic is moved to Power management on Arch Wiki. – day Apr 01 '14 at 20:08
  • 1
    Thanks, this helps! Only editing logind.conf has effect for all linux consoles except the one where an X session with Xfce has been started by a DM (like xdm). (But if I do startx which starts a similar Xfce session, then the setting from logind.conf also take effect.) For example, by default, my system (with an ALTLinux distro) suspended on closing the lid. After I edited logind.conf, I made it hibernate. But only in the X session started by an xdm, the system still suspends when the lid is closed... In my case, I have to find out what gives this effect. – imz -- Ivan Zakharyaschev Jul 19 '15 at 20:18
  • 1
    The explanation for my case was that when Xfce is started by an xdm, it has enough permissions to control and override the corresposponiding settings (and if it is started with startx, then it doesn't have enough permissions). To have a uniform behavior across all linux consoles, I simply did apt-get remove xfce4-power-manager – imz -- Ivan Zakharyaschev Jul 20 '15 at 04:59
  • 9
    systemctl restart systemd-logind caused my Archlinux with GNOME-shell desktop freeze. Be prepared. – mehdix Nov 14 '16 at 13:25
  • I played with the XFCE power manager, set the lid option to "Switch off display", and the machine still suspended on lid close. Never would it have occured to me that systemd had its own opinion on the matter. I hate that blob more by the minute. – mcmlxxxvi Nov 19 '16 at 18:12
  • 1
    Simillarly to @MehdiSadeghi , that causes mime to reboot. – maowtm Jan 16 '18 at 10:59
  • 1
    Similarly to @MehdiSadeghi and maowtm it causes my desktop to freeze and I eventually have to reboot. – Flaming_Dorito Jun 01 '18 at 03:48
  • 1
    It was HandleLidSwitchExternalPower=ignore for me. – modlin Jan 20 '22 at 09:41
  • @mehdix I wish I'd seen your comment before restarting logind ;) My system went completely haywire and I had to reboot. Xfce4, kernel 5.15.16. – AtomHeartFather Jan 26 '22 at 09:21
  • 1
    systemctl kill -s HUP systemd-logind is recommended by Archlinux wiki, instead of systemctl restart systemd-logind. It also didn't wreck my desktop session like the restart did ;) – AtomHeartFather Jan 29 '22 at 11:46
  • @modlin pointed this out, so for clarity: I believe HandleLidSwitch=ignore is used when on battery, HandleLidSwitchExternalPower=ignore is used when on AC power. I'm on Debian testing, KDE with SDDM. I had to use this as KDE settings apply only once user is logged in. I needed a solution to prevent the system from being suspended when the lid is closed while SDDM greeter screen is shown, i.e. before anyone logs in. – likewise Nov 22 '23 at 10:35
46

You can use this to temporarily disable lid-switch events:

systemd-inhibit --what=handle-lid-switch sleep 1d
  • 6
    Never knew of systemd-inhibit before now, very cool – Hubro Jun 10 '16 at 10:34
  • I think it used to be in the arch-wiki -- idk what happened. – user3467349 Jun 10 '16 at 12:31
  • 4
    What I wrote was You can use this to temporarily disable lid-switch events -- which is most commonly what I or other people may want. So I'm not sure what your comment is about? – user3467349 Jul 09 '16 at 00:09
  • 2
    Does 1d mean 1 day? If so, what are the other options? h, m, s? I cannot find anything explicitly explaining the final portion of your command. – mas Jun 18 '18 at 21:58
  • 3
    @malan 1d means 1 day. See man sleep for other options. Like mentioned in an earlier comment, the full command just runs the final part with "inhibition lock taken". In pratice, the lid-switch events are disabled until sleep 1d completes (i.e., 1 day) or you kill it with, e.g., Ctrl+C – oseiskar Mar 11 '20 at 14:26
  • 1
    thank you <3 this was just what I was looking for – Alba Mendez Jun 14 '20 at 10:06