linux进入重启了如何阻止

如果 Linux 已经开始 进入重启流程 (比如你看到关机/重启提示、服务在 stop),还是有机会拦下来的,前提是 systemd 还没 kill 掉你的 shell。

下面按成功率从高到低给你:


✅ 方法 1:立刻发 systemd 取消命令(最有效)

在还能敲命令的时候,马上执行:

bash 复制代码
sudo systemctl cancel

或更强一点:

bash 复制代码
sudo systemctl stop reboot.target poweroff.target shutdown.target

systemd 在执行 reboot 时,本质是在拉起 reboot.target,这条命令可以中断。

如果你看到:

bash 复制代码
Canceled pending shutdown.

说明你救回来了。


✅ 方法 2:kill 掉 systemd 的 shutdown 进程

找正在执行的 shutdown 进程:

bash 复制代码
ps -ef | grep -E "reboot|shutdown|systemd-shutdown"

然后 kill 掉:

bash 复制代码
sudo kill -9 <PID>

特别关注:

bash 复制代码
/usr/lib/systemd/systemd-shutdown

只要这个没跑完,就还能救。


✅ 方法 3:如果是 shutdown -r 触发的

如果是有人执行了:

bash 复制代码
shutdown -r now

你可以执行:

bash 复制代码
sudo shutdown -c

它会显示:

复制代码
Shutdown cancelled.

⚠ 但如果是 systemctl reboot,这个方法无效。


⛔ 什么时候救不了

如果你已经看到:

复制代码
Reached target Shutdown.
Unmounting filesystems...
Sending SIGKILL to remaining processes...

或者屏幕已经黑了、SSH断了,那就已经太晚了,内核已经接管,用户态无法阻止。


🧠 你这种情况很可能是...

你之前在玩:

  • K8s / CI/CD
  • GitLab Runner
  • Azure / VM
  • Streamlit / Python 服务

很常见的坑是:

bash 复制代码
systemctl reboot

被写进了脚本 or cloud-init or k8s node reset

相关推荐
Forsete1 天前
LINUX驱动开发#9——定时器
linux·驱动开发·单片机
JY.yuyu1 天前
Docker常用命令——数据卷管理 / 端口映射 / 容器互联
运维·docker·容器
森G1 天前
七、04ledc-sdk--------makefile有变化
linux·c语言·arm开发·c++·ubuntu
驱动探索者1 天前
linux mailbox 学习
linux·学习·算法
alice--小文子1 天前
cursor-mcp工具使用
java·服务器·前端
lpruoyu1 天前
【Docker进阶-06】docker-compose & docker swarm
运维·docker·容器
China_Yanhy1 天前
入职 Web3 运维日记 · 第 8 日:黑暗森林 —— 对抗 MEV 机器人的“三明治攻击”
运维·机器人·web3
艾莉丝努力练剑1 天前
hixl vs NCCL:昇腾生态通信库的独特优势分析
运维·c++·人工智能·cann
酉鬼女又兒1 天前
每天一个Linux命令_printf
linux·运维·服务器
翼龙云_cloud1 天前
国际云代理商:2026年国际云注册风控升级实战指南 8 大平台无卡解决方案对比
服务器·阿里云·云计算