DEV Community

vast cow
vast cow

Posted on

How to Disable Suspend on Lid Close in Rocky Linux

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)

Recommended Configuration

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
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

Expected output:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
Enter fullscreen mode Exit fullscreen mode

To check the current default target:

systemctl get-default
Enter fullscreen mode Exit fullscreen mode

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

sudo systemctl set-default multi-user.target
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Add the following under the [Login] section:

[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
Enter fullscreen mode Exit fullscreen mode

Apply the changes:

sudo systemctl restart systemd-logind.service
Enter fullscreen mode Exit fullscreen mode

If the System Still Suspends

First, inspect the logs:

journalctl -u systemd-logind -b | grep -i -E 'lid|suspend|sleep'
Enter fullscreen mode Exit fullscreen mode

Then check whether another process is managing power events:

systemd-inhibit --list
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To restore them later:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Enter fullscreen mode Exit fullscreen mode

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)

Top comments (0)