Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › The alt+sysrq key to rescue a hung system - do not use the power button
New Posts  All Forums:Forum Nav:

The alt+sysrq key to rescue a hung system - do not use the power button

post #1 of 8
Thread Starter 
I think this is a very useful tip and a lot of newer linux users may not know about this. Admittedly I just found out about it about a year ago and it should have been on page 1 of the "instruction manual".

We've all been there, perhaps you're testing something new and you didn't get the kernel config or xorg settings just perfect. Or someone provided you with bad software or you yourself wrote bad software, and now you're staring at a black screen. You try mashing ctrl+alt+backspace / ctrl+alt+delete and a few other things on the keyboard but nothing happens. Then you swear a couple times and eventually reach for the power button.

smil3dbd4e4c2e742.gif

Now you've got an unclean shutdown, and if you're unlucky you may have damaged your filesystem to some degree. Though uncommon, it does happen and it's not something you want to deal with.

Check that you have the "magic sysrq key" enabled in your kernel :
Code:
~ $ zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz 
CONFIG_MAGIC_SYSRQ=y

If you don't see "=y" there, follow your distro's guide to reconfiguring and recompling your kernel with that setting enabled. It should be by default however. If you don't have /proc/config.gz enabled, I also feel sorry for you.

smil3dbd4e4c2e742.gif

Once the sysrq key is enabled, if your X server hangs:

Alt+SysRq+K -> kill the x server

At this point you can ctrl+alt+F[1-12] to switch to another VT and continue running commands. If you're still stuck:

Alt+SysRq+R -> put your keyboard into primitive mode, out of the X servers control, then switch VT. thumb.gif If you're system is completely hung and you can't even get to a VT, then:

Alt+SysRq+E -> send SIGTERM to all tasks
Alt+SysRq+I -> send SIGKILL to all tasks
Alt+SysRq+S -> send the sync command to any mounted file systems, very good
Alt+SysRq+U -> unmount and remount /dev/root read only, also very good
Alt+SysRq+B -> reboot the system

The key pressing is kind of touchy, you have to hold Alt, hold SysRq, and then press the letter. Wait a second or two between letters for the syncing etc to occur. If you're on the primary console you'll see the text of what it's doing.

smil3dbd4e4c2e742.gif

The way to remember that is "raising elephants is so utterly boring" .. as a former elephant raiser, I can attest to how boring it was. The K key is newer, so there's no moniker for that yet, so you have to remember two things. Now the next time you hang your system, you have no excuse to have your data bricked it or sit there and wait for fsck ... unless you forget the catch phrase

drunken.gif

en.wikipedia.org/wiki/Magic_SysRq_key
Edited by lloyd mcclendon - 3/20/13 at 5:34pm
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
post #2 of 8
whats the sysrq key? the 'windows'/system key?
post #3 of 8
whats the sysrq key? the 'windows'/system key?
post #4 of 8
Thread Starter 
smile.gif
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
post #5 of 8
i got lost on the loop, but i found my way back.

ive never used the sysrq portion of that button before. weird.
Gaming Rig
(15 items)
 
Sons Rig
(11 items)
 
File Server
(13 items)
 
CPUMotherboardGraphicsGraphics
Core i7 4790K ASUS Z97-WS Gigabyte GeForce GTX 980 Gigabyte GeForce GTX 980 
RAMHard DriveCoolingOS
16 Gb's Mushkin DDR3 @ 1600 MHz Crucial M500 SSD 240gb Coolit ECO C240 Windows 7 Ultimate 
MonitorMonitorPowerCase
ASUS PB287Q 4K Monitor HTC Vive Coolermaster Silent Pro M 1000W Rosewill Blackhawk Ultra 
MouseMouse PadAudio
Razer Deathadder 2013 Steelseries Qck Mass Super Thick Cloth Mouse Pad Genius SW-G2.1 1250 4PC Gaming Speakers 
CPUMotherboardGraphicsGraphics
Core i7 3770k Asus P8Z68 Deluxe Galaxy Geforce GTX 780 Galaxy Geforce GTX 780 
RAMHard DriveCoolingOS
16 Gb's G.Skill DDR3 1866 Crucial M500 SSD 240Gb Coolit ECO C240 Windows 7 Ultimate 
MonitorPowerCase
Benq G2420HD Coolermaster Silent Pro 1000 Watt Deepcool Kendomen 
CPUMotherboardRAMHard Drive
Core i3 2120 Supermicro X9SCM-F 4 Gb Kingston 1600mhz DDR3 ECC 12 Segate 2tb drives (RAID 6) 
Hard DriveHard DriveOSPower
ADATA SP600 SSD 24 Toshiba DT01ACA200 drives (2 RAID 6's) Windows 7 Ultimate 64 bit. OCZ ZT750 Supermicro PWS-665-PQ 
CaseOtherOtherOther
Norco 4020 and Norco 4224 LSI 9260-4i Raid Card Intel RES2SV240 20 port Expander. HP SAS 24 por... Voltaire 410Ex Hca Infiniband HBA 
  hide details  
Reply
Gaming Rig
(15 items)
 
Sons Rig
(11 items)
 
File Server
(13 items)
 
CPUMotherboardGraphicsGraphics
Core i7 4790K ASUS Z97-WS Gigabyte GeForce GTX 980 Gigabyte GeForce GTX 980 
RAMHard DriveCoolingOS
16 Gb's Mushkin DDR3 @ 1600 MHz Crucial M500 SSD 240gb Coolit ECO C240 Windows 7 Ultimate 
MonitorMonitorPowerCase
ASUS PB287Q 4K Monitor HTC Vive Coolermaster Silent Pro M 1000W Rosewill Blackhawk Ultra 
MouseMouse PadAudio
Razer Deathadder 2013 Steelseries Qck Mass Super Thick Cloth Mouse Pad Genius SW-G2.1 1250 4PC Gaming Speakers 
CPUMotherboardGraphicsGraphics
Core i7 3770k Asus P8Z68 Deluxe Galaxy Geforce GTX 780 Galaxy Geforce GTX 780 
RAMHard DriveCoolingOS
16 Gb's G.Skill DDR3 1866 Crucial M500 SSD 240Gb Coolit ECO C240 Windows 7 Ultimate 
MonitorPowerCase
Benq G2420HD Coolermaster Silent Pro 1000 Watt Deepcool Kendomen 
CPUMotherboardRAMHard Drive
Core i3 2120 Supermicro X9SCM-F 4 Gb Kingston 1600mhz DDR3 ECC 12 Segate 2tb drives (RAID 6) 
Hard DriveHard DriveOSPower
ADATA SP600 SSD 24 Toshiba DT01ACA200 drives (2 RAID 6's) Windows 7 Ultimate 64 bit. OCZ ZT750 Supermicro PWS-665-PQ 
CaseOtherOtherOther
Norco 4020 and Norco 4224 LSI 9260-4i Raid Card Intel RES2SV240 20 port Expander. HP SAS 24 por... Voltaire 410Ex Hca Infiniband HBA 
  hide details  
Reply
post #6 of 8
Quote:
Originally Posted by lloyd mcclendon View Post

smile.gif

sad-smiley-002.gif
post #7 of 8
Most modern keyboards don't have the "sysrq" label on them any more... mine doesn't, anyway.
post #8 of 8
I've always just ctl+alt+f1 on to another tty then just pkill the offending app (or pkill X if I want to restart Xorg).
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › The alt+sysrq key to rescue a hung system - do not use the power button