Search This Blog


Rebooting a Hung Linux System

Occasionally an uninterruptable process will get stuck and prevent you from being able to reboot. This could be due to the fact that the filesystem will not unmount because a process is hung open on the drive that's in an uninterruptable state.

There are certain key combinations that will send low-level kernel commands to the system which are made up of 'Alt+SysRq' Keys. If you do not have access to these 'special keys' you can emulate them by adding values to the contents of specific special files.

To enable sysrq commands (add the value of 1 for enable 0 for disable):
echo 1 > /proc/sys/kernel/sysrq

To run a sysrq command to reboot a hung system (sending the 'b' key to sysrq trigger):
echo b > /proc/sysrq-trigger

The above emulates 'Alt+SysRq+b' which 'Immediately reboots the system, without unmounting or syncing filesystems'

NOTE: To safely reboot a system generally the key combination is

unRaw      (take control of keyboard back from X),
 tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
 kIll      (send SIGKILL to all processes, forcing them to terminate immediately),
  Sync     (flush data to disk),
  Unmount  (remount all filesystems read-only),
And can be achieved in the same manor via commandline by echoing each key individually to /proc/sysrq-trigger

This feature is called Magic SysRq and more can be read here:

The following blog describes a fairly straightforward example and explains how to enable sysrq options on kernel boot time:

No comments:

Post a Comment