You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Buildroot嵌入式Linux系统中Busybox reboot命令无效果问题排查

我使用Buildroot 2021.02.2构建了嵌入式Linux系统,内置BusyBox v1.33.0、Linux 5.4.8内核、glibc 2.32运行时。

故障现象

执行reboot命令时系统无任何反应,syslog中也没有错误或警告信息。但添加-f强制参数时可以正常重启设备,BusyBox reboot命令的帮助信息如下:

# reboot --help
BusyBox v1.33.0 () multi-call binary.

Usage: reboot [-d DELAY] [-nf]

Reboot the system

    -d SEC  Delay interval
    -n  Do not sync
    -f  Force (don't go through init)

# reboot -f
< reboots OK >

后续发现该故障为偶发:reboot命令生效与否随机,成功时syslog会输出rcK执行、各服务退出的日志,失败时无任何相关日志,连rcK的调用记录都没有。

初步排查

在/etc/init.d/rcK和inittab中都添加了调试日志,执行普通reboot后,流程既没有到达inittab的shutdown逻辑,也没有执行rcK脚本。/etc/inittab的shutdown配置片段如下:

# 重启前执行的操作
::shutdown:/bin/echo "MY DEBUG" | /usr/bin/logger
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::respawn:/usr/bin/monit -Ic /etc/monitrc

已确认libc.so包含reboot相关功能:

nm build/glibc-2.32-37-g760e1d287825fa91d4d5a0cc921340c740d803e2/build/libc.so.6 | grep reboot
000cb2e0 T reboot

系统使用Busybox init,配置项为BR2_INIT_BUSYBOX=y,Busybox init支持的信号如下:

# init --help
BusyBox v1.33.0 () multi-call binary.

Usage: init

init是系统启动时第一个启动的进程,不会退出。
它会根据/etc/inittab配置(重新)启动子进程。
支持的信号:
HUP: 重新加载/etc/inittab
TSTP: 停止重启子进程,直到收到CONT信号
QUIT: 重新执行另一个init进程
USR1/TERM/USR2/INT: 执行halt/reboot/poweroff/ Ctrl-Alt-Del对应脚本

本次问题的诉求为:希望reboot命令可以走正常关机流程完成重启,不需要绕过init进程,询问对应的排查方向,以及偶发故障的触发原因。


最终解决方案

该偶发故障的触发原因为init脚本中start-stop-daemon参数使用错误:单独使用-m参数不带-b时,会导致偶发的reboot失效问题。
正确的start-stop-daemon用法有两种:

  1. 同时搭配-b -m -p $PIDFILE参数,示例如下:
start-stop-daemon -S -q -m -b -p /var/run/logrotate.pid --exec /usr/sbin/logrotate.sh
  1. 仅使用-p $PIDFILE参数,示例如下:
start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"

内容的提问来源于stack exchange,提问作者Filip Kubicz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 23:18:03