DIGIT-ARC read-only archive · snapshot: July 23, 2026

How to halt Linux and windows systems immediately and safely by pressing power button

15 posts · originally from https://geek.digit.in/community/threads/how-to-halt-linux-and-windows-systems-immediately-and-safely-by-pressing-power-button.211140/

R
rupeshforu3 Original post #1
Apr 14, 2022 at 2:52 PM
Hi I am Rupesh from India and I have bought new PC with Intel i3 10th gen processor and asus prime h510 me motherboard. At present I have installed Fedora 35 and windows 11 and it is running properly.

I am living in a place where there is no constant power supply and so I have bought new ups power supply. Now my requirement is I want to shutdown the system properly and immediately by unmounting all file systems and abort all processes. Generally this can be done by pressing power off or shutdown button in desktop environments like gnome desktop or kde. There is no time to do this because my ups can supply power upto two minutes only. So is there any way to shutdown the windows and Linux systems properly by pressing power button present in cabinet box.

Many of you may ask what is the need of shutting down system immediately. If I don't do this my file system may be corrupted and even hardware may be damaged.

I have seen some options in Linux such as "select what to do when you press power button" and I have selected to shutdown but it is not working properly.

Is there any way to write a script in both windows and Linux systems to shutdown system properly and immediately when I press power button.

Regards,
Rupesh.


Sent from my LM-G710 using Tapatalk
vidhubhushan
Apr 14, 2022 at 3:45 PM
not used for years but i think there were 2 options :
1. sudo shutdown -h now
2. Alt + SysRq + O
R
Apr 14, 2022 at 3:54 PM
May I know how to run shutdown -h now automatically when I press power button present in cabinet box.

Here the issue is there is no time to enter shutdown command in terminal emulator or press other button because even ups may not function after two minutes.

Sent from my LM-G710 using Tapatalk
vidhubhushan
Apr 14, 2022 at 3:59 PM
as i said, i have not worked on it for yearsm i will try to remember but it might not be the exact option as things have changed a lot and also i used to mainly work on unix systems.
1. try to create a shell script with the command. create a shortcut of it and click on that to run.
2. try the second option using keyboard.
SaiyanGoku
Apr 14, 2022 at 4:28 PM
*www.windowscentral.com/how-customize-power-button-action-when-pressed-windows-10
R
Apr 14, 2022 at 6:39 PM
Hi have a look at the following which consists of links to the work done by others on the same subject for Linux.

*www.google.com/search?q=execute+a+...en+power+button+is+pressed&aqs=heirloom-srp..

Sent from my LM-G710 using Tapatalk
K_akash_i
Apr 14, 2022 at 7:56 PM
rupesh, i'm on fedora 36 , this is what i get when i press power button,then it takes like 5 seconds to shut down,
Screenshot from 2022-04-14 19-51-27.png
K_akash_i
Apr 14, 2022 at 8:06 PM
Screenshot from 2022-04-14 19-57-47.png


i have done the same as u did.could u upload ur scrnshots or confirm this is how u selected it? (if thats the case maybe u may require a fresh install)
R
Apr 14, 2022 at 8:10 PM
At present I am running ffmpeg conversion and after some time I will try as you said.

Someone else from Fedora forums suggested as follows.

Try press and hold the power button for about 4 seconds.
It works on every machine I have here.
(It's a hobby, but I like it)

Can I apply this method to both windows and Linux.

Sent from my LM-G710 using Tapatalk
K_akash_i
K_akash_i #10
Apr 14, 2022 at 8:11 PM
u should also disable fast startup on windows if u havent. if u have something concerning these .
The Pros and Cons of Windows 10’s “Fast Startup” Mode
K_akash_i
K_akash_i #11
Apr 14, 2022 at 8:12 PM
At present I am running ffmpeg conversion and after some time I will try as you said.

Someone else from Fedora forums suggested as follows.

Try press and hold the power button for about 4 seconds.
It works on every machine I have here.
(It's a hobby, but I like it)

Can I apply this method to both windows and Linux.

Sent from my LM-G710 using Tapatalk
yes press and hold is the fastest way. but i dont know whether its safe to always do that.
RumbaMon19
Apr 14, 2022 at 8:19 PM
when power button is pressed and held for 10 seconds, the bios cuts of the power and does force shutdown. Not recommended by many.
R
Apr 14, 2022 at 9:28 PM
Yes others in Unix forums suggested not to do as you said.

In Unix forums they also suggested to run "init 0" with super user permissions. They said that this is the safest and fastest way of shutting down Linux system.

Sent from my LM-G710 using Tapatalk
R
Apr 14, 2022 at 10:30 PM
In /etc/systemd directory there is a file called logind.conf and in this file there is the following line

#HandlePowerKey=poweroff

Is there any way to replace poweroff with init 0.

At present when I press power button present in cabinet box it is asking for confirmation whether to power off or not. Instead I want to power off with out any confirmation.

Sent from my LM-G710 using Tapatalk
topgear
topgear #15
May 10, 2022 at 7:45 AM
First check / replace your UPS battery.

Install your OS on a SSD for fastest possible shutdown and startup.