Archives For Lid closed behavior

lid closed activity

In Ubuntu’s Power setting utility, you can only set to Suspend or Do nothing when your laptop lid is closed.

For those who want more lid closed hehavior, such as automatically Shutdown, Hibernate, or Restart, you can follow the steps below to enable either one by editing systemd config file.

power-settings

1. Search for and install dconf Editor in Ubuntu Software. Then launch it and navigate to org -> gnome -> settings daemon -> plugins -> power.

Change the value of “lid-close-ac-action” and “lid-close-battery-action”.

dconf-lid-close

Though it does not work for my laptop, I need to change the two values from “blank” to anything to make following steps work for me.

2. Open terminal from your app launcher or via Ctrl+Alt+T shortcut keys. When it opens, paste the command below and hit run:

sudo apt install gksu && gksudo gedit /etc/systemd/logind.conf

This command installs gksu, allows graphical apps to ask user password to run program as root, and then open systemd config file via Gedit text editor.

3. When the file opens, as the following picture shows, uncomment the line #HandleLidSwitch=suspend and change its value to:

  • HandleLidSwitch=poweroff – automatic shutdown when lid closed.
  • HandleLidSwitch=hibernate – automatic hibernate.
  • HandleLidSwitch=ignore – do nothing.

handlelidswitch

NOTE: The hibernate function is not enable by default in Ubuntu, you need to enable hibernation first before making Ubuntu auto-hibernate when lid is closed.

4. To apply changes, restart systemd service or restart your laptop.

systemctl restart systemd-logind.service

It does not add Shutdown and Hibernate options in your Power setting utility, but directly do the action after you made the change.

automatic shutdown when lid is closed

Ubuntu provides a built-in Power utility which allows to choose your laptop behavior when the lid is closed. However, there are only “Suspend” and “Do nothing” available out-of-the-box.

ubuntu lid closed settings

What if you want to shutdown or hibernate Ubuntu automatically when laptop lid is closed?

See what I did in my 64-bit Ubuntu 14.10:

1. Press Ctrl+Alt+T on keyboard to open the terminal. When it opens, paste the command below and hit enter to edit the systemd-logind settings:

sudo gedit /etc/systemd/logind.conf

Replace gedit with vi or nano if you’re on Ubuntu server without a graphical user interface.

Type in user password when it asks. Note that there will be no visual feed back when type in a password.

2. When the file opens, find out the line #HandleLidSwitch=suspend. Remove the # and change the value so it will be:

HandleLidSwitch=poweroffpower off when lid is closed.

or

HandleLidSwitch=hibernatehibernate when lid is closed

lid-close-action

3. After saved the changes, restart the computer so it takes place in next boot.

shutdown ubuntu when lid is closed

Already upgraded to Ubuntu 14.04? Well, you may want to change your laptop behaviour when the lid is closed.

You can easily set the vaule to “Suspend” or “do nothing” in System Setting -> Power window. Here’s how to shutdown (or hibernate) Ubuntu when you close the lid of your laptop.

ubuntu lid closed setting

To get started:

1. Press Ctrl+Alt+T on keyboard to open the terminal. When it opens, run the command below to open the configuration file via gedit editor:

sudo gedit /etc/systemd/logind.conf

Replace gedit with vi or other text editor if you’re on Server edition.

2. Find out the line #HandleLidSwitch=suspend, remove the # and change it to:

  • HandleLidSwitch=poweroff to shutdown computer when lid is closed
  • HandleLidSwitch=hibernate to hibernate computer when lid is closed
  • HandleLidSwitch=ignore to do nothing

3. Save the file and restart the service or just restart your laptop to apply changes.

sudo restart systemd-logind

Update: for Ubuntu 16.04, the command to restart the systemd service should be:

systemctl restart systemd-logind.service

That’s it. Enjoy!

ubuntu laptop lid closed behavior

 

This tutorial shows you how to change Ubuntu 13.10 behavior to make it shutdown, hibernate, suspend or do nothing when your laptop lid is closed.

Ubuntu Unity provides a built-in utility allows to change lid closed behavior, but it only allows to suspend and do nothing in my Ubuntu 13.10 machine:

ubuntu lid closed setting

If you want to hibernate or shutdown, or you’re on Ubuntu Server without GUI follow the below steps:

1. Press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to edit the config file:

sudo gedit /etc/systemd/logind.conf

For server edition, replace gedit with vi (Press i to start and Esc to exit editing, : followed by wq to save file.)

2. Find the line #HandleLidSwitch=suspend, remove the # and change it to:

  • HandleLidSwitch=poweroff to shutdown computer when lid is closed
  • HandleLidSwitch=hibernate to hibernate computer when lid is closed
  • HandleLidSwitch=ignore to do nothing

3. Save the file and restart the service or just restart your laptop to apply the changes.

sudo restart systemd-logind

That’s it. Enjoy!