Adding this line to Dietpi/config.txt does not produce the desired shut-down. The same pi3B+ using Raspbian works.

Entering dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up on the CLI produces no errors. lsmod says gpio-keys is loaded (but not used).

How to proceed?

AFAIK the syntax to load the overlay from console should be:
dtoverlay gpio-shutdown gpio_pin=3,active_low=1,gpio_pull=up
dtoverlay -l then has “gpio-shutdown” in the list?


2019-06-20 21:15:59 root@micha:/tmp# dtoverlay -h gpio-shutdown
Name:   gpio-shutdown

Info:   Initiates a shutdown when GPIO pin changes. The given GPIO pin
        is configured as an input key that generates KEY_POWER events.
        This event is handled by systemd-logind by initiating a
        shutdown. Systemd versions older than 225 need an udev rule
        enable listening to the input device:

Please try:

systemctl unmask systemd-logind
systemctl start systemd-logind

DietPi v6.24.1 : 12:39 - Mon 24/06/19

  • Device model : RPi 3 Model B+ (armv7l)
  • CPU temp : 53’C : 127’F (Running warm, but safe)
  • FQDN/hostname : alarmPi2
  • LAN IP : (eth0)
  • MOTD : You can select the content of this banner by running: dietpi-banner

DietPi Team : MichaIng (lead), Daniel Knight (founder)
Image : DietPi Core Team (pre-image: Raspbian Lite)
Web : https://DietPi.com | https://twitter.com/dietpi_
Patreon Legends : PINE64 community
Donate : https://DietPi.com/#donate
DietPi Hosting : Powered by https://MyVirtualServer.com

root@alarmPi2:~# dtoverlay gpio-shutdown gpio_pin=3,active_low=1,gpio_pull=up
DTOVERLAY[error]: invalid override value ‘3,active_low=1,gpio_pull=up’ - ignored

  • Failed to set gpio_pin=3,active_low=1,gpio_pull=up
    root@alarmPi2:~# dtoverlay=gpio-shutdown gpio_pin=3,active_low=1,gpio_pull=up
    root@alarmPi2:~# dtoverlay -l
    No overlays loaded
    root@alarmPi2:~# systemctl --version
    systemd 232
    root@alarmPi2:~# systemctl unmask systemd-logind
    root@alarmPi2:~# systemctl start systemd-logind
    Failed to start systemd-logind.service: Unit dbus.socket not found.

I have just noticed that “shutdown now” -

stops the green LED and leaves the red LED on as expected but the USB current goes up from 0A68 to 0A82 - this is not what I expected! Raspbian April 2019 current goes down to 0A21. I don’t know whether it is inherrent in my dietPi or is due to the result of the dtoverlay thing.

Downloaded , uncompressed and uploaded today’s 7z to card.

Accepted minimal image.

After updates, entered “shutdown now”, current now falls to 0A19.

root@alarmPi2:~# dtoverlay gpio-shutdown gpio_pin=3,active_low=1,gpio_pull=up
DTOVERLAY[error]: invalid override value '3,active_low=1,gpio_pull=up' - ignored
* Failed to set gpio_pin=3,active_low=1,gpio_pull=up
root@alarmPi2:~# dtoverlay=gpio-shutdown gpio_pin=3,active_low=1,gpio_pull=up
root@alarmPi2:~# dtoverlay -l
No overlays loaded

dtoverlay=gpio-shutdown… from command line btw cannot work. It’s shell syntax to create a variable but not run any command.
Just to check: echo $dtoverlay

It looks like all parameters need to be separated by spaces (separate arguments):

dtoverlay gpio-shutdown gpio_pin=3 active_low=1 gpio_pull=up
dtoverlay -l

The usage info is indeed misleading.
dtoverlay -h gpio-shutdown shows dtoverlay=gpio-shutdown,=, but this is only the syntax for config.txt, not the command line. This is shown by the general dtoverlay usage info:
dtoverlay [=…]
But there again one cannot derive how to add multiple parameters. However space separated makes sense as these are then added as individual arguments to the command.

I have the same problem with a Pi Zero W running v6.25.3. I have the shutdown button working on a Pi3+ running Debian.

systemd-logind is unmasked? systemctl unmask systemd-logind && systemctl start systemd-logind

And nothing else blocks/uses the GPIO pins, e.g. I2C, SPI or UART (serial device/console)?
ls -Al /dev gives an overview of enabled devices, ttyS0, ttyAMA0, i2c*, and spi* are examples that use GPIO pins.

I ran those two commands didn’t change anything.

Running ls -Al /dev returned this line amongst others

lrwxrwxrwx 1 root root 7 Aug 17 19:51 serial1 → ttyAMA0

Try to disable this serial device, as long as you don’t use any serial/UART login terminal:
/DietPi/dietpi/func/dietpi-set_hardware serialconsole disable

Although I am not 100% sure if this disables /dev/ttyAMA0. It disables any boot messages and login console attached to this device, but via usual methods one can only disable /dev/ttyS0 completely on RPi models with WiFi+Bluetooth. /dev/ttyAMA0 shows up when Bluetooth is disabled, since otherwise Bluetooth uses/block this. /dev/ttyAMA0 uses GPIO 14 & 15 (so pins 8 & 10) AFAIK, so these cannot not be used for the shutdown button.

Aside the hardware side, you assured the user that executes the script has sufficient permissions (e.g. part of “gpio” group)? dtoverlay declaration in /DietPi/config.txt (and /boot/config.txt on Raspbian) is exactly the same?
lsmod lists gpio_keys?

I ran
/DietPi/dietpi/func/dietpi-set_hardware serialconsole disable
No change.

I don’t have a script running , just the dtoverlay line added to the DietPi.txt, so haven’t changed any permissions.
I have checked both txt files are the same.
lsmod lists gpio_keys just returns Usage: lsmod


Also if I run dtoverlay -l I get No overlays loaded

lsmod is the command you should use and the output should contain gpio_keys.

dtoverlay -l only shows the overlays loaded at runtime, thus not the ones added to config.txt.

Note as mentioned above that the syntax for loading overlays at runtime is slightly different, e.g.:
dtoverlay gpio-shutdown gpio_pin=3 active_low=1 gpio_pull=up
Not sure currently if this fails, when loaded via config.txt already, but AFAIK it works. Then you can check via dtoverlay -l if it has been successfully loaded, respectively otherwise the first will throw an error message already.

If overlay and module is loaded and systemd-logind running (systemctl status systemd-logind) and the shutdown button does still not work, then we have to check if the pins are responding as expected. I don’t have the commands here, but it is possible to send input to the keys from command lines as well, as well as checking the current state of the physical pins.

Ok typed the wrong thing for lsmod, this is the reply from lsmod
gpio_keys 9575 0

When I run the overlay from the command line with spaces I get

  • Failed to apply overlay ‘0_gpio-shutdown’ (kernel)

This is what I get when I run systemctl
root@DietPi:~# systemctl unmask systemd-logind
root@DietPi:~# systemctl status systemd-logind
● systemd-logind.service - Login Service
Loaded: loaded (/lib/systemd/system/systemd-logind.service; static; vendor preset: enabled)
Active: inactive (dead)
Condition: start condition failed at Sat 2019-08-17 22:06:53 BST; 1 day 19h ago
Docs: man:systemd-logind.service(8)

Ah that’s it, dbus is missing, didn’t think about that:
G_AGI dbus
systemctl restart systemd-logind

Actually libpam-systemd might be required as well: G_AGI libpam-systemd


It shuts down and a second click of the button it restarts. Tried it a few times and works ok. I will try adding the super capacitor UPS on pin 18 next.

Thanks very much.

Great, probably some info we should add somewhere, at least to dietpi.txt where you can set systemd-logind to be enabled prior to first boot.

Was dbus sufficient or libpam-systemd required as well?

Sorry I ran both first time before trying.

Okay, could be tested, but actually the docs state that libpam-systemd is required for logind functionality in general: https://packages.debian.org/stretch/libpam-systemd
The only other thing that systemd-logind does, AFAIK, is automatically spawning gettys on demand, but not tracking/handling any session tasks.

I just done another install and I didn’t need to run G_AGI libpam-systemd for it to work.

For what ever reason I had to unmask the systemd-logind.

G_AGI dbus
G_AGI libpam-systemd

sudo systemctl unmask systemd-logind

Bootconfig change:
sudo nano /boot/config.txt

I am looking for a way to change the power up from Pin 3 to Pin 21, cause Pin 3 is already in use.