如果 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