Work-around needed to prevent Resume-From-Hibernation when lid opens

Except for one rub, I have hibernation working successfully in Linux (Fedora 44 and earlier versions) on my ThinkPad P52.

THE RUB IS that when hibernated, opening the lid even a crack resumes the session. This is very annoying (dangerous) since lids get bumped, running down batteries.

Even after much online research about this (many others have this problem on P-series ThinkPads) and reading the Fedora and P52 manuals, I have been unable to find a solution — and I’ve tried them all.

Unfortunately most P-series ThinkPads (not sure about recent models) don’t have a UEFI/BIOS setting to control the lid opening event (e.g. Flip Lid, or similar terms).

HOWEVER, I THINK I DO KNOW WHAT NEEDS TO BE DONE to cure the problem. Here are underlying facts on that:

  1. If I shutdown the computer, lifting the lid DOES NOT restart the computer.

  2. But because, when hibernated, lifting the lid does restart the computer (resuming from hibernation), this indicates to me that the fault here is that the computer is not being completely shut down for hibernation. That is, some subsystem is still awake, and is monitoring the lid-closed sensor. (The sensor is in an upper corner of the screen bezel, and is controlled by a magnet bonded underneath the palm rest.)

So, I think what I need is a script that first sets up the hibernation, and then concludes with a total power shutdown (except for the CMOS clock).

(Disabling the lid sensor is not a solution because when at my desk I use external monitors, with the laptop tucked away with lid closed — so the state of the lid must be detectable.)

Can anyone here tell me how to write such a script, and how to activate it via the onscreen hibernation button (replacing the hibernation routine that Fedora uses)?

Assuming hibernation is working correctly, it’s an ACPI hardware and/or firmware issue because the OS is no longer in control once it’s been suspended and saved to disk.

Fedora switched to swapping to zram instead of a dedicated swap partition a while ago, which also meant that there’s no place to save the contents of RAM (and possibly also VRAM) for hibernation, so by default closing the lid suspends a laptop and opening the lid wakes it up.

If there isn’t one, first step is adding enough physical swap space equal to at least system RAM (but the general recommendation is 1.5x). Once the pieces are in place, there’s already a system command, so no custom script required:

systemctl hibernate

Arch Linux’s Power management/Suspend and hibernate wiki page may also be of interest.

Thanks for your reply, CYL.
I am using a swap partition separate from ZRAM, and it is well over 1.5 times the size of my 32 gb of RAM. The command “systemctl hibernate” also results in the problem I have described.

I have just confirmed that this theory is correct.

After hibernating and when hibernated closing the lid, I removed the battery for several minutes.

Then I replaced the battery and opened the lid. The machine remained entirely off. Restarting by using the power button, the machine then successfully resumed from hibernation, to the former state of my work.