Most linux distributions use some type of mechanism to gracefully stop daemons and unmount storage volumes during a reboot or shutdown. It's most commonly done via scripts that will wait for each daemon to shut down gracefully before proceeding to the next daemon.
As we know, sometimes servers misbehave due to things put them through, and you can quickly end up in a situation where things are going badly. I'm talking about the type of situation where you're connected via SSH to a server that controls phone lines for five million people and it sits in a tiny building 400 miles away from the nearest human being. We're talking bad. If you issue a plain reboot
command, it might not even make it that far. Once SSH stops running, you're going to be out of luck.
If you find yourself in this situation (and I hope you won't!), you have some options to get your way with a misbehaving server remotely. You can force an immediate reboot with the following:
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
WHOA THERE! This is pretty much the same as pressing the reset button on the server (if equipped). No daemons will be shut down gracefully, no filesystem sync will occur, and you may get the wrath of a fsck (or worse, a non-booting server) upon reboot. To do things a little more carefully, read on.
These are called magic commands, and they're pretty much synonymous with holding down Alt-SysRq and another key on older keyboards. Dropping 1
into /proc/sys/kernel/sysrq
tells the kernel that you want to enable SysRq access (it's usually disabled). The second command is equivalent to pressing Alt-SysRq-b on a QWERTY keyboard.
There's a better way of rebooting a misbehaving server that Wikipedia shows with the mnemonic "Reboot Even If System Utterly Broken":
unRaw (take control of keyboard back from X),
tErminate (send SIGTERM to all processes),
kIll (send SIGKILL to all processes),
Sync (flush data to disk),
Unmount (remount all filesystems read-only),
reBoot.
I can't vouch for this actually working, but I'm interested to try it. UPDATE: I've been told that doing this series of commands with ReiserFS is a very bad idea.
If you want to shut the machine down entirely (please think about it before using this on a remote system):
echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger
If you want to keep SysRq enabled all the time, you can do that with an entry in your server's sysctl.conf
:
分享到:
相关推荐
该命令用来重启Linux系统。相当于Windows系统中的restart命令。 命令语法: /sbin/reboot [-n] [-w] [-d] [-f] [-i] 或 reboot [-n] [-w] [-d] [-f] [-i] 命令参数: 参数 长参数 描叙 -d 重新...
- `halt`和`reboot`:停止和重启系统,功能类似`shutdown`但无警告信息。 4. **Shell特殊按键**: - `Ctrl+C`:终止当前命令。 - `Ctrl+D`:在命令行中表示EOF(文件结束符),通常用于退出Shell。 - `Ctrl+Z`...
- 最终,Android系统会通过Linux内核提供的函数,如`reboot()`或`shutdown()`,来实现真正的系统重启或关机。这些调用会由Android的系统服务器发起,并通过Binder机制传递到内核空间。 7. **权限控制**: - 只有...
本项目以"Android 关机和重启(reboot and shutdown)源码"为主题,为毕业设计提供了深入的学习资源,适合对Android系统内核感兴趣的开发者。 首先,我们要理解Android系统是如何处理关机和重启命令的。这两个操作...
第六讲 Linux的服务与进程管理 主要内容 Linux的启动过程 Linux的服务管理 Linux的进程管理 Linux的启动过程 BIOS自检 读取并加载硬盘MBR(主引导记录)中的启动引导器(GRUB或LILO等) 运行Linux的系统内核并检测...
学习 Linux 的第一步:当然是从 Linux 命令 入手: 查看 Linux 命令帮助信息 - 关键词:help, whatis, info, ...Linux 系统管理 - 关键词:reboot, exit, shutdown, date, mount, umount, ps, kill, systemctl, service
- **(3) 使用shutdown命令**:在root用户下执行`shutdown -r +5 "This System will be reboot after 5 minutes"`,此命令用于设置系统在5分钟后重启,并向所有已登录用户发送通知。接着切换到student用户查看是否...
"Linux关机和重启服务器命令详解" Linux 系统中有多种关机和重启命令,每种命令都有其特点和用法。了解这些命令的使用方法和参数可以帮助用户更好地管理 Linux 系统。 shutdown 命令 shutdown 命令可以安全地将...
linux教程: 查看 Linux 命令帮助信息 - 关键词:help, whatis, info, which, where...Linux 系统管理 - 关键词:reboot, exit, shutdown, date, mount, umount, ps, kill, systemctl, service, crontab Linux 网络管理
这个压缩包文件“Android关机和重启(reboot and shutdown)源码.rar”很可能包含的是Android操作系统执行关机和重启操作的核心源代码。下面我们将深入探讨Android系统中的关机和重启过程以及相关知识点。 1. **...
在 `include/linux/reboot.h` 文件中,定义了一些 magic 数值,这些 magic 数值用于防止误操作。这些 magic 数值包括: * `LINUX_REBOOT_CMD_RESTART`:表示重新启动系统 * `LINUX_REBOOT_CMD_HALT`:表示关机 * `...
本资料包“Android 关机和重启(reboot and shutdown)源码”提供了Android系统执行这两个操作的源代码,这对于我们理解Android系统底层工作原理、系统服务管理以及设备驱动的交互具有极大的学习价值。 首先,我们...
Android 关机和重启(reboot and shutdown)源码.zip项目安卓应用源码下载Android 关机和重启(reboot and shutdown)源码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司...
退出系统则通过"logout"或Ctrl+D实现,关机或重启有多种命令,如"halt"、"reboot"和"shutdown",后者尤其适用于多用户环境,确保所有用户有机会保存工作。 4. **窗口与终端工作模式**:Linux支持窗口工作方式(如X ...
本资源包"Android 关机和重启(reboot and shutdown)源码.zip"提供了Android系统实现关机和重启功能的源代码,帮助开发者深入理解这一过程。以下是关于这个主题的详细知识点: 1. **系统服务**: - 在Android中,...
在关机和重启过程中,会修改特定的系统属性,如`sys.shutdown.requested`或`sys.reboot.reason`,来标记请求的状态和原因。 5. **HAL(Hardware Abstraction Layer)**: Android的硬件抽象层是操作系统与硬件之间...