RHEL: What is "SysRq key" and how to use it

RHEL: What is "SysRq key" and how to use it

# Tested on RHEL 5, 6 & 7


# What is the "Magic" 'SysRq' key?
# ------------------------------------------------------------------------------------------

# According to the Linux kernel documentation:
#
#  It is a 'magical' key combo you can hit which the kernel will respond to regardless of
#  whatever else it is doing, even if the console is unresponsive.
#
# The 'SysRq' key is one of the best (and sometimes the only) way to determine what a
# machine is really doing. It is useful when a system appears to be "hung" or for
# diagnosing elusive, transient, kernel-related problems.



# How do I enable and disable the 'SysRq' key?
# ------------------------------------------------------------------------------------------

# For security reasons, Red Hat Enterprise Linux disables the 'SysRq' key by default. To
# enable it, run:

echo 1 > /proc/sys/kernel/sysrq

# Or: sysctl -w kernel.sysrq=1

# List of possible values in /proc/sys/kernel/sysrq:
#
#  0 - disable sysrq completely
#  1 - enable all functions of sysrq
#    >1 - bitmask of allowed sysrq functions (see below for detailed function description):
#      2 - enable control of console logging level
#      4 - enable control of keyboard (SAK, unraw)
#      8 - enable debugging dumps of processes etc.
#     16 - enable sync command
#     32 - enable remount read-only
#     64 - enable signalling of processes (term, kill, oom-kill)
#    128 - allow reboot/poweroff
#    256 - allow nicing of all RT tasks


# To disable it:

echo 0 > /proc/sys/kernel/sysrq

# Or: sysctl -w kernel.sysrq=0


# To enable it permanently, set the kernel.sysrq value to 1. That will cause it to be
# enabled on start up

# RHEL 5 & 6
vi /etc/sysctl.conf
   kernel.sysrq = 1

# RHEL 7
vi /usr/lib/sysctl.d/50-default.conf
   kernel.sysrq = 1


# Since enabling 'SysRq' gives you physical console access extra abilities, it is recommended
# to disable it when not troubleshooting a problem or to ensure that physical console
# access is properly secured.



# How do I trigger a 'SysRq' event?
# ------------------------------------------------------------------------------------------

# There are several ways to trigger a 'SysRq' event. On a normal system, with an AT
# keyboard, events can be triggered from the console with the following key combination:

# Alt+PrintScreen+[CommandKey]

# For instance, to tell the kernel to dump memory info (command key "m"), you would hold
# down the "Alt" and "Print Screen keys", and then hit the m key.

# Note that this will not work from an X Window System screen. You should first change to
# a text virtual terminal. Hit Ctrl+Alt+F1 to switch to the first virtual console prior to
# hitting the 'SysRq' key combination.

# On a serial console, you can achieve the same effect by sending a Break signal to the
# console and then hitting the command key within 5 seconds. This also works for virtual
# serial console access through an out-of-band service processor or remote console like
# HP iLO, Sun ILOM and IBM RSA.
# Refer to service processor specific documentation for details on how to send a Break
# signal; for example, How to trigger SysRq over an HP iLo Virtual Serial Port (VSP).

# If you have a root shell on the machine (and the system is responding enough for you to
# do so), you can also write the command key character to the /proc/sysrq-trigger file.
# This is useful for triggering this info when you are not on the system console or for
# triggering it from scripts.

echo 'm' > /proc/sysrq-trigger



# When I trigger a 'SysRq' event that generates output, where does it go?
# ------------------------------------------------------------------------------------------

# When a 'SysRq' command is triggered, the kernel will print out the information to the
# kernel ring buffer and to the system console. This information is normally logged via
# syslog to /var/log/messages.

# Unfortunately, when dealing with machines that are extremely unresponsive, syslogd is
# often unable to log these events. In these situations, provisioning a serial console is
# often recommended for collecting the data.



# What sort of 'SysRq' events can be triggered?
# ------------------------------------------------------------------------------------------

# There are several 'SysRq' events that can be triggered once the 'SysRq' facility is
# enabled. These vary somewhat between kernel versions, but there are a few that are
# commonly used:

#  m - dump information about memory allocation
#  t - dump thread state information
#  p - dump current CPU registers and flags
#  c - intentionally crash the system (useful for forcing a disk or netdump)
#  s - immediately sync all mounted filesystems
#  u - immediately remount all filesystems read-only
#  b - immediately reboot the machine
#  o - immediately power off the machine (if configured and supported)
#  f - start the Out Of Memory Killer (OOM)
#  w - dumps tasks that are in uninterruptible (blocked) state
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
linux aix Killing a process and all of its descendants
Viewed 1420 times since Tue, May 5, 2020
linux-training.be gives you books for free to study Linux
Viewed 3892 times since Sat, Jun 2, 2018
How To Run Multiple SSH Command On Remote Machine And Exit Safely
Viewed 1278 times since Tue, Aug 6, 2019
RHEL: Reserved space on a ext2/ext3/ext4 filesystem
Viewed 2957 times since Sun, May 27, 2018
How To: Linux Hard Disk Encryption With LUKS [ cryptsetup Command ]
Viewed 5348 times since Fri, Jul 13, 2018
How to disable SSH cipher/ MAC algorithms for Linux and Unix
Viewed 17225 times since Fri, Aug 21, 2020
Kernel sysctl configuration file for Linux
Viewed 2176 times since Fri, Aug 3, 2018
CONFIGURE OCFS2
Viewed 6405 times since Sat, Jun 2, 2018
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting
Viewed 13178 times since Wed, May 30, 2018
Fedora 32: Simple Local File-Sharing with Samba CIFS Linux
Viewed 7002 times since Sun, Dec 6, 2020