Running Ubuntu on Laptop? Here’s the beginner’s guide shows how to configure and tell what to do when the lid is closed.
By default Ubuntu will go suspend when you close the laptop lid. There’s no option to change this action since the relevant settings in Dconf Editor do not work.
What if you want your machine go to sleep, power off, hibernate, or just do nothing when you close the laptop lid? Well, you can do this by changing the configuration file for the systemd-logind service.
1. Edit the systemd-logind config file:
terminal from your system app launcher. When it opens, run command to edit the config file:
sudo -H gedit /etc/systemd/logind.conf
For Ubuntu based systems, you may replace gedit with your system text editor.
About the key lines:
Remove # at the beginning for 1, 2, or all the following lines and changing the value.
- #HandleLidSwitchDocked=ignore – If your system is inserted in a docking station, or if more than one display is connected, then the action occurs if specified.
- #HandleLidSwitchExternalPower=suspend – If your system is on external power, the action occurs if specified.
- #HandleLidSwitch=suspend – For all other cases, the value of HandleLidSwitch will occur if enabled.
About the key values:
The value for the lid close behavior can be:
- ignore – do nothing.
- poweroff – shutdown machine.
- reboot – restart the system.
- lock – screen lock all running sessions.
You can also set the value to suspend, hibernate (make sure if hibernate works firstly), halt, hybrid-sleep (save system state to both disk & RAM), suspend-then-hibernate, or even kexec system call.
2. To make things simple:
To change lid close action without any condition, enable the #HandleLidSwitch=suspend line and change the value to ignore, lock, poweroff, etc.
To tell Ubuntu what to do when your notebook plugged, also remove # from #HandleLidSwitchExternalPower=suspend line and change its value.
For multi-display or dock station, remove # from #HandleLidSwitchDocked=ignore to enable it and set a value.
3. Apply changes:
After changes, save the file and restart the logind service by running command in terminal:
systemctl restart systemd-logind.service
SAVE YOUR WORK before running the command as it will log out the current session.