Thursday, February 2, 2017

Quick and dirty reboot of remote Linux server

It sounds annoying sometimes when I was rebooting the remote Linux server, especially on the Cloud. After issuing command like:

$
$ reboot now

The terminal session will definitely be disconnected but the server still hangs in the middle of the termination process and would not boot-up.

We can hard reset the machine if we are sitting in front of it. Holding down [Alt] and [SysRq] (which is the Print Screen key) while slowly typing keys R, E, I, S, U, B will get you safely restarted. Meanings of the keys as follows:

  •     R: Switch the keyboard from raw mode to XLATE mode
  •     E: Send the SIGTERM signal to all processes except init
  •     I: Send the SIGKILL signal to all processes except init
  •     S: Sync all mounted filesystems
  •     U: Remount all mounted filesystems in read-only mode
  •     B: Immediately reboot the system, without unmounting partitions or syncing


For the cloud server, we definitely need some sort of Terminal commands to put the server strictly into reboot process no matter what process is currently running or hanging. At least, we can diagnose it after it boots up again.

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

First command mimics the keystroke of System Request [SysRq] key and the second one mimics hitting [b] key.

So, [b] for what? It does immediately reboot the system, without unmounting partitions or syncing

So just be prepared, you may suffer any data loss afterwards. However, it's really useful at the time you want to make sure the server does reboot immediately.

*A suggestion would be manually stopping major services and processes before you issue such commands.