Reset any linux system from the console as if the reset button was pushed

What if you do not have the physical access to your server and you know there is a great possibility your server won’t shutdown properly, when you issue a reboot command (halt, shutdown and so on).
Ok, here is a situation, you have a dedicated server with no panel for resets, no IPMI access and a kernel bug just left a process with Disk sleep or any uninterruptible state that even a kill -9 won’t help! So just rebooting with the normal process of shutdown (going through the init levels or systemd states) won’t help, the shutdown process will be waiting infinite time for proper process termination, which won’t happen! All you need is just a simple old reset button pushed, but you have only a console, here what you can do and it is essentially the same as if someone pushed the server reset button:

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

This technique is known as magic SysRq key and have more options, but this is probably most used. It will immediately reboot the server, without unmounting or syncing filesystems. So be extremely careful and an additional advice: issue a sync command before the reset, even if you know it it won’t finish.

sync &

BE WARNED, you can break your filesystem (with the modern filesystem and their late state this is unlikely to happen) or database (this is really likely to happen, but you could always repair or at least shutdown the database software and/or make a backup before), but you can save your server!

Leave a Reply

Your email address will not be published. Required fields are marked *