Forcing Linux to Reboot
Until I branched out a few years ago from supporting Unix server to working with Linux clusters, I never really encountered this issue: you type “reboot”, “init 0”, or “shutdown” as root and… nothing happens. Or the system starts going down but then hangs on unmounting a filesystem or unloading a module. I think this happened once to a colleague of mine who was rebooting a Solaris server, but this is a common problem with Linux.
So what do you do when you need to reboot a stubborn Linux box? A likely reason for a Linux system to hang on shutdown is NFS and specifically – a stale NFS mountpoint. Before rebooting or shutting down the server, try unmounting filesystems manually. Open several SSH/telnet connections to the server (just in case one of the sessions hangs) and try running “umount -f” or “umount -l”. After that try shutting down NFS client manually by running “/etc/init.d/nfs down”. If this still hangs, at least now you know what’s messing with your reboot.
There are two more likely reasons for a system failing to respond to the “init” command (both “reboot” and “shutdown” are linked to the “init” command): a bad disk or a kernel module (such as a device driver, for example) failing to unload. If you really need to force your system to reboot, issue the following commands:
sync ; sync echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger
If you need to shut down the system, replace the last line with “echo o > /proc/sysrq-trigger”. Also, if your system disk is going bad, you may want to skip the “sync ; sync” part.
If you reboot the system using the “sysrq” trigger above, you will end up with some filesystem corruption. You should expect that during boot-up the system will run fsck for a while. So don’t panic if your server does not come up right away.