magic_sysrq_在Linux上使用Magic SysRq键修复冻结的X服务器,干净地重新引导并运行其他低级命令...

magic_sysrq

magic_sysrq

sysrq key

On Linux, the magic SysRq key can send commands directly to the Linux kernel. You can use it to recover from freezes or cleanly restart your system, even if nothing appears to be responding.

在Linux上,魔术SysRq密钥可以将命令直接发送到Linux内核。 即使似乎没有任何响应,也可以使用它从冻结中恢复或干净地重新启动系统。

The magic SysRq key is implemented as part of Linux’s keyboard driver – it will work as long as the Linux kernel is still running. Only a kernel panic should disable this key combination.

神奇的SysRq键是作为Linux键盘驱动程序的一部分实现的-只要Linux内核仍在运行,它就可以工作。 只有内核崩溃才应禁用此组合键。

Image Credit: solylunafamilia on Flickr

图片来源: Flickr上的solylunafamilia

使用Magic SysRq键 (Using the Magic SysRq Key)

The SysRq key is located near the Scroll Lock key on your keyboard – the Sys Rq key is generally the same as your Print Screen key. The “magic” SysRq combination is Alt+SysRq.

SysRq键位于键盘上的Scroll Lock键附近– Sys Rq键通常与您的Print Screen键相同。 “魔术” SysRq组合是Alt + SysRq。

To use this key combination, your Linux kernel must have been compiled with the CONFIG_MAGIC_SYSRQ compile option – most Linux distributions will have this enabled by default. Assuming it’s compiled into your kernel, it can be enabled or disabled on a running system by changing the value of /proc/sys/kernel/sysrq. To check if it’s enabled, run the following command:

要使用此组合键,您的Linux内核必须已使用CONFIG_MAGIC_SYSRQ编译选项进行了编译-大多数Linux发行版将默认启用该功能。 假设已将其编译到内核中,则可以通过更改/ proc / sys / kernel / sysrq的值在运行的系统上启用或禁用它。 要检查是否已启用,请运行以下命令:

cat /proc/sys/kernel/sysrq

猫/ proc / sys /内核/ sysrq

If you see a “1”, all functions of the magic SysRq key are enabled. A greater number indicates only certain functions are enabled—see the official Linux kernel help for more information.

如果看到“ 1”,则魔术SysRq键的所有功能都已启用。 较大的数字表示仅启用了某些功能-有关更多信息,请参见Linux内核官方帮助

image

If you see a “0”, you can enable all magic SysRq options yourself by running the following command:

如果看到“ 0”,则可以通过运行以下命令自己启用所有魔术SysRq选项:

sudo echo “1” > /proc/sys/kernel/sysrq

sudo回声“ 1”> / proc / sys / kernel / sysrq

On Ubuntu, the magic SysRq options are set at boot according to the contents of the /etc/sysctl.d/10-magic-sysrq.conf file. Edit this file to choose your desired values.

在Ubuntu上,根据/etc/sysctl.d/10-magic-sysrq.conf文件的内容在启动时设置了神奇的SysRq选项。 编辑此文件以选择所需的值。

处理冻结的X服务器 (Dealing With a Frozen X Server)

If your X server (the program that runs your graphical desktop) freezes, you may find yourself unable to use your system. There are a few magic SysRq commands that can help:

如果您的X服务器(运行图形桌面的程序)死机,您可能会发现自己无法使用系统。 有一些神奇的SysRq命令可以帮助您:

  • Alt + SysRq + r – Takes the keyboard out of raw mode, taking control away from the X server. After running this combination, you should be able to use the Ctrl + Alt + F1 (and other F-key) keyboard shortcuts to switch to another console and restart X.

    Alt + SysRq + r –使键盘退出原始模式,使控制权脱离X服务器。 运行此组合后,您应该能够使用Ctrl + Alt + F1(和其他F键)键盘快捷键切换到另一个控制台并重新启动X。

  • Alt + SysRq + k – Kills all programs on the current virtual console, including X. You can also enable the Ctrl+Alt+Backspace keyboard shortcut in Ubuntu’s keyboard preferences to restart your X server – however, this shortcut is implemented by the X server and may not always work.

    Alt + SysRq + k –杀死当前虚拟控制台上的所有程序,包括X。您还可以在Ubuntu的键盘偏好设置中启用Ctrl + Alt + Backspace键盘快捷键来重新启动X服务器-但是,此快捷方式由X服务器实现可能并不总是有效。

干净地重启系统 (Cleanly Restarting Your System)

Used in sequence, some of these actions can be used to cleanly end processes, flush data to disk, unmount all file systems, and restart your computer. To perform this process, press and hold the Alt + SysRq key combination and – while holding the Alt and SysRq keys down — type the following keys in order, pausing for several seconds in between each key:

按顺序使用这些操作中的某些操作可用于干净地结束进程,将数据刷新到磁盘,卸载所有文件系统以及重新启动计算机。 要执行此过程,请按住Alt + SysRq组合键,然后–按住Alt和SysRq键的同时–依次键入以下键,在每个键之间暂停几秒钟:

reisub

礼拜

The mnemonic “Raising Elephants Is So Utterly Boring” is often used to remember this sequence. Here’s what each key does:

助记符“R aisingélephants I S S 0ütterly O形环”通常用来记住该序列。 每个键的作用如下:

  • r – Puts the keyboard into raw mode, taking control of it away from the X server.

    r –将键盘置于原始模式,使其不受X服务器的控制。

  • e – Sends the terminate signal to all processes, asking them to end gracefully.

    e –向所有进程发送终止信号,要求它们正常结束。

  • i – Sends the kill signal to all processes, forcing them to end immediately.

    i –向所有进程发送终止信号,迫使它们立即结束。

  • s – Flushes data from your cache to disk.

    s –将数据从缓存刷新到磁盘。

  • u – Remounts all file systems read-only.

    u –以只读方式重新安装所有文件系统。

  • b – Reboots your computer.

    b –重新启动计算机。

更多命令 (More Commands)

Here are some other actions you can perform with the magic SysRq key. To perform an action, press and hold the Alt + SysRq keys while typing the letter:

这是您可以使用魔术SysRq键执行的其他一些操作。 要执行操作,请在输入字母时按住Alt + SysRq键:

  • n – Resets the nice level (priority) of all high and realtime priority processes.

    n –重置所有高优先级和实时优先级进程的优先级(优先级)。

  • f – Calls oom_kill, which will kill a memory-hogging process.

    f –调用oom_kill,它将杀死占用大量内存的进程。

  • o – Shuts off the computer.

    o –关闭计算机。

There are other actions, but they may be more useful to developers than the average Linux geek. For more information on the magic SysRq key – and a full list of actions you can perform – consult the official magic SysRq documentation for the Linux kernel.

还有其他动作,但对开发人员而言,它们可能比普通Linux怪胎更有用。 有关magic SysRq键的详细信息以及可以执行的操作的完整列表,请查阅Linux内核的官方magic SysRq文档

翻译自: https://www.howtogeek.com/119127/use-the-magic-sysrq-key-on-linux-to-fix-frozen-x-servers-cleanly-reboot-and-run-other-low-level-commands/

magic_sysrq

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值