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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
- Hold down the Alt and SysRq (Print Screen) keys.
- While holding those down, type the following keys in order, several seconds apart: REISUB.
- 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
Method 2
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.
Method 3
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.
Method 4
Try using the init command:
init 0
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0