Magicsysrq keys for maintenance ance with Ubuntu troubles

Source: Internet
Author: User
Tags echo command
Original post address: http://ubuntuforums.org/showthread.php? T = 617349
Author: pmdematagda November 19th, 2007
 

Magicsysrq keys for maintenance ance with Ubuntu troubles

This guide consists of four parts :-
1) Introduction
2) restarting Ubuntu safely when it is frozen.
3) Shutting Down Ubuntu safely when it is frozen.
4) brief descriptions about the keys you can use in magic sysrq sequences.
5) controlling the use of sysrq keys.

1) Introduction

First off I wowould like to thank the creators of the different Linux
Kernel documentation, tutorials and how-tos that made this possible, I
Wocould also like to thank pauper And vadi for their help in this (in
Someway ).

The magic sysrq keys are key combinations within the Linux kernel that
Allows the user to perform varous low level commands regardless of
System's state, kernel t during kernel panics or freezes. It is often
Used to recover from X-server freezes, or to reboot a computer
Corrupting the filesystem.

2) restarting Ubuntu safely when it is frozen

If anyone faces a freeze with Ubuntu where you cannot do anything, then
This will certainly be helpful if you want to reboot the OS as cleanly
As possible without damaging their HDD's or losing their data.

In case of a freeze where you cannot do anything, simply pressAlt + printscreen+ R + S + E + I + u + B,
Keep in mind that the underlined keys must be kept pressed through
Rest of the sequence and that you will need to keep holding
Sequence keys for a small period of time before going to the next one
So that their actions can be carried out properly (for example, hold
The r key for about 1-2 seconds before moving on to s). If the sequence
Does not work at first, then increase the time period between each
Sequence key press and try again.

If anyone requires a good way of remembering the sequence R + S + E + I + u + B, just remember"RAisingSKinnyELephantsISUTterlyBOring ".

If someone requires a good description on what each keystroke does, here is something rather good :-

RAw (take control of keyboard back from X), TERminate (kill-15 programs, allowing them to terminate gracefully), KILL (kill-9 unterminated programs ),SYNC (flush data to disk ),UNmount (remount everything read-only), ReBOOT.

Note:-This keystroke does not work in the event of a kernel
Freeze as the keystroke sequence depends on the kernel in order
Unmount and make the required steps before the restart.

3) safely shutting down Ubuntu when it is frozen

The key sequence to achieve this does not differ from the one used
Restart Ubuntu safely failed t for the last key. So here it is
Follows :-
Alt + printscreen+ R + S + E + I + u + O, keep in mind
That as in the previous sequence, the underlined keys must be kept
Pressed through the rest of the sequence and that you will need to keep
Holding the sequence keys for a small period of time before going
The next one so that their actions can be carried out properly.

If someone requires a good description on what each keystroke here
Does, there is not much of a difference from the last one, interval t (once
Again), the final key :-

RAw (take control of keyboard back from X), TERminate (kill-15 programs, allowing them to terminate gracefully), KILL (kill-9 unterminated programs ),SYNC (flush data to disk ),UNmount (remount everything read-only), shutdOWn.

Note:-This keystroke does not work in the event of a kernel
Freeze as the keystroke sequence depends on the kernel in order
Unmount and make the required steps before the shutdown.

4) brief descriptions about the keys you can use in magic sysrq Sequences

0-9-Sets the console Log Level, controlling which kernel messages will be printed to your console so that you don't get flooded.

B-Restarts the system without making steps to ensure that
Conditions are good for a safe reboot, using this key alone is like
Doing a cold reboot.

E-Sends sigterm to all processes failed t init. This means that
An attempt is done to end the current processes failed t init, safely,
E.g. Saving a document.

F-Call oom_kill (out of memory killer), which will kill a process that is consuming all available memory.

H-Displays help about the sysrq keys on a terminal though in actuality you can use any keyExceptFor the ones specified, to display help.

I-Sends sigkill to all processes failed t init. This means that
All the processes before t for init are killed, any data in processes
That are killed will be lost.

K-Kills all processes on the current terminal. It is a bad
Idea to do this on a console where X is running as the GUI will stop
And you can't see what you type, so you will need to switch to a tty
After doing the magic sysrq.

L-Sends sigkill to all processes, including init. This means thatEveryProcess including init will be killed, using this keyWillRender your system non-functional and no further magicsysrq keys can be used. So in this case you will have to cold reboot it.

M-Dumps memory info to your console.

O-Shuts down the system via ACPI or in older systems, APM.
In key "B", using this key alone is like a cold reboot (or in this case,
A cold shutdown ).

P-Dumps the current registers and flags to your console.

Q-Dumps all timers info to your console.

R-Takes keyboard and mouse control from the X server. This can
Be useful if the X-server crashed, you can change to a console and kill
The X-server or check the error log.
Note:-The documentation refers to this key's task as "turns off
Keyboard RAW mode and sets it to Xlate ", but I suppose it's safe enough
To assume that it takes back control from X.

S-Writes all data from the disc cache to the hard-discs, it is
A Sync and is necessary to reduce the chances of Data Processing uption.

T-Dumps a list of current tasks and info to your console.

U-Remounts all mounted filesystems read-only. After using this
Key, You can reboot the system with ALT + sysrq + B without harming
System.

W-Dumps uninterruptable (BLOCKED) State tasks.

5) controlling the use of sysrq keys.

There are some ways of controlling the use of sysrq keys (I. e. What can
Be used, enabling or disabling them completely), two ways of doing this
Are :-
1) refreshing the sysrq keys during kernel Compilation itself.
There isn't much here since you can only disable sysrq keys and not
Actually control or define what you can and can't use. The option you
Are looking for is:-code:

MAGIC_SYSRQ

2) using proc sysrq trigger CILS.
This is much more flexible than changing the configuration of
Kernel but this has one downside with security which is explained
After (since it is very minor). You use the echo command to achieve this
For example, But you cocould also use any normal text editor to achieve this.
Now the command is (you will need root permissions):-code:

echo * > /proc/sys/kernel/sysrq

Where "*" is a number, which can be any one of these :-
0-Disable sysrq keys completely

1-Enable all functions of sysrq

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 (control the nice level (priority) of real time tasks)

So you can define what sysrq keys can be used, and also define whether
They are all on or off. Also, there may be more ways of controlling
Sysrq keys, but as of now the above two are the only ways I know.

Now for the "downside". For example you disable sysrq keys when you
Want to stop people (local) from doing key presses and then shutting
Down or messing up the PC during an important task (very obscure, I
Know). Now with processing the kernel, you can stop sysrq keys from
Being used at all from the beginning of the boot process right Uptil
The end, with calling the proc sysrq triggers however, your option only
Takes place when it is executed (I. e. After the system has booted up) So
There is a certain area of vulnerability with calling the triggers
Whereas there is no such thing in processing the kernel, some people
Are that desperate to secure their systems to care about a few seconds,
However do not blame me for it.

Something about the magicsysrq keys is that they can be used in any
Sequence and in any way to achieve the required objective, for example
You can just press Alt + sysrq + B to do something like a cold reboot.

One more Note:-even though
This guide is made for Ubuntu, the magic sysrq keys can be used on
Other Linux distributions with little/no alterations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.