Magic SysReq key

2 minute read

While reading through the internet I learned about a magical key SysReq for Linux based systems. Well, I first discovered about the SysReq in the LinuxForYou now OSFY .When I first learned about it I was like “Where you have been my whole life ? “. Well before beginning let me show what this magic button looks like SysReq Yep!, that seems familiar, it’s the same key PrtScn which we use to take screenshots. Yes, my keyboard look a little messy, apologizes for that.

Now, let’s talk technical

SysReq is used or should be used to recover your linux machine from hangs. Plus, it can also be used to soft reboot your system without any filesystem corruptions. Check if SysReq key is enabled

 cat /proc/sys/kernel/sysrq
 

If you see a 0, then it’s not enabled, you can enable it with following command

  # Run as root or with 'sudo' prefix
  echo "1" > /proc/sys/kernel/sysrq
 

If you already have SysReq enabled you see 1 or any other value.Wikipedia explains it nicely

On newer kernels (since 2.6.12), it is possible to have a more fine-grained control.On these machines, the number written to /proc/sys/kernel/sysrq can be zero, one, or a number greater than one which is a bitmask indicating which features to allow.

Possible values are :

  1. disable SysRq
  2. enable SysRq completely

Values greater than 1 - bitmask of enabled SysRq functions


  • 2 - control of console logging level
  • 4 - control of keyboard (SAK, unraw)
  • 8 - debugging dumps of processes etc.
  • 16 - sync command
  • 32 - remount read-only
  • 64 - signalling of processes (term, kill, oom-kill)
  • 128 - reboot/poweroff
  • 256 - nicing of all RT tasks

Let’s Do the SysReq Dance

This part is also shamelessly copied from Wikipedia A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked up. This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work. Steps :

  • un R aw (take control of keyboard back from X),
  • t E rminate (send SIGTERM to all processes, allowing them to terminate gracefully),
  • k I ll (send SIGKILL to all processes, forcing them to terminate immediately),
  • S ync (flush data to disk),
  • U nmount (remount all filesystems read-only),
  • re B oot. (reboots the System)
Hold down the Alt and SysRq (Print Screen) keys. While holding them down, type the following keys in order, several seconds apart Computer should reboot. In practice, each command may require a few seconds to complete, especially if feedback is unavailable from the screen due to a freeze or display corruption.

Reboot Even If System Utterly Broken”- To remember it .

Security Issues

This wonderful may be seen as a security issue, because user who knows SysReq well, can bring down the system or a server with just some key pushes. (S)He can shutdown the system by just adding a o after the SysReq key. One way to safeguard is to disable SysReq

  # Run as root or with 'sudo' prefix
  echo "0" > /proc/sys/kernel/sysrq
 

Be safe and keep playing around :)

References and Further Readings

Updated:

Comments