20

Or is shutdown -h now the fastest it can get?

I look for some syscall or similar that will allow to skip lots of the stuff done prior to shutdown (in particular to care about the running proccesses).

At best I would like a kernel related solution, being ignorant to the init-middleware (like systemd or upstart).

The risks related with i.e. killing directly all services like cups/apache/pulseaudio etc... I would not care....

remark: the solution should be software-vice. Pressing buttons at the device is not what I look for.

  • 8
    "The risks related with i.e. killing directly all services like cups/apache/pulseaudio etc... I would not care...." -> Are you sure? Leaving complex software in an inconsistent state may lead to nasty surprises next time it is used. Maybe you should consider disabling services you don't use much (e.g. cups, apache); you can always start and stop those things manually when you do want to use them. – goldilocks Oct 21 '14 at 13:58
  • The method I seek is for the moment in which I want to avoid people having access to my PC. Any delay in shutting down allows mischieve. I rather loose data then expose it. – humanityANDpeace Oct 21 '14 at 13:59
  • 2
    Also visit this – Pandya Oct 21 '14 at 14:01
  • 8
    There's an idea. Start saving money for some new hardware though. – John WH Smith Oct 21 '14 at 14:02
  • sudo shutdown -P 0 I use that and it starts the shutdown process right away, no matter what apps are open – gkmohit Oct 21 '14 at 15:02
30

It doesn't get much faster than using the System Request (SysRq) functionality and then triggering an immediate reboot.

This is a key combination understood by the kernel.

Enable SysRq:

echo 1 > /proc/sys/kernel/sysrq

Now, send it into reboot.

echo b > /proc/sysrq-trigger

b - Immediately reboot the system, without unmounting or syncing filesystems.

Note:

Although this is a reboot it will behave like the power has been cut off, which is not recommended.

If you want to sync and umount the filesystems before hand then use:

echo s > /proc/sysrq-trigger
echo u > /proc/sysrq-trigger

or if you just want to power off the system then:

echo o > /proc/sysrq-trigger

Magic key combinations

There are also key combinations to use that are interpreted by the kernel:

Alt+SysRq / Print Screen+Command Key

Command Keys:

R - 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.
B - Reboot.

Quoting from the Magic SysRq Key Wiki:

A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked up.

  1. Hold down the Alt and SysRq (Print Screen) keys.
  2. While holding those down, type the following keys in order, several seconds apart: REISUB.
  3. Computer should reboot.

A way to remember these are:

"Reboot Even If System Utterly Broken" or simply the word "BUSIER" read backwards.

References

Magic SysRq Key Wiki
Fedora SysRq

  • 11
    It's important to note that a clean system can take even less than 2 seconds to shutdown. When I call poweroff on my Arch machine, I can't even see the shutdown log being printed on screen... – John WH Smith Oct 21 '14 at 14:07
  • Before the second echo, you would want to run sync (linux.about.com/library/cmd/blcmdl8_sync.htm), which would make sure that buffers are written to the disk, including superblocks. – Arcege Oct 21 '14 at 14:14
  • you suggest the b being echod not o. Is b better? – humanityANDpeace Oct 21 '14 at 14:25
  • It depends what you mean by better. While the b option is very fast, it does not sync the disks, which is not ideal, there are many options which provide ways of cutting down on the shutdown time, some more extreme than others. There is also a panic option. Read the wiki and trial and error to see what best meets your needs. – geedoubleya Oct 21 '14 at 14:41
  • Well on my screwed-up system the echo o /proc/sysrq-trigger does create a hang. The system stays on. Indeed the b the system is gone. Yet it reboots that means that the RAM can be kept, which is a vulnerability I would like the b option with the system being off in the end. Sadly this does not work with o option in my sys. Thanks for the suggestion to you and also to @Pandya – humanityANDpeace Oct 21 '14 at 14:57
8

The nasty approach is shutdown -h -n now.

Note that this will not do any cleanup, so file systems may get inconsistent, databases break etc., but it shuts down the system really fast.

  • 1
    thank you, this sounds interessting: is this -n option documented and still in current version of shutdown? – humanityANDpeace Oct 21 '14 at 15:47
  • 1
    Yes, that is standard. It directly tells the kernel to drop everything. This command is normally used from the last shutdown script, when the regular shutdown has completed. – Simon Richter Oct 21 '14 at 15:50
  • 7
    But I cannot stress enough that this will most likely cause bad effects, as it is largely equivalent to pulling the plug. – Simon Richter Oct 21 '14 at 15:51
  • Wonderfully simple and effective. This -n option is exactly what I was looking for. Thank you SO MUCH for answering the question as-asked. You don't know how frustrating it is to ask a question and hear the neckbeards all tell you why your question is wrong instead of just answering it. I would upvote this answer fifty times if I could. THANK YOU. – Joshua Pech Sep 14 '17 at 20:49
5

Some distros offer a poweroff command which is simpler than shutdown.

Using it with:

poweroff -f

will perform a disk sync and then power down. This is a good compromise between being much faster while still performing the minimal shutdown to ensure the filesystems are not corrupted.

0

Try using the init command:

init 0

protected by Michael Mrozek Oct 24 '14 at 2:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.