Magic SysRq — your emergency link to the kernel
With most Linux distributions you do have emergency access to the kernel should your machine freeze or become unresponsive to normal keyboard input. This then can allow for a safe reboot. The first thing to check is that your compiled kernel has support for Magic SysRq. To do this check out the config file in the /boot directory of your server or desktop machine. The OS I am working with is SUSE Enterprise Server 10 SP1. The kernel configuration file will relate to the running kernel. As I look at this file it is named:
Now that is a bit of a mouthful and you may find that you have many configuration files in the boot directory that represent kernels you have or have had on your system. So try this:
ls /boot/config-$(uname -r)
uname -r displays the current kernel version, $() returns the output of any command that is run from within the brackets.
Once you have located the kernel configuration file you then need to verify that support for MagicSysRq is in your kernel:
grep MAGIC_SYSRQ /boot/config-$(uname -r)
Hopefully you will see something similar to this:
If you don’t have support you will need to use another kernel with the required support . On SUSE the support is built in to the kernel, however, you need to turn enable it as it is turned off by default..
This will have a value of 1 or 0
• 0 = off
• 1 = on
To turn it on then:
echo 1 > /proc/sys/kernel/sysrq
This will turn it until the next reboot. If you need it set permanently you will need to edit files or use the SUSE YaST tool.
From the YaST Local Security Tool you can turn on support for Magic SysRq. This actually writes to the file:
This line should be yes as above to permanently turn on Sysrq. This will have effect after a server reboot but you can turn it on immediately as described on the previously.
- Using YaST will set the file and current running value.
- Other systems use the line kernel.sysrq=1 in /etc/sysctl.conf
Ok, so we have Magic SysRq support in the kernel and we have turned it on. Now to use it.
( Well of course you will hope that you don’t have to use it )
Using the Sysrq key on the keyboard it is possible to send signals directly to the kernel. In the event of a system freeze we can
- sync all disks (flush buffers to disk),
- remount file-systems as read-only and
Preserving the file-system’s integrity during the emergency reboot. The key sequences are best pressed from you system console or Alt+F10 screen. This way you will see the messages passed back from the kernel.
Hold down the ALT and SysRq Key and then the option key that you require. Consider BUSIER but spelled backwards:
R E I S U B
- ALT + SysRq + R
Captures the keyboard from X server
- ALT + SysRq + E
SIGTERM to all processes except init
- ALT + SysRq + I
SIGKILL to all processes except init
- ALT + SysRq + S
Sync all filesystems ( flush write buffers )
- ALT + SysRq + U
Remount all filesystem as Read-only
- ALT + SysRq + B