• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to use Magic SysRq tool in CentOS / RHEL

by admin

What is SysRq utility

In case your kernel freezes or/and hangs, you can use ‘magic’ SysRq tool. The ‘magic’ SysRq key allows instant access to several essential kernel commands, including Sync, Unmount, kill processes, showMem, showPc and reBoot. According to the Linux kernel documentation:

It is a ‘magical’ key combo you can hit to which the kernel will respond regardless of whatever else it is doing, even if the console is unresponsive.

How to Enable SysRq

The SysRq key can be activated by setting the ‘Magic SysRq’. You have to make sure that the kernel.sysrq in sysctl.conf is set properly:

kernel.sysrq = 1 (SysRq turned ON)
kernel.sysrq = 0 (SysRq turned OFF)
Note: On CentOS/RHEL 7 you should make the changes into “/usr/lib/sysctl.d/50-default.conf”

The above settings ensure that SysRq is enabled by default after system boot (By default it is disabled in CentOS/RHEL). To enable it, run in right away in the current session, use the below command:

# echo 1 > /proc/sys/kernel/sysrq

And to disable it again:

# echo 0 > /proc/sys/kernel/sysrq
NOTE: Since enabling SysRq gives someone with 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 to trigger a SysRq event

There are several ways to trigger a SysRq event. On most architectures SysRq events can be triggered from the console with the following key combination:

Alt+PrintScreen+[CommandKey]

The PrintScreen is the Key used as SysRq key in most of Linux the systems.

sysrq key CentOS RHEL

To access a non responsive system, press Alt+SysRq and H to get a list of options. Different kernel version may have different options. To get the supported options for your current kernel, you can run the command below as root:

# echo h > /proc/sysrq-trigger

and check dmesg output. Below is an example on RHEL 7 system:

# dmesg
[ 4338.124035] SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)

Types of SysRq events

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:

Key Function
m dump information about memory allocation
t dump thread state information
p dump current CPU registers and flags
c intentionally crash the system (kernel panic). Useful for capturing a vmcore through kdump.
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

How to trigger a SysRq event from root shell

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

This method has the additional benefit of working even when kernel.sysrq is set to 0.

CentOS / RHEL 6 : How to configure kdump
CentOS / RHEL 7 : How to configure kdump

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. gpasswd Command Examples in Linux
  2. Linux OS Service ‘syslog’
  3. modprobe: command not found
  4. mumble: command not found
  5. fstrim: command not found
  6. scontrol: command not found
  7. How to Install Cockpit’s Web Console in CentOS/RHEL 8
  8. certbot Command Examples in Linux
  9. antibody – “The fastest” shell plugin manager (Command Examples)
  10. ccomps: Decompose graphs into their connected components

You May Also Like

Primary Sidebar

Recent Posts

  • Chezmoi: A multi-machine dotfile manager, written in Go
  • cheat: Create and view interactive cheat sheets on the command-line
  • chars: Display names and codes for various ASCII and Unicode characters and code points
  • chafa: Image printing in the terminal

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright