Hardware Reboot A Linux Server From Software

Have you ever stumbled upon a semi-frozen Linux server without being able to reboot it because of some processes waiting in uninterruptible sleep for some I/O, while still being able to login through SSH?

I have. More than once. So why not just force a hardware reset, writing some garbage to restricted I/O ports or memory location?. Sometimes, a hardware reboot is the only way to go. And, if you can do it from software, you may save a car travel just to push a button.

What follows is a program for Linux (found in some linux-kernel thread) which does just that in no more than 2 lines of C code. Enjoy!.

#include <sys /io.h>

int main() {
    ioperm(0x64,1,1);
    while (1) outb(0xfe, 0x64);
}

Usage:

  1. Compile: gcc -o hardreset hardreset.c
  2. Run: ./hardreset
  3. Pray for the server to come back... :)(

Guess what?. You must run it with root permissions.