Sometimes I would like to shut down in a hurry. By hurry I mean 5 to 10 seconds. Assume I can run any script with root privileges in tty which I've prepared beforehand, and after 5 or 10 seconds the power will go out. What's the best way to minimize the damage (like maybe unmounting all devices, or closing all open files)?
2 Answers
Anyway you can shutdown from terminal using the command,
sudo shutdown -h now
or,
sudo poweroff
Afterwards you need to put your sudo password. Here is an answer describes how you can shutdown from terminal without entering password. To do so,
Just run sudo visudo
from terminal and add the following line:
%user_name ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/shutdown
This allows you to run the above commands, using sudo
, however with no password.
So, sudo poweroff
or sudo shutdown -h now
will now result in a password less shutdown.
If you want a step further ahead you can make a alias named stopnow
or whatever,
alias stopnow='sudo poweroff'
That would enable you to shutdown the system by only running stopnow
in terminal.
Alt+Print Screen+R,E,I,S,U. Then Power Button to shut down.
Will quickly and safely shut down a computer running Linux (Ubuntu). It is talking directly to the kernel, and can be used at anytime.
Reference: http://en.wikipedia.org/wiki/Magic_SysRq_key
This is a modified version of REISUB. Since we don't want a restart, B is replaced with just shutting the computer down.

- 3,927
-
2
-
ok, so I guess replace B with O then to shut down? I'm not going to try it because I don't need to, but the Wikipedia article says that will shut it down. – Paul Tanzini Dec 12 '13 at 14:46
-
This is in short "Reboot Even If System Utterly Broken". It is not going to shutdown the system. – sourav c. Dec 12 '13 at 14:52
-
This looks pretty good, I'm going to test
echo reisuo > /proc/sysrq-trigger
now, see you in a few minutes if it works. – ike Dec 12 '13 at 14:52 -
The terminal command as root didn't do anything, the button combo did something, but not shutdown, more like a freeze, but on reboot, no
fsck
needed – ike Dec 12 '13 at 15:11 -
2I don't think this is minimizing the damage, on the contrary, this should only be used when the system is not responding. Killing processes is never good. And even when using this key combo we should wait a few secs between pressing those keys. (let the processes which can terminate safely before we SIGKILL them, wait for the sync before we unmount, etc.) – falconer Dec 12 '13 at 15:13
-
-
-
Interesting; I know from experience using REISUB that as soon as you start it kills the screen and goes into a zombie like state. It doesn't actually power down until you hit that B. I'm not sure how the O combination works, but B is instant restart. If you can stop the power-on by hitting the power button, REISUB should work out for you. – Paul Tanzini Dec 12 '13 at 15:39
-
@Dash_plus_Java Unless you hit
B
it would not going to reboot. Every letter in the sequence do a separate job, likeR
=take control of keyboard back from X,E
=send SIGTERM to all processes, allowing them to terminate gracefully,I
=send SIGKILL to all processes, forcing them to terminate immediately,S
=flush data to disk,U
=remount all filesystems read-only. See wiki link. – sourav c. Dec 12 '13 at 15:45 -
1@Dash_plus_Java why don't you edit your answer, it is not actually an answer to the question. isn't it? – sourav c. Dec 12 '13 at 15:46
-
@souravc Done. Since we don't need a reboot, just leave the B off and shut down the computer with power button. – Paul Tanzini Dec 12 '13 at 16:10
sudo init 0
may be a faster command, but would skip the notifying users and wont stop applications that are running, which may be bad. – Paul Tanzini Dec 12 '13 at 15:05shutdown: time expected
And to shutdown you need the -h option. And this can sometimes take a long time which I don't always have. – ike Dec 12 '13 at 15:10sudo poweroff
should be quite fast and safe. I use it a lot when testing @#$% kernel boot parameters... – Rmano Dec 12 '13 at 16:46shutdown
alone was working in the linked answer because it was (unwisely) aliased tosudo shutdown now
. You can aliasSTOPNOW
tosudo poweroff
still... – Rmano Dec 12 '13 at 17:03visudo
. I am editing my answer. – sourav c. Dec 12 '13 at 17:07sudo poweroff
took about 25 seconds on my machine. – ike Dec 12 '13 at 17:11sudo init 0
suggestion? It is not clean but cleaner than the Magic SysRQ. See also http://superuser.com/questions/108704/how-to-shutdown-instantly – Rmano Dec 12 '13 at 17:15sudo init 0
? I think it is not completely safe. – sourav c. Dec 12 '13 at 17:29poweroff
is so slow? – Rmano Dec 12 '13 at 17:32waiting for all processes to terminate
, then about 10 to power off. And I have a Dell XPS 8300 with 16GB ram and core i7 2nd gen and ubuntu 13.10 – ike Dec 12 '13 at 17:34sudo init 0
also took about 25 seconds – ike Dec 12 '13 at 20:03