Keeping Ubuntu Server awake on a Laptop when closing the lid

April 18, 2021

So recently I've reinstalled Ubuntu on my home server. This was due to me originally using Ubuntu Desktop then converting it to Server by uninstalling the Desktop Environment. Epic conversion, I know. Due to performance issues with it I needed to do a full reinstall and properly replace it with Ubuntu Server.

After installing I noticed closing the lid meant it would go to sleep and everything on the system would stop running. If you're here you probably, like me, want to keep it awake. Maybe it's so it's not lighting up the room or you want to tuck the laptop away. So let's do it.

If you're using Ubuntu Server I assume you're comfortable with the command line. So to begin with open the logind.conf file located at:

sh

1/etc/systemd/logind.conf

You can use either Nano or Vim so the command for Nano would be:

sh

1sudo nano /etc/systemd/logind.conf

The default login.conf

The default login.conf

Then find these two lines, which should be commented out:

text

1#HandleLidSwitch=suspend
2#LidSwitchIgnoreInhibited=yes

Uncomment them and change them to:

text

1HandleLidSwitch=ignore
2LidSwitchIgnoreInhibited=no

Modified logind.conf

Modified logind.conf

Then you'll want to exit Nano by using CTRL+X and pressing Y to save, then run

text

1sudo service systemd-logind restart

Which will restart the logind service. You're then free to close the lid. Why this isn't the default is beyond me but I assume there's a reason.

You may wonder what some of this does so let's cover it.

The file you're editing, logind.conf, handles configuration parameters of the systemd login manager, remember the service we restarted (systemd-logind.service)?

HandleLidEvents= Handles how the system responds to lid events, obviously.

LidSwitchIgnoreInhibited= Handles if the system respects blocking suspend on lid closure.

For more information, have a read here: https://www.man7.org/linux/man-pages/man5/logind.conf.5.html

And that's that. Simple.

Did this post help you?

Consider buying me a slice of pizza!