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

rupeshforu3

In the zone
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
 
OP
R

rupeshforu3

In the zone
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

Alakh Niranjan
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.
 
OP
R

rupeshforu3

In the zone
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

Journeyman
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

Journeyman
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)
 
OP
R

rupeshforu3

In the zone
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

Journeyman
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

Journeyman
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

Feel Pain.
when power button is pressed and held for 10 seconds, the bios cuts of the power and does force shutdown. Not recommended by many.
 
OP
R

rupeshforu3

In the zone
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
 
OP
R

rupeshforu3

In the zone
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

Super Moderator
Staff member
First check / replace your UPS battery.

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