The operation is explained in /boot/overlays/README
It is quite safe, I have it on all my Pi in case I need to shutdown a headless Pi (or one without keyboard attached), although my Pi are rarely shutdown, unless I am adding hardware.
I use dtoverlay=gpio-shutdown,gpio_pin=21 so I can shutdown by bridging pins 39/40
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 overlay only handles shutdown. After shutdown, the system
can be powered up again by driving GPIO3 low. The default
configuration uses GPIO3 with a pullup, so if you connect a
button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
you get a shutdown and power-up button. Please note that
Raspberry Pi 1 Model B rev 1 uses GPIO1 instead of GPIO3.
Load: dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin GPIO pin to trigger on (default 3)
For Raspberry Pi 1 Model B rev 1 set this
explicitly to value 1, e.g.:
dtoverlay=gpio-shutdown,gpio_pin=1
active_low When this is 1 (active low), a falling
edge generates a key down event and a
rising edge generates a key up event.
When this is 0 (active high), this is
reversed. The default is 1 (active low).
gpio_pull Desired pull-up/down state (off, down, up)
Default is "up".
Note that the default pin (GPIO3) has an
external pullup. Same applies for GPIO1
on Raspberry Pi 1 Model B rev 1.
debounce Specify the debounce interval in milliseconds
(default 100)
Answer from Milliways on Stack ExchangeRaspberry Pi 4 B GPIO boot and shutdown button(s) - Raspberry Pi Stack Exchange
raspberry pi - Disable GPIO by default and temporarily activate it via python script - Stack Overflow
python - Raspberry pi GPIO pin not turning off - Stack Overflow
pi 2 - How to turn off all gpio pin during powering up raspberry pi? - Raspberry Pi Stack Exchange
Videos
The operation is explained in /boot/overlays/README
It is quite safe, I have it on all my Pi in case I need to shutdown a headless Pi (or one without keyboard attached), although my Pi are rarely shutdown, unless I am adding hardware.
I use dtoverlay=gpio-shutdown,gpio_pin=21 so I can shutdown by bridging pins 39/40
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 overlay only handles shutdown. After shutdown, the system
can be powered up again by driving GPIO3 low. The default
configuration uses GPIO3 with a pullup, so if you connect a
button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
you get a shutdown and power-up button. Please note that
Raspberry Pi 1 Model B rev 1 uses GPIO1 instead of GPIO3.
Load: dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin GPIO pin to trigger on (default 3)
For Raspberry Pi 1 Model B rev 1 set this
explicitly to value 1, e.g.:
dtoverlay=gpio-shutdown,gpio_pin=1
active_low When this is 1 (active low), a falling
edge generates a key down event and a
rising edge generates a key up event.
When this is 0 (active high), this is
reversed. The default is 1 (active low).
gpio_pull Desired pull-up/down state (off, down, up)
Default is "up".
Note that the default pin (GPIO3) has an
external pullup. Same applies for GPIO1
on Raspberry Pi 1 Model B rev 1.
debounce Specify the debounce interval in milliseconds
(default 100)
I see two separate questions re use and configuration of "power buttons" to halt and boot an RPi 4:
Question 1:
Is the shutdown initiated with connecting the GPIO3 pin and the GND pin considered a safe shutdown?
Answer:
Yes - it is a safe shutdown. For details & confirmation, see REF 1 and REF 2.
Question 2:
I know that I can change the pin for shutdown, by changing dtoverlay=gpio-shutdown to dtoverlay=gpio-shutdown,gpio-pin=X, but is there a way to change the pin for boot up as well? Considering GPIO3 is normally used for I2C.
Answer:
Before going any further, I'd like to make sure we're clear on two points:
You can startup and shutdown your RPi with a single push-button switch connected between GPIO 3 and GND. You didn't specifically say that you wanted this 1-button arrangement, but it's far more convenient than using separate buttons for shutdown and startup. The only good reason I can think of to do it any other way is to reduce energy consumption while leaving power connected to the RPi.
Shutting down your RPi - whether done with a button press, or from the command line - does not remove power. Your RPi will continue to consume some power in
shutdownunless and until you "pull the plug".
That said, let's review the options:
Option 1. Move I2C from GPIO 3 and GPIO 4
The latest version of the firmware provides numerous overlay options for "relocating" I2C1, and/or "adding" I2C buses in /boot/config.txt. Review the latest version of the README for details.
This is the easiest option, and you need not read any further unless you need to minimize power consumption while in shutdown.
Option 2.
The RPi 4 introduced a new bootloader that's stored in EEPROM (instead of a bootcode.bin file). It also provided new configuration properties - two of which are relevant to reducing power consumption while the RPi 4 is shutdown or halted; i.e. the system is not running, but is powered up:
WAKE_ON_GPIO
If 1 then 'sudo halt' will run in a lower power mode until either GPIO3 or GLOBAL_EN are shorted to ground.
Default: 1 (0 in original version of bootloader 2019-05-10) Version: All
POWER_OFF_ON_HALT
If 1 and WAKE_ON_GPIO=0 then switch off all PMIC outputs in halt. This is lowest possible power state for halt but may cause problems with some HATs because 5V will still be on. GLOBAL_EN must be shorted to ground to boot.
Default: 0 Version: 2019-07-15
This informs us that the GLOBAL_EN input node may be used in lieu of GPIO 3 to restart the RPi 4 in all possible configurations of these parameters. Three things should be noted re GLOBAL_EN:
- It is not a GPIO
- It is pulled up to 5V
- The actual restart is not* triggered when
GLOBAL_ENis pulled LOW by pressing the pushbutton, but when it is "released" and allowed to return to its "pulled-up" (logic HIGH) state.
The GLOBAL_EN node is shown in the photo below:

Summary for Option 2:
This is more difficult than Option 1, but offers the advantage of reduced power consumption in halt/shutdown. The most straightforward hardware implementation is to use two pushbuttons - one for startup, one for shutdown. If you want to take some additional effort, a single button startup & shutdown solution is illustrated here.
Keep the fan connected to the 5v pin. Connect the other side of the fan via a transistor to ground. Switch the transistor on and off via a GPIO pin. This will turn the fan on when the transistor is switched on and switch it off when the transistor is switched. There are plenty of web sites with how to do this.
There is no need to write a program with recent Raspbian.
Only a single line needs to be added to cmdline.txt
dtoverlay=gpio-fan,temp=60000
See Fan Control