1

On my notebook in the dash (above the keyboard) there is physical button for turning the computer on and off.

How to set up this button to turn off the system immediately without confirmation? Where is the handler for this button? Or how to create it and use? I want to put to it systemctl poweroff.

There is the similar question - Disable shutdown confirmation ubuntu 20.04 but it is not only about setting up the physical "Power off" button. For configuring Shutdown/Reboot menu items in system menu Bring Out Sub Menu Extension can be used as explained here. Moreover the accepted answer in this question is not working - I tried it. Also this answer explains that the solution must be another.

Please do not suggest to me:

  • To press to the button and wait a minute.
  • To make keyboard shortcut.

I have "Power button" and I want to make use of it. Or at least to know that this is impossible in Ubuntu 20.04.

0

2 Answers 2

2

First solution

I found working solution here and here:

  • Create file:

sudo nano /etc/acpi/events/powerbtn

with the content:

event=button/power (PWR.||PBTN)
action=/sbin/poweroff
  • Then restart the acpi daemon with:

sudo acpid restart

  • Try to use "Power off" button.

Related links:


Second solution

Also I tested the answer of Terrance and confirm that this recommendations is also working.

1

For GNOME Desktop, in your terminal run

hostnamectl set-chassis vm

then reboot. After the system reboots it should work where the power button will now power off the system without asking.

To set it back run

hostnamectl set-chassis desktop

same as above, reboot the system then it should start asking again about shutting down.

Hope this helps!

2
  • Terrance, thanks. I just tested everything in your answer and confirm that all works as you described (only not tested for the second user). Thanks for the solution! I'm curious what command gets executed under this VM chassis mark to reboot the system? And where this command is configured? May it can be customized? Feb 14, 2022 at 19:07
  • For me, it works only if the monitor ever gets connected. Otherwise (if the monitor wasn't ever connected since power on), the power button is just ignored.
    – DeepSOIC
    Sep 26, 2023 at 9:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .