Skip to content
vast-cow's blog
Go back

How to Disable Suspend on Lid Close in Rocky Linux

Edit page

In Rocky Linux, lid-close handling is generally managed by systemd-logind, even when using multi-user.target. Set HandleLidSwitch=ignore. The Rocky Linux documentation also recommends setting HandleLidSwitch to ignore in /etc/systemd/logind.conf. (Rocky Linux Docs)

sudo cp -a /etc/systemd/logind.conf /etc/systemd/logind.conf.bak.$(date +%F-%H%M%S)

sudo mkdir -p /etc/systemd/logind.conf.d

sudo tee /etc/systemd/logind.conf.d/99-ignore-lid.conf >/dev/null <<'EOF'
[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
EOF

sudo systemctl restart systemd-logind.service

This ignores lid-close events in all cases: normal operation, when connected to AC power, and when docked. The default value of HandleLidSwitch is suspend; changing it to ignore prevents logind from suspending the system when the lid is closed. (man7.org)

Verification

systemd-analyze cat-config systemd/logind.conf | grep -E 'HandleLidSwitch'

Expected output:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

To check the current default target:

systemctl get-default

If you want to keep the system on multi-user.target:

sudo systemctl set-default multi-user.target

If Editing /etc/systemd/logind.conf Directly

If drop-in configuration files are not supported in your environment, you can edit the main configuration file directly:

sudo vi /etc/systemd/logind.conf

Add the following under the [Login] section:

[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Apply the changes:

sudo systemctl restart systemd-logind.service

If the System Still Suspends

First, inspect the logs:

journalctl -u systemd-logind -b | grep -i -E 'lid|suspend|sleep'

Then check whether another process is managing power events:

systemd-inhibit --list

With multi-user.target, desktop environments typically do not interfere. However, if a graphical session such as GNOME is running, the desktop environment may take over suspend handling. The systemd documentation notes that Handle* settings may be bypassed when another application holds a low-level inhibitor lock. (man7.org)

As a last resort, you can disable suspend-related targets entirely:

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

To restore them later:

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

In most cases, setting HandleLidSwitch=ignore in logind is sufficient. If you are using a laptop as a server and plan to operate it under heavy load with the lid closed, be aware that some models have reduced cooling performance when closed. The Red Hat documentation provides a similar caution. (Red Hat Documentation)


Edit page
Share this post:

Comments


Previous Post
Tool to Detect Changes and Check the Time and Content
Next Post
How to Use `getopt` with `getopt.h` / `getopt.c` in MSVC and Licensing Considerations